非线性样本
from matplotlib import pyplot as mp
y = [.4187, .0964, .0853, .0305, .0358, .0338, .0368, .0222, .0798, .1515]
x = [[i]for i in range(len(y))]
mp.scatter(x, y, s=99)
mp.show()
Sklearn回归汇总
import matplotlib.pyplot as mp
# 训练集
y = [.27, .16, .06, .036, .044, .04, .022, .017, .022, .014, .017, .02, .019, .017, .011, .01, .03, .05, .066, .09]
ly, n = len(y), 100
x = [[i / ly]for i in range(ly)]
# 待测集
w = [[i / n] for i in range(n)]
# # x轴范围
# max_x = 1
# x, w = [[i[0]*max_x] for i in x], [[i[0]*max_x] for i in w]
def modeling(models):
for i in range(len(models)):
print(models[i].__name__)
# 建模、拟合
model = models[i]()
model.fit(x, y)
# 预测
z = model.predict(w)
# 可视化
mp.subplot(3, 4, i + 1)
mp.title(models[i].__name__, size=10)
mp.xticks(())
mp.yticks(())
mp