数学建模习题10.3
`import numpy as np
import statsmodels.formula.api as smf
import pylab as plt
创建x值序列
x = np.arange(17, 30, 2)
加载数据
a = np.loadtxt('data10_3.txt')
设置图形样式和字体
plt.rc('text', usetex=True)
plt.rc('font', size=16)
plt.style.use('default')
绘制图形
plt.plot(x, a[0], '*', label='y1')
plt.plot(x, a[1], 'o', label='y2')
准备数据字典
x = np.hstack([x, x])
d = {'y': a.flatten(), 'x': x}
拟合多项式回归模型
model = smf.ols('y ~ x + np.power(x, 2)', d).fit()
print(model.summary())
print('残差的方差:', model.mse_resid)
显示图例和图形
plt.legend()
plt.show()
打印学号后两位
print("学号后两位:05")
`

浙公网安备 33010602011771号