Skip to content

Commit

Permalink
Inheritance in OnehotTransactions (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
iaroslav-ai authored and rasbt committed Sep 19, 2017
1 parent 4a24604 commit 958cb83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ The CHANGELOG for the current development version is available at

- The `'support'` column returned by `frequent_patterns.association_rules` was changed to compute the support of "antecedant union consequent", and new `antecedant support'` and `'consequent support'` column were added to avoid ambiguity. [#245](https://github.com/rasbt/mlxtend/pull/245)
- Added `'leverage'` and `'conviction` as evaluation metrics to the `frequent_patterns.association_rules` function. [#246](https://github.com/rasbt/mlxtend/pull/246) & [#247](https://github.com/rasbt/mlxtend/pull/247)
- Allow the `OnehotTransactions` to be cloned via scikit-learn's `clone` function, which is required by e.g., scikit-learn's `FeatureUnion` or `GridSearchCV` (via [Iaroslav Shcherbatyi](https://github.com/iaroslav-ai)). [#249](https://github.com/rasbt/mlxtend/pull/249)

##### Bug Fixes

-
- Allow `OneHot`


### Version 0.8.0 (2017-09-09)
Expand Down
3 changes: 2 additions & 1 deletion mlxtend/preprocessing/onehot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# License: BSD 3 clause

import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin


def one_hot(y, num_labels='auto', dtype='float'):
Expand Down Expand Up @@ -51,7 +52,7 @@ def one_hot(y, num_labels='auto', dtype='float'):
return ary.astype(dtype)


class OnehotTransactions(object):
class OnehotTransactions(BaseEstimator, TransformerMixin):
"""One-hot encoder class for transaction data in Python lists
Parameters
Expand Down
18 changes: 18 additions & 0 deletions mlxtend/preprocessing/tests/test_onehot_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import numpy as np
from mlxtend.preprocessing import OnehotTransactions
from sklearn.base import clone
from mlxtend.utils import assert_raises


dataset = [['Apple', 'Beer', 'Rice', 'Chicken'],
Expand Down Expand Up @@ -63,3 +65,19 @@ def test_inverse_transform():
oht.fit(dataset)
np.testing.assert_array_equal(np.array(data_sorted),
np.array(oht.inverse_transform(expect)))


def test_cloning():

oht = OnehotTransactions()
oht.fit(dataset)
oht2 = clone(oht)

msg = ("'OnehotTransactions' object has no attribute 'columns_'")
assert_raises(AttributeError,
msg,
oht2.transform,
dataset)

trans = oht2.fit_transform(dataset)
np.testing.assert_array_equal(expect, trans)

0 comments on commit 958cb83

Please sign in to comment.