sklearn linear regression model

Download the California housing prices from sklearn model, you may need to download.
Method using linear regression of the data training.
Each coefficient can be obtained and the size of each factor was observed influence on the results.
Where the population has a decimal point data items processed, in fact, a small special factors.

from sklearn.linear_model import LinearRegression as LR
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.datasets import fetch_california_housing as fch
import pandas as pd

housevalue = fch()
X = pd.DataFrame(housevalue.data)
y = housevalue.target

X.columns = housevalue.feature_names

Xtrain, Xtest, Ytrain, Ytest = train_test_split(X, y, test_size=0.3, random_state=420)
for i in [Xtrain, Xtest]:
    i.index = range(i.shape[0])

reg = LR().fit(Xtrain, Ytrain)
yhat = reg.predict(Xtest)

print(reg.coef_) # 线性回归方程中的系数
print([*zip(Xtrain.columns,reg.coef_)]) # 将系数与对应名称组合起来输出
print(reg.intercept_) # 线性回归中的截距项
Published 92 original articles · won praise 15 · views 4853

Guess you like

Origin blog.csdn.net/qq_43656233/article/details/104098611