首页 > 编程知识 正文

线性回归算法步骤,波士顿房价预测模型

时间:2023-05-06 10:44:15 阅读:142252 作者:1523

第一关(线性回归算法思想1 BC第二关)线性回归# encoding=utf8 importnumpyasnp # msedefmse _ score (y _ predict, y _ test (: # * * * * * begin * * * * * * * * # m=len (y _ predict ) a=y_test-y_predictmse=NP a(/m) test _ feature (: ' ' input : train _ feature ) ndarray ) :训练样本特征train_label(ndarray ) 3360训练60predict(ndarray ) :测试样品的预测标签(() ) * * * * * * begin * * * * * * # #培训数据new _ train=NP.concation 在train_feature )中添加x0=1axis=1) #使用正则表达式解计算参数train _ t=new _ train.TL inal=NP.Lina LG.inv (NP.dot (trand ) ) new_train ) ) train_label(#测试数据new _ test=NP.concatenate ((NP.ones (len ) test _ feates _ featenate ) ) 1 )添加x0=1axis=1) #测试集预测标签predict=NP.dot(new_test ),然后计算theta (* * * * * * end * * * * * * # return preturn prest ) y_test ) : MSE=NP.mean ((y_predict-y _ test ) *2) returnMSE#R2defR2_score ) y _ predict, y_test (:' input : y _ predict ) ndarray ) :预测值y _ test ) ndarray ) :真值output3:r2(float ) 3360 R2 R2

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。