Skip to content

Commit

Permalink
Merge pull request #6 from messier16/fix-bugged_unseen_labels
Browse files Browse the repository at this point in the history
Fix error in CategoryEncoder transform
  • Loading branch information
fferegrino authored Nov 5, 2018
2 parents f1fb37b + cbd8d4f commit ceb24b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion m16_mlutils/pipeline/CategoryEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ def transform(self, X):
o = self.one_hot_encoders[c].transform(
values.reshape(len(values), 1))
except (KeyError, ValueError):
o = np.zeros((1, len(self.label_encoders[c].classes_)))
o = np.zeros((len(X), len(self.label_encoders[c].classes_)))
one_hots.append(o)
return np.concatenate(one_hots, axis=1)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from setuptools.command.install import install

# Package version
VERSION = "0.4.3"
VERSION = "0.4.4"

class VerifyVersionCommand(install):
"""Custom command to verify that the git tag matches our version"""
Expand Down
9 changes: 6 additions & 3 deletions tests/test_CategoryEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ def test_previously_unseen(self):
})

test = pd.DataFrame({
'l': ['z']
'l': ['z', 'y']
})

encoder = CategoryEncoder()

expected = self.array([[0,0,0]])
expected = self.array([
[0, 0, 0],
[0, 0, 0],
])

encoder.fit(train)
actual = encoder.transform(test)

self.assertArrayEqual(expected, actual)
self.assertArrayEqual(expected, actual)

0 comments on commit ceb24b7

Please sign in to comment.