• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

freqtrade / freqtrade / 9394559170

26 Apr 2024 06:36AM UTC coverage: 94.656% (-0.02%) from 94.674%
9394559170

push

github

xmatthias
Loader should be passed as kwarg for clarity

20280 of 21425 relevant lines covered (94.66%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/freqtrade/freqai/prediction_models/CatboostClassifierMultiTarget.py
1
import logging
1✔
2
import sys
1✔
3
from pathlib import Path
1✔
4
from typing import Any, Dict
1✔
5

6
from catboost import CatBoostClassifier, Pool
1✔
7

8
from freqtrade.freqai.base_models.BaseClassifierModel import BaseClassifierModel
1✔
9
from freqtrade.freqai.base_models.FreqaiMultiOutputClassifier import FreqaiMultiOutputClassifier
1✔
10
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
1✔
11

12

13
logger = logging.getLogger(__name__)
1✔
14

15

16
class CatboostClassifierMultiTarget(BaseClassifierModel):
1✔
17
    """
18
    User created prediction model. The class inherits IFreqaiModel, which
19
    means it has full access to all Frequency AI functionality. Typically,
20
    users would use this to override the common `fit()`, `train()`, or
21
    `predict()` methods to add their custom data handling tools or change
22
    various aspects of the training that cannot be configured via the
23
    top level config.json file.
24
    """
25

26
    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:
1✔
27
        """
28
        User sets up the training and test data to fit their desired model here
29
        :param data_dictionary: the dictionary holding all data for train, test,
30
            labels, weights
31
        :param dk: The datakitchen object for the current coin/model
32
        """
33

34
        cbc = CatBoostClassifier(
1✔
35
            allow_writing_files=True,
36
            loss_function='MultiClass',
37
            train_dir=Path(dk.data_path),
38
            **self.model_training_parameters,
39
        )
40

41
        X = data_dictionary["train_features"]
1✔
42
        y = data_dictionary["train_labels"]
1✔
43

44
        sample_weight = data_dictionary["train_weights"]
1✔
45

46
        eval_sets = [None] * y.shape[1]
1✔
47

48
        if self.freqai_info.get('data_split_parameters', {}).get('test_size', 0.1) != 0:
1✔
49
            eval_sets = [None] * data_dictionary['test_labels'].shape[1]
1✔
50

51
            for i in range(data_dictionary['test_labels'].shape[1]):
1✔
52
                eval_sets[i] = Pool(
1✔
53
                    data=data_dictionary["test_features"],
54
                    label=data_dictionary["test_labels"].iloc[:, i],
55
                    weight=data_dictionary["test_weights"],
56
                )
57

58
        init_model = self.get_init_model(dk.pair)
1✔
59

60
        if init_model:
1✔
61
            init_models = init_model.estimators_
×
62
        else:
63
            init_models = [None] * y.shape[1]
1✔
64

65
        fit_params = []
1✔
66
        for i in range(len(eval_sets)):
1✔
67
            fit_params.append({
1✔
68
                'eval_set': eval_sets[i], 'init_model': init_models[i],
69
                'log_cout': sys.stdout, 'log_cerr': sys.stderr,
70
            })
71

72
        model = FreqaiMultiOutputClassifier(estimator=cbc)
1✔
73
        thread_training = self.freqai_info.get('multitarget_parallel_training', False)
1✔
74
        if thread_training:
1✔
75
            model.n_jobs = y.shape[1]
×
76
        model.fit(X=X, y=y, sample_weight=sample_weight, fit_params=fit_params)
1✔
77

78
        return model
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc