black formatting on freqai files

This commit is contained in:
robcaulk
2022-07-03 10:59:38 +02:00
parent 106131ff0f
commit ffb39a5029
7 changed files with 508 additions and 427 deletions

View File

@@ -28,8 +28,9 @@ class CatboostPredictionMultiModel(IFreqaiModel):
return dataframe
def train(self, unfiltered_dataframe: DataFrame,
pair: str, dk: FreqaiDataKitchen) -> Tuple[DataFrame, DataFrame]:
def train(
self, unfiltered_dataframe: DataFrame, pair: str, dk: FreqaiDataKitchen
) -> Tuple[DataFrame, DataFrame]:
"""
Filter the training data and train a model to it. Train makes heavy use of the datahkitchen
for storing, saving, loading, and analyzing the data.
@@ -40,8 +41,7 @@ class CatboostPredictionMultiModel(IFreqaiModel):
:model: Trained model which can be used to inference (self.predict)
"""
logger.info('--------------------Starting training '
f'{pair} --------------------')
logger.info("--------------------Starting training " f"{pair} --------------------")
# unfiltered_labels = self.make_labels(unfiltered_dataframe, dk)
# filter the features requested by user in the configuration file and elegantly handle NaNs
@@ -61,13 +61,14 @@ class CatboostPredictionMultiModel(IFreqaiModel):
# optional additional data cleaning/analysis
self.data_cleaning_train(dk)
logger.info(f'Training model on {len(dk.data_dictionary["train_features"].columns)}'
' features')
logger.info(
f'Training model on {len(dk.data_dictionary["train_features"].columns)}' " features"
)
logger.info(f'Training model on {len(data_dictionary["train_features"])} data points')
model = self.fit(data_dictionary)
logger.info(f'--------------------done training {pair}--------------------')
logger.info(f"--------------------done training {pair}--------------------")
return model
@@ -80,22 +81,26 @@ class CatboostPredictionMultiModel(IFreqaiModel):
"""
cbr = CatBoostRegressor(
allow_writing_files=False, gpu_ram_part=0.5,
verbose=100, early_stopping_rounds=400, **self.model_training_parameters
allow_writing_files=False,
gpu_ram_part=0.5,
verbose=100,
early_stopping_rounds=400,
**self.model_training_parameters,
)
X = data_dictionary["train_features"]
y = data_dictionary["train_labels"]
# eval_set = (data_dictionary["test_features"], data_dictionary["test_labels"])
sample_weight = data_dictionary['train_weights']
sample_weight = data_dictionary["train_weights"]
model = MultiOutputRegressor(estimator=cbr)
model.fit(X=X, y=y, sample_weight=sample_weight) # , eval_set=eval_set)
return model
def predict(self, unfiltered_dataframe: DataFrame,
dk: FreqaiDataKitchen, first: bool = False) -> Tuple[DataFrame, DataFrame]:
def predict(
self, unfiltered_dataframe: DataFrame, dk: FreqaiDataKitchen, first: bool = False
) -> Tuple[DataFrame, DataFrame]:
"""
Filter the prediction features data and predict with it.
:param: unfiltered_dataframe: Full dataframe for the current backtest period.
@@ -119,8 +124,10 @@ class CatboostPredictionMultiModel(IFreqaiModel):
pred_df = DataFrame(predictions, columns=dk.label_list)
for label in dk.label_list:
pred_df[label] = ((pred_df[label] + 1) *
(dk.data["labels_max"][label] -
dk.data["labels_min"][label]) / 2) + dk.data["labels_min"][label]
pred_df[label] = (
(pred_df[label] + 1)
* (dk.data["labels_max"][label] - dk.data["labels_min"][label])
/ 2
) + dk.data["labels_min"][label]
return (pred_df, dk.do_predict)