Skip to content

Commit

Permalink
Add encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mirand863 committed Apr 23, 2024
1 parent 097a58e commit cdb81fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 6 additions & 3 deletions hiclass/HierarchicalClassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import abc
import hashlib
import logging
import pickle

import networkx as nx
import numpy as np
import pickle
from joblib import Parallel, delayed
from sklearn.base import BaseEstimator
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import LabelEncoder
from sklearn.utils.validation import _check_sample_weight

try:
Expand Down Expand Up @@ -215,7 +215,10 @@ def _disambiguate(self):
child = str(self.y_[i, j])
row.append(parent + self.separator_ + child)
new_y.append(np.asarray(row, dtype=np.str_))
self.y_ = np.array(new_y)
new_y = np.array(new_y)
self.label_encoder_ = LabelEncoder()
self.label_encoder_.fit(new_y)
self.y_ = self.label_encoder_.transform(new_y)

def _create_digraph(self):
# Create DiGraph
Expand Down
9 changes: 3 additions & 6 deletions hiclass/LocalClassifierPerLevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"""

import hashlib
import numpy as np
import pickle
from copy import deepcopy
from joblib import Parallel, delayed
from os.path import exists

import numpy as np
from joblib import Parallel, delayed
from sklearn.base import BaseEstimator
from sklearn.preprocessing import LabelEncoder
from sklearn.utils.validation import check_array, check_is_fitted

from hiclass.ConstantClassifier import ConstantClassifier
Expand Down Expand Up @@ -273,9 +273,6 @@ def _fit_classifier(self, level, separator):
classifier = ConstantClassifier()
if not self.bert:
try:
label_encoder = LabelEncoder()
label_encoder.fit(y)
y = label_encoder.transform(y)
classifier.fit(X, y, sample_weight)
except TypeError:
classifier.fit(X, y)
Expand Down
9 changes: 3 additions & 6 deletions hiclass/LocalClassifierPerParentNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"""

import hashlib
import networkx as nx
import numpy as np
import pickle
from copy import deepcopy
from os.path import exists

import networkx as nx
import numpy as np
from sklearn.base import BaseEstimator
from sklearn.preprocessing import LabelEncoder
from sklearn.utils.validation import check_array, check_is_fitted

from hiclass.ConstantClassifier import ConstantClassifier
Expand Down Expand Up @@ -231,9 +231,6 @@ def _fit_classifier(self, node):
classifier = ConstantClassifier()
if not self.bert:
try:
label_encoder = LabelEncoder()
label_encoder.fit(y)
y = label_encoder.transform(y)
classifier.fit(X, y, sample_weight)
except TypeError:
classifier.fit(X, y)
Expand Down

0 comments on commit cdb81fe

Please sign in to comment.