Skip to content

AdaBoostClassifier predict() gives incorrect label #15732

@prabhat00155

Description

@prabhat00155

Description

AdaBoostClassifier predict() labels don't match up with the results of predict_proba(). Here is an example:
model.predict_proba(X_test) gives this: array([0.51176443, 0.48823557]), where as model.predict(X_test) gives 1 instead of 0.

Steps/Code to Reproduce

import numpy as np
from sklearn.datasets import make_classification
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier

X, y = make_classification(n_features=100, n_samples=1000, random_state=42, n_classes=2, n_informative=7)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)

model = AdaBoostClassifier(n_estimators=2, algorithm="SAMME", random_state=42,
                                                base_estimator=DecisionTreeClassifier(
                                                    max_depth=5, random_state=42))
model.fit(X_train, y_train)
print(np.mean(model.predict(X_test) == np.argmax(model.predict_proba(X_test), axis=1)))

Expected Results

1.0

Actual Results

0.93

Versions

System:
python: 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
executable: /Users/prroy/Documents/MachineLearning/onnx_projects/tmp_env/bin/python
machine: Darwin-19.0.0-x86_64-i386-64bit

Python deps:
pip: 18.1
setuptools: 40.6.2
sklearn: 0.21.3
numpy: 1.17.2
scipy: 1.3.1
Cython: None
pandas: 0.25.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugModerateAnything that requires some knowledge of conventions and best practiceshelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions