本文整理汇总了Python中sklearn.pipeline.make_union方法的典型用法代码示例。如果您正苦于以下问题:Python pipeline.make_union方法的具体用法?Python pipeline.make_union怎么用?Python pipeline.make_union使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.pipeline
的用法示例。
在下文中一共展示了pipeline.make_union方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_missing_indicator_with_imputer
# 需要导入模块: from sklearn import pipeline [as 别名]
# 或者: from sklearn.pipeline import make_union [as 别名]
def test_missing_indicator_with_imputer(X, missing_values, X_trans_exp):
trans = make_union(
SimpleImputer(missing_values=missing_values, strategy='most_frequent'),
MissingIndicator(missing_values=missing_values)
)
X_trans = trans.fit_transform(X)
assert_array_equal(X_trans, X_trans_exp)
示例2: test_make_union
# 需要导入模块: from sklearn import pipeline [as 别名]
# 或者: from sklearn.pipeline import make_union [as 别名]
def test_make_union():
pca = PCA(svd_solver='full')
mock = Transf()
fu = make_union(pca, mock)
names, transformers = zip(*fu.transformer_list)
assert_equal(names, ("pca", "transf"))
assert_equal(transformers, (pca, mock))
示例3: test_make_union_kwargs
# 需要导入模块: from sklearn import pipeline [as 别名]
# 或者: from sklearn.pipeline import make_union [as 别名]
def test_make_union_kwargs():
pca = PCA(svd_solver='full')
mock = Transf()
fu = make_union(pca, mock, n_jobs=3)
assert_equal(fu.transformer_list, make_union(pca, mock).transformer_list)
assert_equal(3, fu.n_jobs)
# invalid keyword parameters should raise an error message
assert_raise_message(
TypeError,
'Unknown keyword arguments: "transformer_weights"',
make_union, pca, mock, transformer_weights={'pca': 10, 'Transf': 1}
)
示例4: main
# 需要导入模块: from sklearn import pipeline [as 别名]
# 或者: from sklearn.pipeline import make_union [as 别名]
def main():
vectorizer = make_union(
on_field('name', Tfidf(max_features=100000, token_pattern='\w+')),
on_field('text', Tfidf(max_features=100000, token_pattern='\w+', ngram_range=(1, 2))),
on_field(['shipping', 'item_condition_id'],
FunctionTransformer(to_records, validate=False), DictVectorizer()),
n_jobs=4)
y_scaler = StandardScaler()
with timer('process train'):
train = pd.read_table('../input/train.tsv')
train = train[train['price'] > 0].reset_index(drop=True)
cv = KFold(n_splits=20, shuffle=True, random_state=42)
train_ids, valid_ids = next(cv.split(train))
train, valid = train.iloc[train_ids], train.iloc[valid_ids]
y_train = y_scaler.fit_transform(np.log1p(train['price'].values.reshape(-1, 1)))
X_train = vectorizer.fit_transform(preprocess(train)).astype(np.float32)
print(f'X_train: {X_train.shape} of {X_train.dtype}')
del train
with timer('process valid'):
X_valid = vectorizer.transform(preprocess(valid)).astype(np.float32)
with ThreadPool(processes=4) as pool:
Xb_train, Xb_valid = [x.astype(np.bool).astype(np.float32) for x in [X_train, X_valid]]
xs = [[Xb_train, Xb_valid], [X_train, X_valid]] * 2
y_pred = np.mean(pool.map(partial(fit_predict, y_train=y_train), xs), axis=0)
y_pred = np.expm1(y_scaler.inverse_transform(y_pred.reshape(-1, 1))[:, 0])
print('Valid RMSLE: {:.4f}'.format(np.sqrt(mean_squared_log_error(valid['price'], y_pred))))
示例5: __init__
# 需要导入模块: from sklearn import pipeline [as 别名]
# 或者: from sklearn.pipeline import make_union [as 别名]
def __init__(self, training_values=None, training_targets=None):
self.vectorizer = make_union(TfidfVectorizer(), PostTransformer())
# Set using parameter_search. TODO: review after updating
# corpus.
self.classifier = svm.LinearSVC(C=1, loss='squared_hinge', multi_class='ovr', class_weight='balanced', tol=1e-6)
if training_values is not None and training_targets is not None:
self.fit(training_values, training_targets)
示例6: test_objectmapper
# 需要导入模块: from sklearn import pipeline [as 别名]
# 或者: from sklearn.pipeline import make_union [as 别名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.pipeline.Pipeline, pipeline.Pipeline)
self.assertIs(df.pipeline.FeatureUnion, pipeline.FeatureUnion)
self.assertIs(df.pipeline.make_pipeline, pipeline.make_pipeline)
self.assertIs(df.pipeline.make_union, pipeline.make_union)