| print_function |
| # 导入相关python库 |
| os |
| np |
| pd |
| #设定随机数种子 |
| 36) |
| #使用matplotlib库画图 |
| matplotlib |
| seaborn |
| plot |
| datasets |
| #读取数据 |
| 'kc_train.csv') |
| #销售价格 |
| #测试数据 |
| #数据预处理 |
| #查看是否有缺失值 |
| #特征缩放 |
| MinMaxScaler |
| MinMaxScaler() |
| #进行内部拟合,内部参数会发生变化 |
| housing) |
| columns) |
| MinMaxScaler() |
| t) |
| t) |
| columns) |
| #选择基于梯度下降的线性回归模型 |
| LinearRegression |
| LinearRegression() |
| #进行拟合 |
| target) |
| #使用均方误差用于评价模型好坏 |
| mean_squared_error |
| #输入数据进行预测得到结果 |
| #使用均方误差来评价模型好坏,可以输出mse进行查看评价值 |
| #绘图进行比较 |
| #画布大小 |
| 100 |
| #取100个点进行比较 |
| #目标取值 |
| #预测取值 |
| #线条显示位置 |
| show() |
| #输出测试数据 |
| scaler_t) |
| result) |
df_result.to_csv("result.csv")
| # 兼容 pythone2,3 |