-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add label encoder The label encoder that convert original labels into integers (0, 1, 2, ...) * check dtype and add comments * Bug fix * bug fix * Disable partial mode Label encoder does not deal with partial mode yet. * Label encoder with scikit-learn * bug fix * Add utility vars in __init__() * Bug fix There is a typo. :) * black formatting * Update cascade.py * modify save and load * fix format * Add testing case for label encoder * fix format * fix format * black formatting * add CHANGELOG.rst
- Loading branch information
Showing
3 changed files
with
136 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import numpy as np | ||
from numpy.testing import assert_array_equal | ||
|
||
from sklearn.datasets import load_digits | ||
from deepforest import CascadeForestClassifier | ||
|
||
|
||
def test_model_input_label_encoder(): | ||
"""Test if the model behaves the same with and without label encoding.""" | ||
|
||
# Load data | ||
X, y = load_digits(return_X_y=True) | ||
y_as_str = np.char.add("label_", y.astype(str)) | ||
|
||
# Train model on integer labels. Labels should look like: 1, 2, 3, ... | ||
model = CascadeForestClassifier(random_state=1) | ||
model.fit(X, y) | ||
y_pred_int_labels = model.predict(X) | ||
|
||
# Train model on string labels. Labels should look like: "label_1", "label_2", "label_3", ... | ||
model = CascadeForestClassifier(random_state=1) | ||
model.fit(X, y_as_str) | ||
y_pred_str_labels = model.predict(X) | ||
|
||
# Check if the underlying data are the same | ||
y_pred_int_labels_as_str = np.char.add( | ||
"label_", y_pred_int_labels.astype(str) | ||
) | ||
assert_array_equal(y_pred_str_labels, y_pred_int_labels_as_str) | ||
|
||
# Clean up buffer | ||
model.clean() |