• 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/LightGBMClassifierMultiTarget.py
1
import logging
1✔
2
from typing import Any, Dict
1✔
3

4
from lightgbm import LGBMClassifier
1✔
5

6
from freqtrade.freqai.base_models.BaseClassifierModel import BaseClassifierModel
1✔
7
from freqtrade.freqai.base_models.FreqaiMultiOutputClassifier import FreqaiMultiOutputClassifier
1✔
8
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
1✔
9

10

11
logger = logging.getLogger(__name__)
1✔
12

13

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

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

32
        lgb = LGBMClassifier(**self.model_training_parameters)
1✔
33

34
        X = data_dictionary["train_features"]
1✔
35
        y = data_dictionary["train_labels"]
1✔
36
        sample_weight = data_dictionary["train_weights"]
1✔
37

38
        eval_weights = None
1✔
39
        eval_sets = [None] * y.shape[1]
1✔
40

41
        if self.freqai_info.get('data_split_parameters', {}).get('test_size', 0.1) != 0:
1✔
42
            eval_weights = [data_dictionary["test_weights"]]
1✔
43
            eval_sets = [(None, None)] * data_dictionary['test_labels'].shape[1]  # type: ignore
1✔
44
            for i in range(data_dictionary['test_labels'].shape[1]):
1✔
45
                eval_sets[i] = (  # type: ignore
1✔
46
                    data_dictionary["test_features"],
47
                    data_dictionary["test_labels"].iloc[:, i]
48
                )
49

50
        init_model = self.get_init_model(dk.pair)
1✔
51
        if init_model:
1✔
52
            init_models = init_model.estimators_
×
53
        else:
54
            init_models = [None] * y.shape[1]
1✔
55

56
        fit_params = []
1✔
57
        for i in range(len(eval_sets)):
1✔
58
            fit_params.append(
1✔
59
                {'eval_set': eval_sets[i], 'eval_sample_weight': eval_weights,
60
                 'init_model': init_models[i]})
61

62
        model = FreqaiMultiOutputClassifier(estimator=lgb)
1✔
63
        thread_training = self.freqai_info.get('multitarget_parallel_training', False)
1✔
64
        if thread_training:
1✔
65
            model.n_jobs = y.shape[1]
×
66
        model.fit(X=X, y=y, sample_weight=sample_weight, fit_params=fit_params)
1✔
67

68
        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