Scikit-Learn 线性预测

import matplotlib.pyplot as plt


import numpy as np


rng = np.random.RandomState(42)


x = 10 * rng.rand(50)


y = 2 * x - 1 + rng.rand(50)


# 随机产生数据


plt.scatter(x, y)


# plt.show()




# 生命通过什么模型来解决问题


from sklearn.linear_model import LinearRegression


# 构造相应的参数
model = LinearRegression(fit_intercept=True)


X = x[:, np.newaxis]
# 模拟得到函数
model.fit(X, y)


# 生成新的数据集合


xfilt = np.linspace(-1, 11)


Xfit = xfilt[:, np.newaxis]


# 预测数据
yfit = model.predict(Xfit)
# 画图
plt.scatter(Xfit, yfit)


plt.show()

猜你喜欢

转载自blog.csdn.net/qq_33291307/article/details/80559145