선형 회귀 전력 예측

1502 단어 기계 학습
import pandas as pd
# pandas     
data = pd.read_csv("C:/Users/Administrator/Desktop/data/ccpp.csv")
data.head()

X = data[["AT","V","AP","RH"]]
print(X.shape)
y = data[["PE"]]
print (y.shape)

"""
sklearn.cross_validation sklearn      ,        model_selection
"""
from sklearn.model_selection import train_test_split
#          
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=1)
print (X_train.shape)
print (y_train.shape)
print (X_test.shape)
print (y_test.shape)


from sklearn.linear_model import LinearRegression
linreg = LinearRegression()
linreg.fit(X_train,y_train)
#       ,    
print (linreg.intercept_)#   
print (linreg.coef_)  #  


y_pred = linreg.predict(X_test)
from sklearn import metrics
import numpy as np
#   sklearn   mse Rmse
print ("MSE:",metrics.mean_squared_error(y_test, y_pred))
print ("RMSE:",np.sqrt(metrics.mean_squared_error(y_test, y_pred)))


#     
from sklearn.model_selection import cross_val_predict
predicted = cross_val_predict(linreg,X,y,cv=10)
print ("MSE:",metrics.mean_squared_error(y, predicted))
print ("RMSE:",np.sqrt(metrics.mean_squared_error(y, predicted)))


#       
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(y, predicted)
ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4)
ax.set_xlabel('Measured')
ax.set_ylabel('Predicted')
plt.show()

좋은 웹페이지 즐겨찾기