机器学习 线性回归
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.linspace(1,10,20)
a = np.random.randint(1,10,20)
y = x * 4 + a
plt.plot(x,y,'o')
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(x.reshape(20,1), y.reshape(20,1))
LinearRegression(copy_X=True,fit_intercept=True,n_jobs =1,normalize = False)
model.predict(6) #预测出的函数值y
model.coef_ #系数k
model.intercept_ #截距b