簡體   English   中英

“以退出代碼0完成的過程”,但未顯示所需的輸出

[英]“Process finished with exit code 0” but desired output is not shown

我是python的新手,並在名為linear_regression_example.py的模塊中創建了這個小類“ myclass”。 它打印出回歸摘要和密度圖:

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()

我還有另一個文件,叫做test.py:

import linear_regression_example as lre

test = lre.myclass()
test.myregression()

在pycharm中運行test.py會導致輸出“過程已完成,退出代碼為0”,但未顯示任何摘要或圖。 也許這里有人知道問題出在哪里。

最好的祝福

多米尼克

linear_regression_example.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()

if __name__ == '__main__':
    test = myclass()
    test.myregression()

test.py

import linear_regression_example  as lre

test = lre.myclass()
test.myregression()

輸出(來自test.py)

test.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM