#安装scikit-learn pip install Anaconda
from sklearn.datasets import make_regression
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
#生成核酸数据
x,y=make_regression(n_samples=100,n_features=1,noise=20,random_state=0)
print(x.shape)
plt.scatter(x,y)

lr_model=LinearRegression()
lr_model.fit(x,y)
LinearRegression(copy_X=True,fit_intercept=True,n_jobs=1,normalize=False)
#评估
train_score=lr_model.score(x,y)
plt.plot(x,lr_model.predict(x),'r')
#a
lr_model.coef_
#b
lr_model.intercept_
#以下是预测,
new_x=5
y=lr_model.predict(new_x)
#增加特征数量,来增加精度