Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
clara-de-smet committed Oct 11, 2024
1 parent 873e984 commit 5dbed25
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
6 changes: 2 additions & 4 deletions openstef/model/regressors/custom_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ class CustomOpenstfRegressor(OpenstfRegressor):

@staticmethod
@abstractmethod
def valid_kwargs() -> list[str]:
...
def valid_kwargs() -> list[str]: ...

@classmethod
@abstractmethod
def objective(self) -> Type[RegressorObjective]:
...
def objective(self) -> Type[RegressorObjective]: ...


def load_custom_model(custom_model_path) -> CustomOpenstfRegressor:
Expand Down
7 changes: 5 additions & 2 deletions openstef/model/regressors/linear_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def __init__(
missing_values: Value to be considered as missing value
imputation_strategy: Imputation strategy
fill_value: Fill value
weight_scale_percentile: Percentile used in scaling of the samples
weight_exponent: Exponent used in sample weighing
weight_floor: Minimum weight for samples
no_fill_future_values_features: The features for which it does not make sense
to fill future values. Rows that contain trailing null values for these
features will be removed from the data.
Expand Down Expand Up @@ -203,8 +206,8 @@ def fit(self, x: pd.DataFrame, y: pd.Series, **kwargs) -> RegressorMixin:
return self

def _calculate_sample_weights(self, y: np.array):
"""Calculate sample weights based on the y values of arbitrary scale. The resulting weights are in the range [0,
1] and are used to put more emphasis on certain samples.
"""Calculate sample weights based on the y values of arbitrary scale.
The resulting weights are in the range [0, 1] and are used to put more emphasis on certain samples.
The sample weighting function does:
* Rescale data to a [-1, 1] range using quantile scaling. 90% of the data will
Expand Down
6 changes: 3 additions & 3 deletions openstef/model/standard_deviation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def generate_standard_deviation_data(self, model: RegressorMixin) -> RegressorMi
confidence_interval_horizon = self._calculate_standard_deviation(
sub_val.iloc[:, 0], predicted
)
confidence_interval_horizon[
"horizon"
] = horizon # Label with respective horizon
confidence_interval_horizon["horizon"] = (
horizon # Label with respective horizon
)
self.standard_deviation = pd.concat(
[self.standard_deviation, confidence_interval_horizon]
)
Expand Down
6 changes: 3 additions & 3 deletions test/unit/data_classes/test_split_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def test_load(self):

# Non Callable object
split_func_dc = copy.deepcopy(self.split_func_with_strings)
split_func_dc[
"function"
] = "test.unit.data_classes.test_split_function.dummy_not_func"
split_func_dc["function"] = (
"test.unit.data_classes.test_split_function.dummy_not_func"
)
with self.assertRaises(ValueError):
_ = split_func_dc.load()

Expand Down
3 changes: 1 addition & 2 deletions test/unit/model/test_custom_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
)


class DummyObjective(RegressorObjective):
...
class DummyObjective(RegressorObjective): ...


class DummyRegressor(CustomOpenstfRegressor):
Expand Down
12 changes: 6 additions & 6 deletions test/unit/pipeline/test_create_basecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def setUp(self) -> None:
self.PJ = TestData.get_prediction_job(pid=307)
forecast_input = TestData.load("reference_sets/307-test-data.csv")
# Set last 7 days to nan, just like operationally
forecast_input.loc[
forecast_input.index.max() - timedelta(days=7) :, "load"
] = np.nan
forecast_input.loc[forecast_input.index.max() - timedelta(days=7) :, "load"] = (
np.nan
)
# Shift so the input matches 'now'
offset_seconds = (
pd.to_datetime(datetime.utcnow(), utc=True)
Expand Down Expand Up @@ -80,9 +80,9 @@ def test_create_basecase_forecast_pipeline_constant_load(self):
forecast_input.loc[
forecast_input.index.max() - timedelta(days=21) :, "load"
] = forecast_input.loc[forecast_input.index.max() - timedelta(days=14), "load"]
forecast_input.loc[
forecast_input.index.max() - timedelta(days=7) :, "load"
] = np.nan
forecast_input.loc[forecast_input.index.max() - timedelta(days=7) :, "load"] = (
np.nan
)

base_case_forecast = create_basecase_forecast_pipeline(self.PJ, forecast_input)

Expand Down
3 changes: 1 addition & 2 deletions test/unit/pipeline/test_pipeline_train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
from openstef.validation import validation


class DummyObjective(RegressorObjective):
...
class DummyObjective(RegressorObjective): ...


class DummyRegressor(CustomOpenstfRegressor):
Expand Down

0 comments on commit 5dbed25

Please sign in to comment.