import matplotlib.pyplot as plt import numpy as np from scipy.optimize import curve_fit def f_fit(x, a, b, c): return a * x ** 2 + b * x + c x = [1, 2, 3, 4, 5, 6, 7, 8, 9] y = [9.36, 52, 191, 350, 571, 912, 1207, 1682, 2135] p_fit, prov = curve_fit(f_fit, x, y) print(p_fit) print(f_fit(10, p_fit[0], p_fit[1], p_fit[2])) plt.scatter(x, y) x_line = np.arange(1, 9, 0.1) y_line = p_fit[0] * x_line ** 2 + p_fit[1] * x_line + p_fit[2] plt.plot(x_line, y_line) plt.show()
根据阿里过去九年的双十一销售额度拟合出的曲线如下:
根据拟合出的参数计算19年的销售额为: 2680.12,与真实数据2684仅差4亿
2680.12/2684≈0.9986
无边沉沦,苦海渡航