Skip to content

Commit 989b23f

Browse files
import one hot encoder Pt.6
1 parent ba8d759 commit 989b23f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "genbooster"
7-
version = "0.6.6"
7+
version = "0.6.7"
88
description = "A fast boosting implementation using Rust and Python"
99
requires-python = ">=3.7"
1010
authors = [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="genbooster",
5-
version="0.6.6",
5+
version="0.6.7",
66
packages=find_packages(where="src"),
77
package_dir={"": "src"},
88
install_requires=[

src/genbooster/adaboostclassifier.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from sklearn.base import BaseEstimator, ClassifierMixin
55
from sklearn.preprocessing import StandardScaler
66
from sklearn.tree import ExtraTreeRegressor
7-
from pythonutils import one_hot_encode2
87
from .adaboostregressor import AdaBoostRegressor
98

109

@@ -146,4 +145,21 @@ def predict_proba(self, X) -> np.ndarray:
146145
raw_preds = np.asarray([booster.predict(X) for booster in self.boosters_])
147146
shifted_preds = raw_preds - np.max(raw_preds, axis=0)
148147
exp_preds = np.exp(shifted_preds)
149-
return exp_preds / np.sum(exp_preds, axis=0)
148+
return exp_preds / np.sum(exp_preds, axis=0)
149+
150+
# one-hot encoding
151+
def one_hot_encode2(y, n_classes):
152+
# Convert pandas Series or DataFrame to numpy array
153+
if hasattr(y, 'values'):
154+
y = np.asarray(y.values, dtype=np.int64)
155+
else:
156+
y = np.asarray(y, dtype=np.int64)
157+
158+
# Initialize the one-hot encoded matrix
159+
res = np.zeros((len(y), n_classes))
160+
161+
# Fill in the 1s
162+
for i in range(len(y)):
163+
res[i, y[i]] = 1
164+
165+
return res

0 commit comments

Comments
 (0)