Repository navigation
Closed
Labels
Description
From the original paper (https://www.intlpress.com/site/pub/files/_fulltext/journals/sii/2009/0002/0003/SII-2009-0002-0003-a008.pdf), it is mentioned that the decision function of each weak-learner should have a symmetry such that the sum of the decision should be equal to zero.
However, this is not the case:
In [8]: from sklearn.ensemble import AdaBoostClassifier
...: from sklearn.datasets import make_classification
...: X, y = make_classification(n_samples=1000, n_features=4,
...: n_informative=2, n_redundant=0,
...: random_state=0, shuffle=False, n_classes=3, n_clusters_per_class=1)
...: clf = AdaBoostClassifier(n_estimators=1, random_state=0, algorithm="SAMME")
...: clf.fit(X, y)
Out[8]: AdaBoostClassifier(algorithm='SAMME', n_estimators=1, random_state=0)
In [9]: clf.decision_function(X)
Out[9]:
array([[0., 0., 1.],
[1., 0., 0.],
[1., 0., 0.],
...,
[0., 0., 1.],
[0., 0., 1.],
[0., 0., 1.]])Here, the 0. entry should be weighted to -0.5 instead. However, this is the case for the SAMME.R algorithm:
In [10]: from sklearn.ensemble import AdaBoostClassifier
...: from sklearn.datasets import make_classification
...: X, y = make_classification(n_samples=1000, n_features=4,
...: n_informative=2, n_redundant=0,
...: random_state=0, shuffle=False, n_classes=3, n_clusters_per_class=1)
...: clf = AdaBoostClassifier(n_estimators=1, random_state=0, algorithm="SAMME.R")
...: clf.fit(X, y)
Out[10]: AdaBoostClassifier(n_estimators=1, random_state=0)
In [11]: clf.decision_function(X)
Out[11]:
array([[-2.65127772, 1.2727494 , 1.37852832],
[ 4.84854331, -1.10251582, -3.7460275 ],
[ 4.84854331, -1.10251582, -3.7460275 ],
...,
[-2.65127772, 1.2727494 , 1.37852832],
[-2.65127772, 1.2727494 , 1.37852832],
[-2.65127772, 1.2727494 , 1.37852832]])
In [12]: clf.decision_function(X).sum(axis=1)
Out[12]:
array([4.4408921e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00,
4.4408921e-16, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00,
...
])I think that it would be better to exactly get the implementation proposed by the algorithm.
Activity