def test_resid_lever_plot_arg_err(self):
     """
     Check error for resid_lever_plot, with no assigned variables
     """
     try:
         test_plot = plt.RegressionAnalysisPlot(DF)
         test_plot.resid_lever_plot()
     except Exception as err:
         self.assertEqual(err.args[0], 'No predictors or response assigned')
 def test_init_response(self):
     """
     Check constructor error if response not chosen from dataframe
     """
     try:
         test_resp = 'somename'
         plt.RegressionAnalysisPlot(DF, response=test_resp)
     except Exception as err:
         msg = 'Input response variable not existed in the '
         msg += 'given dataframe'
         self.assertEqual(err.args[0], msg)
 def test_init_predictors(self):
     """
     Check constructor error if predictors not chosen from dataframe
     """
     try:
         test_preds = PREDS + ['somename']
         plt.RegressionAnalysisPlot(DF, predictors=test_preds)
     except Exception as err:
         msg = 'Input predictor variable(s) not existed '
         msg += 'in the given dataframe'
         self.assertEqual(err.args[0], msg)
Пример #4
0
import regression_analysis_plot as plt

EXTERNAL_STYLESHEETS = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
APP = dash.Dash(__name__, external_stylesheets=EXTERNAL_STYLESHEETS)
LOWESS = sm.nonparametric.lowess

# Read csv dataset
OPTION = 'Please enter a CSV data file url or local path:\n'
OPTION += 'Url example: www.someplace.com/mydata.csv\n'
OPTION += 'Local path example: ./mydata.csv\n'
ADDRESS = input(OPTION)
DF = pd.read_csv(ADDRESS, sep=',')
DF = DF.dropna()  # remove missing data
DF = DF.select_dtypes(exclude=['object'])  # keep only numeric columns
COLS = DF.columns
MYCLASS = plt.RegressionAnalysisPlot(DF)

# Layout and Plots
APP.layout = html.Div([
    html.H1('Linear Regression Model Diagnostics',
            style={'textAlign': 'center'}),
    html.Div('Data Source: %s\n' % ADDRESS, style={'font-weight': 'bold'}),
    html.Div([
        html.Div([
            dcc.Dropdown(
                id='predictors',
                options=[{'label': i, 'value': i} for i in COLS],
                placeholder='Select predictor variable(s)',
                multi=True
            )
        ], style={'width': '49%', 'display': 'inline-block'}),
"""
Unit tests for analysis_plot.py
"""

import unittest
from unittest.mock import patch
import seaborn as sns
import regression_analysis_plot as plt

DF = sns.load_dataset('iris')
PREDS = [DF.columns[0]]
RESP = DF.columns[1]
MYPLOT = plt.RegressionAnalysisPlot(DF, predictors=PREDS, response=RESP)


class TestRegressionAnalysisPlot(unittest.TestCase):
    """
    32 tests for analysis_plot
    """
    def test_init_predictors(self):
        """
        Check constructor error if predictors not chosen from dataframe
        """
        try:
            test_preds = PREDS + ['somename']
            plt.RegressionAnalysisPlot(DF, predictors=test_preds)
        except Exception as err:
            msg = 'Input predictor variable(s) not existed '
            msg += 'in the given dataframe'
            self.assertEqual(err.args[0], msg)