Skip to content

Commit

Permalink
Fix in check_is_fitted method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbacce committed Dec 18, 2019
1 parent aa45e7e commit c921439
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion giottotime/causality_tests/shifted_linear_coefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def transform(self, data: pd.DataFrame) -> pd.DataFrame:
fit coefficients between each timeseries. The shift is indicated in rows.
"""
check_is_fitted(self, ["best_shifts_", "max_corrs_"])
check_is_fitted(self)
data_t = data.copy()

for col in data_t:
Expand Down
2 changes: 1 addition & 1 deletion giottotime/causality_tests/shifted_pearson_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def transform(self, data: pd.DataFrame) -> pd.DataFrame:
between each timeseries The shift is indicated in rows.
"""
check_is_fitted(self, ["best_shifts_", "max_corrs_"])
check_is_fitted(self)
data_t = data.copy()

for col in data_t:
Expand Down
2 changes: 1 addition & 1 deletion giottotime/experimental/trend_models/exponential_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def predict(self, time_series: pd.DataFrame) -> pd.DataFrame:
Raised if the model is not fitted yet.
"""
check_is_fitted(self, ["model_exponent_"])
check_is_fitted(self)

predictions = np.exp(time_series * self.model_exponent_)
return predictions
Expand Down
2 changes: 1 addition & 1 deletion giottotime/experimental/trend_models/polynomial_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def predict(self, ts: pd.DataFrame) -> pd.DataFrame:
Raised if the model is not fitted yet.
"""
check_is_fitted(self, ["model_weights_"])
check_is_fitted(self)

p = np.poly1d(self.model_weights_)
predictions = p(ts.values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def __init__(
self, constant: int = 2, length: int = 50, output_name: str = "ConstantFeature"
):
super().__init__(output_name)
self._length = length
self.length = length
self.constant = constant

def transform(self, time_series: Optional[pd.DataFrame] = None) -> pd.DataFrame:
Expand All @@ -204,7 +204,7 @@ def transform(self, time_series: Optional[pd.DataFrame] = None) -> pd.DataFrame:
data=self.constant, index=time_series.index
).to_frame()
else:
constant_series = pd.Series(data=[self.constant] * self._length).to_frame()
constant_series = pd.Series(data=[self.constant] * self.length).to_frame()

constant_series_renamed = self._rename_columns(constant_series)
return constant_series_renamed
Expand Down
2 changes: 1 addition & 1 deletion giottotime/models/regressors/linear_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def predict(self, X: pd.DataFrame) -> pd.DataFrame:
The predictions of the model
"""
check_is_fitted(self, ["model_weights_"])
check_is_fitted(self)

predictions = self.model_weights_[0] + np.dot(X, self.model_weights_[1:])
return predictions
12 changes: 6 additions & 6 deletions giottotime/models/time_series_models/gar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, base_model: object, feed_forward: bool = False):
f"{base_model} must implement both 'fit' " f"and 'predict' methods"
)

self._base_model = base_model
self._feed_forward = feed_forward
self.base_model = base_model
self.feed_forward = feed_forward

def fit(self, X: pd.DataFrame, y: pd.DataFrame, **kwargs: object) -> "GAR":
"""Fit the GAR model according to the training data.
Expand All @@ -49,13 +49,13 @@ def fit(self, X: pd.DataFrame, y: pd.DataFrame, **kwargs: object) -> "GAR":
"""
features = X.copy()
models_per_predstep = [deepcopy(self._base_model) for _ in range(y.shape[1])]
models_per_predstep = [deepcopy(self.base_model) for _ in range(y.shape[1])]

for pred_step, model_for_pred_step in enumerate(models_per_predstep):
target_y = y[f"y_{pred_step}"]
model_for_pred_step.fit(features, target_y, **kwargs)

if self._feed_forward:
if self.feed_forward:
predictions = model_for_pred_step.predict(features)
features[f"preds_{pred_step}"] = predictions

Expand Down Expand Up @@ -83,7 +83,7 @@ def predict(self, X: pd.DataFrame) -> pd.DataFrame:
Thrown if the model has not been previously fitted.
"""
check_is_fitted(self, ["models_per_predstep_", "train_features_"])
check_is_fitted(self)

test_features = X.copy()

Expand All @@ -93,7 +93,7 @@ def predict(self, X: pd.DataFrame) -> pd.DataFrame:
model_predictions = model_for_pred_step.predict(test_features)
predictions[f"y_{pred_step}"] = model_predictions

if self._feed_forward:
if self.feed_forward:
test_features[f"preds_{pred_step}"] = model_predictions

return predictions

0 comments on commit c921439

Please sign in to comment.