Python-一元线性回归
from sklearn import linear_model
import numpy as np
model = linear_model.LinearRegression()
x = [2,4,5,6,7,9]
y = [7,5,3,5,3,1]
x = np.array(x).reshape(-1,1)
y = np.array(y).reshape(-1,1)
model.fit(x, y)
#cept = model.intercept_ #截距
#coef = model.coef_ #系数
a = model.predict([[12]]) #预测x为12时,y的值
浙公网安备 33010602011771号