data.csv

    1. from sklearn.model_selection import train_test_split
    2. import numpy as np
    3. from sklearn import datasets,linear_model
    4. import pandas as pd
    5. data = pd.read_csv("data.csv“)
    6. y = data.iloc[:,2]
    7. x = data.iloc[:, 3:5]
    8. # 训练数据
    9. x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.25, random_state = 1)
    10. regr = linear_model.LinearRegression()
    11. regr.fit(x_train,y_train)
    12. print('coefficients(b1,b2...):',regr.coef_)
    13. print('intercept(b0):',regr.intercept_)
    14. # 预测数据
    15. y_pred = regr.predict(x_test)
    16. # 查看模型得分
    17. regr.score(x_test, y_test)