我是python新手,创建了一个小类“myclass”,它位于一个名为线性回归的模块中_示例.py. 它会打印出回归摘要和密度图:import statsmodels.api as sm
import sklearn.datasets as skld
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
class myclass:
def __init__(self, result=1):
self.result = result
def myregression(self):
y_X = skld.load_boston()
y = y_X['target']
X = y_X['data']
n = y_X['feature_names']
y = pd.DataFrame(y)
X = pd.DataFrame(X, columns=n)
X = sm.add_constant(X)
mod = sm.OLS(y, X)
result = mod.fit()
if self.result == 1:
print(result.summary())
pred = mod.predict(result.params)
pred = pd.DataFrame(pred)
errors = y - pred
sns.distplot(errors)
plt.show()
我还有另一个文件,叫做测试.py公司名称:
^{pr2}$
跑步测试.py在pycharm中,结果是输出“Process finished with exit code 0”,但不显示摘要或绘图。也许这里有人知道问题出在哪里。在
谨致问候
多米尼克