«Процесс завершен с кодом выхода 0», но желаемый результат не отображается - PullRequest
0 голосов
/ 03 января 2019

Я новичок в python и создал этот крошечный класс "myclass", который находится внутри модуля с именем 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()

У меня также есть другой файл с именем test.py:

import linear_regression_example as lre

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

Запуск test.py в pycharm приводит к выводу«Процесс завершен с кодом выхода 0», но сводка или график не отображаются.Может быть, кто-то здесь знает, в чем проблема.

С уважением

Доминик

1 Ответ

0 голосов
/ 03 января 2019

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...