diff --git a/opengrid/library/regression.py b/opengrid/library/regression.py index 8632fcc..361c2a8 100644 --- a/opengrid/library/regression.py +++ b/opengrid/library/regression.py @@ -30,8 +30,8 @@ class MultiVarLinReg(Analysis): The analysis is based on a forward-selection approach: starting from a simple model, the model is iteratively refined and verified until no statistical relevant improvements can be obtained. Each model in the iteration loop - is stored in the attribute self._list_of_fits. The selected model is self._fit (=pointer to the last element of - self._list_of_fits). + is stored in the attribute self.list_of_fits. The selected model is self.fit (=pointer to the last element of + self.list_of_fits). The dataframe can contain daily, weekly, monthly, yearly ... values. Each row is an instance. @@ -105,7 +105,7 @@ def list_of_fits(self): def do_analysis(self): """ - Find the best model (fit) and create self._list_of_fits and self._fit + Find the best model (fit) and create self.list_of_fits and self.fit """ if self.cross_validation: @@ -115,7 +115,7 @@ def do_analysis(self): def _do_analysis_no_cross_validation(self): """ - Find the best model (fit) and create self._list_of_fits and self._fit + Find the best model (fit) and create self.list_of_fits and self.fit """ # first model is just the mean @@ -356,7 +356,7 @@ def add_prediction(self): ------- Nothing, adds columns to self.df """ - self.df = self._predict(fit=self._fit, df=self.df) + self.df = self._predict(fit=self.fit, df=self.df) def plot(self, model=True, bar_chart=True, **kwargs): """ @@ -388,7 +388,7 @@ def plot(self, model=True, bar_chart=True, **kwargs): """ plot_style() figures = [] - fit = kwargs.get('fit', self._fit) + fit = kwargs.get('fit', self.fit) df = kwargs.get('df', self.df) if not 'predicted' in df.columns: diff --git a/opengrid/tests/test_regression.py b/opengrid/tests/test_regression.py index e35eff1..4149c07 100644 --- a/opengrid/tests/test_regression.py +++ b/opengrid/tests/test_regression.py @@ -29,12 +29,17 @@ def test_init(self): mvlr.do_analysis() self.assertTrue(hasattr(mvlr, 'list_of_fits')) - # def test_raises(self): - # df = datasets.get('gas_2016_hour') - # df_month = df.resample('MS').sum() - # mvlr = og.MultiVarLinReg(df_month, '313b', p_max=0.04) - # self.assertRaises(UnboundLocalError, mvlr.fit) - # self.assertRaises(UnboundLocalError, mvlr.list_of_fits) + def test_raises(self): + df = datasets.get('gas_2016_hour') + df_month = df.resample('MS').sum() + mvlr = og.MultiVarLinReg(df_month, '313b', p_max=0.04) + self.assertRaises(UnboundLocalError, mvlr.add_prediction) + try: + x = mvlr.list_of_fits + self.assertTrue(False) + except UnboundLocalError: + self.assertTrue(True) + def test_strange_names(self): df = datasets.get('gas_2016_hour')