-
Notifications
You must be signed in to change notification settings - Fork 12
/
ada_boost.py
91 lines (71 loc) · 2.77 KB
/
ada_boost.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from niaaml.classifiers.classifier import Classifier
from niaaml.utilities import MinMax
from niaaml.utilities import ParameterDefinition
from sklearn.ensemble import AdaBoostClassifier
import numpy as np
import warnings
from sklearn.exceptions import (
ConvergenceWarning,
DataConversionWarning,
DataDimensionalityWarning,
EfficiencyWarning,
FitFailedWarning,
UndefinedMetricWarning,
)
__all__ = ["AdaBoost"]
class AdaBoost(Classifier):
r"""Implementation of AdaBoost classifier.
Date:
2020
Author:
Luka Pečnik
License:
MIT
Reference:
Y. Freund, R. Schapire, “A Decision-Theoretic Generalization of on-Line Learning and an Application to Boosting”, 1995.
Documentation:
https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostClassifier.html
See Also:
* :class:`niaaml.classifiers.Classifier`
"""
Name = "AdaBoost"
def __init__(self, **kwargs):
r"""Initialize AdaBoost instance."""
warnings.filterwarnings(action="ignore", category=ConvergenceWarning)
warnings.filterwarnings(action="ignore", category=DataConversionWarning)
warnings.filterwarnings(action="ignore", category=DataDimensionalityWarning)
warnings.filterwarnings(action="ignore", category=EfficiencyWarning)
warnings.filterwarnings(action="ignore", category=FitFailedWarning)
warnings.filterwarnings(action="ignore", category=UndefinedMetricWarning)
self._params = dict(
n_estimators=ParameterDefinition(MinMax(min=10, max=111), np.uint),
algorithm=ParameterDefinition(["SAMME"]),
)
self.__ada_boost = AdaBoostClassifier(algorithm='SAMME')
def set_parameters(self, **kwargs):
r"""Set the parameters/arguments of the algorithm."""
self.__ada_boost.set_params(**kwargs)
def fit(self, x, y, **kwargs):
r"""Fit AdaBoost.
Arguments:
x (pandas.core.frame.DataFrame): n samples to classify.
y (pandas.core.series.Series): n classes of the samples in the x array.
"""
self.__ada_boost.fit(x, y)
def predict(self, x, **kwargs):
r"""Predict class for each sample (row) in x.
Arguments:
x (pandas.core.frame.DataFrame): n samples to classify.
Returns:
pandas.core.series.Series: n predicted classes.
"""
return self.__ada_boost.predict(x)
def to_string(self):
r"""User friendly representation of the object.
Returns:
str: User friendly representation of the object.
"""
return Classifier.to_string(self).format(
name=self.Name,
args=self._parameters_to_string(self.__ada_boost.get_params()),
)