def test_sparse(): copy = CopyTransformer() tfidf = TfidfTransformer() X_t = tfidf.fit_transform([[1, 2, 3]]) assert issparse(X_t) X_dense = copy.transform(X_t).toarray() expect = np.array([[0.26726124, 0.53452248, 0.80178373]]) assert np.allclose(X_dense, expect)
def test_pipeline(): param_grid = [{'logisticregression__C': [1, 0.1, 10]}] pipe = make_pipeline(StandardScaler(), CopyTransformer(), LogisticRegression()) grid = GridSearchCV(pipe, param_grid, cv=3, n_jobs=1) grid.fit(X, y)
def test_pipeline(): param_grid = [{'logisticregression__C': [1, 0.1, 10]}] pipe = make_pipeline( StandardScaler(), CopyTransformer(), LogisticRegression(solver='liblinear', multi_class='ovr')) grid = GridSearchCV(pipe, param_grid, cv=3, n_jobs=1, iid=False) grid.fit(X, y)
def test_copy_failtype(): copy = CopyTransformer() expect = ("X must be a list or NumPy array or SciPy sparse array." " Found <class 'int'>") if sys.version_info < (3, 0): expect = expect.replace('class', 'type') assert_raises(ValueError, expect, copy.transform, 1)
def test_copy(): copy = CopyTransformer() np.testing.assert_array_equal(X, copy.transform(X))
from mlxtend.preprocessing import CopyTransformer trans = CopyTransformer() meta = { 'id': 'raw1', 'name': 'Raw Features', 'description': ( "Just copy raw features to comply with " "this preprocessing framewortk."), 'keywords': ['CopyTransformer', 'mlxtend'], 'feature_names_prefix': 'raw' }