博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
线性回归-实践篇
阅读量:6655 次
发布时间:2019-06-25

本文共 1350 字,大约阅读时间需要 4 分钟。

 

 转至:云不知深处的博客: https://blog.csdn.net/pakko/article/details/37527799

总结了,下面我们以的二手房数据来实践线性回归。

数据及代码连接,工具使用。

1,数据获取

从网站爬到数据,并整理成我们需要的。爬取方式不便多讲,本人是用的jsoup。

2,数据过滤

爬到数据后,过滤了房间面积小于30平米,大于150平米的数据,总价格大于800w的也过滤了。(这些数据太小或者太大)

3,一元线性回归

x表示房子面积,y表示房价,使用正规方程组的方法计算。

拿到代码后执行one即可。

执行结果如下:

 

4,多元线性回归

 

x表示房子面积、房间数、楼层,y表示房价,使用正规方程组的方法计算。

 

拿到代码后执行multi即可。

执行结果如下:

 

 

% Load the data from our text file

data = load('house.txt');

% Define x and y

x = data(:,1:3);
y = data(:,4);

% Create a function to plot the data

function plotData(x,y)
plot(x,y,'rx','MarkerSize',8); % Plot the data
end
% Plot the data
plotData(x,y);
xlabel('Square Feet'); % Set the x-axis label
ylabel('Price'); % Set the y-axis label
fprintf('Program paused. Press enter to continue.\n');
pause;

% Count how many data points we have

m = length(x);
% Add a column of all ones (intercept term) to x
X = [ones(m, 1) x];

% Calculate theta

theta = (pinv(X'*X))*X'*y

% Plot the fitted equation we got from the regression

hold on; % this keeps our previous plot of the training data visible
plot(X(:,2), X*theta, '-')
legend('Training data', 'Linear regression')
hold off % Don't put any more plots on this figure

price = [1, 80, 2, 0.5] * theta;

fprintf(['Predicted price of a 80 sq-ft, 2 rooms, middle floor' ...

'(using normal equations):\n %f\n'], price);

 

转载于:https://www.cnblogs.com/judejie/p/9012808.html

你可能感兴趣的文章
linux问题收集
查看>>
openstack-mitaka之Telemetry服务(computer节点安装部署)
查看>>
JavaScript标记
查看>>
Linux Shell编程之五字符串的处理
查看>>
C#使用技巧之调用JS脚本方法一
查看>>
如果C++程序要调用已经被编译后的C函数,需要extern “C”
查看>>
Modify Ip For Node
查看>>
我的Linux笔记3--bash的PATH环境变量设置
查看>>
搭建本地光盘YUM源及公司内部YUM服务器的方法
查看>>
批处理删除特定时间以前的文件
查看>>
我的友情链接
查看>>
5015.网络安全__防火墙运行模式和部署实例
查看>>
ubuntu server12.04配置java环境
查看>>
cd用法
查看>>
grub2故障举例及修复
查看>>
第 2 章 OpenStack 架构 - 015 - OpenStack 架构
查看>>
java中的代码块理解
查看>>
MogileFS 安装及基本管理
查看>>
我的友情链接
查看>>
CentOS 7.2 mysql-5.7.17 审计插件安装、开启与设定
查看>>