File: catgb.py

package info (click to toggle)
orange3 3.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,912 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (30 lines) | stat: -rw-r--r-- 804 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Tuple

import numpy as np

import catboost

from Orange.base import CatGBBaseLearner, CatGBModel
from Orange.classification import Learner, Model
from Orange.data import Variable, DiscreteVariable, Table
from Orange.preprocess.score import LearnerScorer

__all__ = ["CatGBClassifier"]


class _FeatureScorerMixin(LearnerScorer):
    feature_type = Variable
    class_type = DiscreteVariable

    def score(self, data: Table) -> Tuple[np.ndarray, Tuple[Variable]]:
        model: CatGBClassifier = self(data)
        return model.cat_model.feature_importances_, model.domain.attributes


class CatGBClsModel(CatGBModel, Model):
    pass


class CatGBClassifier(CatGBBaseLearner, Learner, _FeatureScorerMixin):
    __wraps__ = catboost.CatBoostClassifier
    __returns__ = CatGBClsModel