博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
回归模型与房价预测
阅读量:7078 次
发布时间:2019-06-28

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

1. 导入boston房价数据集

from sklearn.datasets import load_bostonboston=load_boston()boston.keys()

print(boston.DESCR)

boston.data.shape

import pandas as pdpd.DataFrame(boston.data)

2. 一元线性回归模型,建立一个变量与房价之间的预测模型,并图形化显示。

import matplotlib.pyplot as pltx=boston.data[:,5]y=boston.targetplt.figure(figsize=(10,6))plt.scatter(x,y)plt.plot(x,9.1*x-34,'g')plt.show()

from sklearn.linear_model import LinearRegressionlineR=LinearRegression()lineR.fit(x.reshape(-1,1),y)lineR.coef_

lineR.intercept_

3. 多元线性回归模型,建立13个变量与房价之间的预测模型,并检测模型好坏,并图形化显示检查结果。

from sklearn.linear_model import LinearRegressionlineR=LinearRegression()lineR.fit(boston.data,y)w=lineR.coef_w

b=lineR.intercept_b

import matplotlib.pyplot as pltx=boston.data[:,12].reshape(-1,1)y=boston.targetplt.figure(figsize=(10,6))plt.scatter(x,y)from sklearn.linear_model import LinearRegressionlineR=LinearRegression()lineR.fit(x,y)y_pred=lineR.predict(x)plt.plot(x,y_pred)print(lineR.coef_,lineR.intercept_)plt.show()

4.  一元多项式回归模型,建立一个变量与房价之间的预测模型,并图形化显示

from sklearn.preprocessing import PolynomialFeaturespoly=PolynomialFeatures(degree=2)x_poly=poly.fit_transform(x)x_poly

from sklearn.preprocessing import PolynomialFeaturespoly=PolynomialFeatures(degree=2)x_poly=poly.fit_transform(x)lrp=LinearRegression()lrp.fit(x_poly,y)y_plot_pred=lrp.predict(x_poly)plt.scatter(x,y)plt.scatter(x,y_pred)plt.scatter(x,y_plot_pred)plt.show()

转载于:https://www.cnblogs.com/guangshang/p/10107525.html

你可能感兴趣的文章
jQuery实现加入购物车飞入动画效果
查看>>
【Win 10应用开发】认识一下UAP项目
查看>>
【Win10 应用开发】从前台应用触发后台任务
查看>>
***PHP 去除换行符
查看>>
自定义异常时如何定义checked异常和unchecked异常
查看>>
SMTP邮件服务器配置
查看>>
addChildViewController transitionFromViewController nib storyboard
查看>>
找到一个给定的页面(一)
查看>>
Swift - 按钮(UIButton)的用法
查看>>
AWK中的OFS的问题
查看>>
hbase ganglia监控配置
查看>>
VARCHAR2 他们占几个字节? NLS_LENGTH_SEMANTICS,nls_language
查看>>
centos6.4设备hadoop-2.5.1(完全分布式)
查看>>
your local changes would be overwritten by merge. commit stash or revert them to proceed. view them
查看>>
systemd启动多实例
查看>>
android测试参考,及CreateProcess failure, error问题解决
查看>>
Windows PowerShell 简介
查看>>
TypeScript学习笔记(二):基本数据类型及数据转换
查看>>
js css 实现简单的计算器
查看>>
android 58 jvm和dvm的区别(Dalvil VM)
查看>>