习题9.3
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
df = pd.read_excel('F:\python数学建模与算法\第九章习题\hm9.3.xlsx', header=None)
df = df.apply(pd.to_numeric, errors='coerce')
df = df.dropna()
fig = plt.figure()
ax = fig.add_subplot(111)
labels = ['Lab'+str(i) for i in range(1, 8)]
ax.boxplot(df.values, sym='xr', labels=labels)
plt.title('Boxplot of Labs')
plt.show()
y = df.values.flatten()
x = np.tile(np.arange(1, 8), (len(df), 1)).flatten()
model_dic = {'x': x, 'y': y}
model = sm.formula.ols('y ~ C(x)', data=model_dic).fit()
anovat = sm.stats.anova_lm(model)
print(anovat)

浙公网安备 33010602011771号