30户的暖气的分析结果复制粘贴下来发给队友
(好像是有点多了一个对话框都过不去)
被嫌弃了
你就不能给我打包个excel!!!
好吧
import csv
with open("result.csv","w") as csvfile:
writer = csv.writer(csvfile)
#先写入columns_name
writer.writerow(['index','住户','模型权重','截距','回归方程','训练集R^2','测试集R^2','均方误差(MSE)','根均方误差(RMSE)','"平均绝对值误差(MAE)'])
def all(x):
data2=data[(data.address_2nd==x)]
X ,y= data2[['POWER','IN_TEMPERATURE','温度']],data2['ROOM_TEMPERATURE']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
lr = LinearRegression()
lr.fit(X_train, y_train)
y_hat = lr.predict(X_test)
df1=x
df2=lr.coef_
df3=lr.intercept_
list(df2)
df4=('y = %f x1 + %f x2 +%f x3 +%f'%(df2[0],df2[1],df2[2],df3))
df5=r2_score(y_train, lr.predict(X_train))
df6=r2_score(y_test, y_hat)
df7=mean_squared_error(y_test, y_hat)
df8=np.sqrt(mean_squared_error(y_test, y_hat))
df9=mean_absolute_error(y_test, y_hat)
writer.writerows([[i,df1,df2,df3,df4,df5,df6,df7,df8,df9]])
address = [15311251,15310819,15310804,15311234,15311289,15311072,15311061,15310846,15311065,15311342,15311245,15310966,
15311191,15311361,15310827,15311196,15311235,15311233,15310808,15311473,15310839,15310815,15310845,
15311082]
for i in range(len(address)):
x = address[i]
all(x)
for i in address:
df1=x
df2=lr.coef_
df3=lr.intercept_
df4=r2_score(y_train, lr.predict(X_train))
i+=1