Repository: scikit-learn-contrib/DESlib

Issue:
Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe'
Hi,

I got this error for Single Best method.

Other methods so far were fine, but up to SB, it produced this error:

```
~\anaconda3\lib\site-packages\sklearn\base.py in score(self, X, y, sample_weight)
    367         """
    368         from .metrics import accuracy_score
--> 369         return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
    370 
    371 

~\anaconda3\lib\site-packages\deslib\static\single_best.py in predict(self, X)
    110         self._check_is_fitted()
    111         predicted_labels = self._encode_base_labels(self.best_clf_.predict(X))
--> 112         return self.classes_.take(predicted_labels)
    113 
    114     def predict_proba(self, X):

TypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe'
```

Discussion:

Patch:
diff --git a/deslib/static/base.py b/deslib/static/base.py
index d5b1f59..e72547e 100644
--- a/deslib/static/base.py
+++ b/deslib/static/base.py
@@ -89,7 +89,7 @@ class BaseStaticEnsemble(BaseEstimator, ClassifierMixin):
 
         self._validate_pool()
         # dealing with label encoder
-        self.check_label_encoder()
+        self._check_label_encoder()
         self.y_enc_ = self._setup_label_encoder(y)
 
         self.n_classes_ = self.classes_.size
@@ -97,7 +97,7 @@ class BaseStaticEnsemble(BaseEstimator, ClassifierMixin):
 
         return self
 
-    def check_label_encoder(self):
+    def _check_label_encoder(self):
         # Check if base classifiers are not using LabelEncoder (the case for
         # scikit-learn's ensembles):
         if isinstance(self.pool_classifiers_, BaseEnsemble):
diff --git a/deslib/static/single_best.py b/deslib/static/single_best.py
index 6de5c57..0c8b13a 100644
--- a/deslib/static/single_best.py
+++ b/deslib/static/single_best.py
@@ -113,7 +113,7 @@ class SingleBest(BaseStaticEnsemble):
         X = check_array(X)
         self._check_is_fitted()
         predicted_labels = self._encode_base_labels(self.best_clf_.predict(X))
-        return self.classes_.take(predicted_labels)
+        return self.classes_.take(predicted_labels.astype(np.int))
 
     def predict_proba(self, X):
         """Estimates the posterior probabilities for each class for each sample


Test patch:
diff --git a/deslib/tests/static/test_oracle.py b/deslib/tests/static/test_oracle.py
index bb055e5..d003f48 100644
--- a/deslib/tests/static/test_oracle.py
+++ b/deslib/tests/static/test_oracle.py
@@ -1,9 +1,9 @@
 import numpy as np
-
-from deslib.static.oracle import Oracle
 from sklearn.datasets import make_classification
 from sklearn.ensemble import RandomForestClassifier
 
+from deslib.static.oracle import Oracle
+
 
 def test_predict(create_X_y, create_pool_classifiers):
     X, y = create_X_y
@@ -52,3 +52,15 @@ def test_predict_proba_right_class():
     proba = oracle.predict_proba(X_test, y_test)
     probas_max = np.argmax(proba, axis=1)
     assert np.allclose(probas_max, preds)
+
+
+def test_label_encoder_base_ensemble():
+    from sklearn.ensemble import RandomForestClassifier
+    X, y = make_classification()
+    y[y == 1] = 2
+    y = y.astype(np.float)
+    pool = RandomForestClassifier().fit(X, y)
+    oracle = Oracle(pool)
+    oracle.fit(X, y)
+    pred = oracle.predict(X, y)
+    assert np.isin(oracle.classes_, pred).all()
diff --git a/deslib/tests/static/test_single_best.py b/deslib/tests/static/test_single_best.py
index 1ad2d78..403953a 100644
--- a/deslib/tests/static/test_single_best.py
+++ b/deslib/tests/static/test_single_best.py
@@ -84,6 +84,18 @@ def test_label_encoder(create_label_encoder_test):
     assert np.array_equal(pred, y)
 
 
+def test_label_encoder_base_ensemble():
+    from sklearn.ensemble import RandomForestClassifier
+    X, y = make_classification()
+    y[y == 1] = 2
+    y = y.astype(np.float)
+    pool = RandomForestClassifier().fit(X, y)
+    sb = SingleBest(pool)
+    sb.fit(X, y)
+    pred = sb.predict(X)
+    assert np.isin(sb.classes_, pred).all()
+
+
 def test_different_scorer():
     X, y = make_classification(n_samples=100, random_state=42)
     X_val, y_val = make_classification(n_samples=25, random_state=123)
diff --git a/deslib/tests/static/test_stacked.py b/deslib/tests/static/test_stacked.py
index c60b972..e23f651 100644
--- a/deslib/tests/static/test_stacked.py
+++ b/deslib/tests/static/test_stacked.py
@@ -1,5 +1,6 @@
 import numpy as np
 import pytest
+from sklearn.datasets import make_classification
 from sklearn.linear_model import Perceptron
 from sklearn.tree import DecisionTreeClassifier
 from sklearn.utils.estimator_checks import check_estimator
@@ -48,6 +49,18 @@ def test_label_encoder():
     assert np.array_equal(pred, y)
 
 
+def test_label_encoder_base_ensemble():
+    from sklearn.ensemble import RandomForestClassifier
+    X, y = make_classification()
+    y[y == 1] = 2
+    y = y.astype(np.float)
+    pool = RandomForestClassifier().fit(X, y)
+    st = StackedClassifier(pool)
+    st.fit(X, y)
+    pred = st.predict(X)
+    assert np.isin(st.classes_, pred).all()
+
+
 def test_one_class_meta_dataset(create_X_y):
     X, y = create_X_y
     pool = [DecisionTreeClassifier().fit(X, y) for _ in range(5)]
diff --git a/deslib/tests/static/test_static_selection.py b/deslib/tests/static/test_static_selection.py
index 30f5134..bb7de5f 100644
--- a/deslib/tests/static/test_static_selection.py
+++ b/deslib/tests/static/test_static_selection.py
@@ -75,6 +75,18 @@ def test_label_encoder(create_label_encoder_test):
     assert np.array_equal(pred, y)
 
 
+def test_label_encoder_base_ensemble():
+    from sklearn.ensemble import RandomForestClassifier
+    X, y = make_classification()
+    y[y == 1] = 2
+    y = y.astype(np.float)
+    pool = RandomForestClassifier().fit(X, y)
+    ss = StaticSelection(pool)
+    ss.fit(X, y)
+    pred = ss.predict(X)
+    assert np.isin(ss.classes_, pred).all()
+
+
 def test_predict_proba(example_static_selection):
     X, y, pool = example_static_selection
     expected = np.tile([0.52, 0.48], (y.size, 1))