当前位置: 首页>>代码示例>>Python>>正文


Python compose.make_column_transformer方法代码示例

本文整理汇总了Python中sklearn.compose.make_column_transformer方法的典型用法代码示例。如果您正苦于以下问题:Python compose.make_column_transformer方法的具体用法?Python compose.make_column_transformer怎么用?Python compose.make_column_transformer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.compose的用法示例。


在下文中一共展示了compose.make_column_transformer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_make_column_transformer_kwargs

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def test_make_column_transformer_kwargs():
    scaler = StandardScaler()
    norm = Normalizer()
    ct = make_column_transformer((scaler, 'first'), (norm, ['second']),
                                 n_jobs=3, remainder='drop',
                                 sparse_threshold=0.5)
    assert_equal(ct.transformers, make_column_transformer(
        (scaler, 'first'), (norm, ['second'])).transformers)
    assert_equal(ct.n_jobs, 3)
    assert_equal(ct.remainder, 'drop')
    assert_equal(ct.sparse_threshold, 0.5)
    # invalid keyword parameters should raise an error message
    assert_raise_message(
        TypeError,
        'Unknown keyword arguments: "transformer_weights"',
        make_column_transformer, (scaler, 'first'), (norm, ['second']),
        transformer_weights={'pca': 10, 'Transf': 1}
    ) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:20,代码来源:test_column_transformer.py

示例2: get_estimator

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def get_estimator():

    categorical_cols = ['Sex', 'Pclass', 'Embarked']
    numerical_cols = ['Age', 'SibSp', 'Parch', 'Fare']

    preprocessor = make_column_transformer(
        (OneHotEncoder(handle_unknown='ignore'), categorical_cols),
        (SimpleImputer(strategy='constant', fill_value=-1), numerical_cols),
    )

    pipeline = Pipeline([
        ('transformer', preprocessor),
        ('classifier', LogisticRegression()),
    ])

    return pipeline 
开发者ID:paris-saclay-cds,项目名称:ramp-workflow,代码行数:18,代码来源:estimator.py

示例3: get_estimator

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def get_estimator():
    merge_transformer = FunctionTransformer(_merge_external_data,
                                            validate=False)
    categorical_cols = ['Arrival', 'Departure']
    drop_col = ['DateOfDeparture']
    preoprocessor = make_column_transformer(
        (OneHotEncoder(handle_unknown='ignore'), categorical_cols),
        ('drop', drop_col),
        remainder='passthrough'
    )
    pipeline = Pipeline(steps=[
        ('merge', merge_transformer),
        ('transfomer', preoprocessor),
        ('regressor', RandomForestRegressor(n_estimators=10, max_depth=10,
                                            max_features=10)),
    ])
    return pipeline 
开发者ID:paris-saclay-cds,项目名称:ramp-workflow,代码行数:19,代码来源:estimator.py

示例4: test_column_transformer_mixed_cols_sparse

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def test_column_transformer_mixed_cols_sparse():
    df = np.array([['a', 1, True],
                   ['b', 2, False]],
                  dtype='O')

    ct = make_column_transformer(
        (OneHotEncoder(), [0]),
        ('passthrough', [1, 2]),
        sparse_threshold=1.0
    )

    # this shouldn't fail, since boolean can be coerced into a numeric
    # See: https://github.com/scikit-learn/scikit-learn/issues/11912
    X_trans = ct.fit_transform(df)
    assert X_trans.getformat() == 'csr'
    assert_array_equal(X_trans.toarray(), np.array([[1, 0, 1, 1],
                                                    [0, 1, 2, 0]]))

    ct = make_column_transformer(
        (OneHotEncoder(), [0]),
        ('passthrough', [0]),
        sparse_threshold=1.0
    )
    with pytest.raises(ValueError,
                       match="For a sparse output, all columns should"):
        # this fails since strings `a` and `b` cannot be
        # coerced into a numeric.
        ct.fit_transform(df) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:30,代码来源:test_column_transformer.py

示例5: test_make_column_transformer

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def test_make_column_transformer():
    scaler = StandardScaler()
    norm = Normalizer()
    ct = make_column_transformer((scaler, 'first'), (norm, ['second']))
    names, transformers, columns = zip(*ct.transformers)
    assert_equal(names, ("standardscaler", "normalizer"))
    assert_equal(transformers, (scaler, norm))
    assert_equal(columns, ('first', ['second']))

    # XXX remove in v0.22
    with pytest.warns(DeprecationWarning,
                      match='`make_column_transformer` now expects'):
        ct1 = make_column_transformer(([0], norm))
    ct2 = make_column_transformer((norm, [0]))
    X_array = np.array([[0, 1, 2], [2, 4, 6]]).T
    assert_almost_equal(ct1.fit_transform(X_array),
                        ct2.fit_transform(X_array))

    with pytest.warns(DeprecationWarning,
                      match='`make_column_transformer` now expects'):
        make_column_transformer(('first', 'drop'))

    with pytest.warns(DeprecationWarning,
                      match='`make_column_transformer` now expects'):
        make_column_transformer(('passthrough', 'passthrough'),
                                ('first', 'drop')) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:28,代码来源:test_column_transformer.py

示例6: test_make_column_transformer_pandas

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def test_make_column_transformer_pandas():
    pd = pytest.importorskip('pandas')
    X_array = np.array([[0, 1, 2], [2, 4, 6]]).T
    X_df = pd.DataFrame(X_array, columns=['first', 'second'])
    norm = Normalizer()
    # XXX remove in v0.22
    with pytest.warns(DeprecationWarning,
                      match='`make_column_transformer` now expects'):
        ct1 = make_column_transformer((X_df.columns, norm))
    ct2 = make_column_transformer((norm, X_df.columns))
    assert_almost_equal(ct1.fit_transform(X_df),
                        ct2.fit_transform(X_df)) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:14,代码来源:test_column_transformer.py

示例7: test_make_column_transformer_remainder_transformer

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def test_make_column_transformer_remainder_transformer():
    scaler = StandardScaler()
    norm = Normalizer()
    remainder = StandardScaler()
    ct = make_column_transformer((scaler, 'first'), (norm, ['second']),
                                 remainder=remainder)
    assert ct.remainder == remainder 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:9,代码来源:test_column_transformer.py

示例8: create_preprocessing_pipeline

# 需要导入模块: from sklearn import compose [as 别名]
# 或者: from sklearn.compose import make_column_transformer [as 别名]
def create_preprocessing_pipeline(num_columns):
    preprocessor = make_column_transformer(
        (np.arange(num_columns), StandardScaler()),
        remainder='passthrough'
    )
    return preprocessor 
开发者ID:aws,项目名称:aws-step-functions-data-science-sdk-python,代码行数:8,代码来源:sklearn_mnist_preprocessor.py


注:本文中的sklearn.compose.make_column_transformer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。