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


Python FunctionTransformer.fit_transform方法代码示例

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


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

示例1: test_function_transformer_future_warning

# 需要导入模块: from sklearn.preprocessing import FunctionTransformer [as 别名]
# 或者: from sklearn.preprocessing.FunctionTransformer import fit_transform [as 别名]
def test_function_transformer_future_warning(validate, expected_warning):
    # FIXME: to be removed in 0.22
    X = np.random.randn(100, 10)
    transformer = FunctionTransformer(validate=validate)
    with pytest.warns(expected_warning) as results:
        transformer.fit_transform(X)
    if expected_warning is None:
        assert len(results) == 0
开发者ID:SuryodayBasak,项目名称:scikit-learn,代码行数:10,代码来源:test_function_transformer.py

示例2: test_function_transformer_frame

# 需要导入模块: from sklearn.preprocessing import FunctionTransformer [as 别名]
# 或者: from sklearn.preprocessing.FunctionTransformer import fit_transform [as 别名]
def test_function_transformer_frame():
    pd = pytest.importorskip('pandas')
    X_df = pd.DataFrame(np.random.randn(100, 10))
    transformer = FunctionTransformer(validate=False)
    X_df_trans = transformer.fit_transform(X_df)
    assert hasattr(X_df_trans, 'loc')
开发者ID:SuryodayBasak,项目名称:scikit-learn,代码行数:8,代码来源:test_function_transformer.py

示例3: FunctionTransformer

# 需要导入模块: from sklearn.preprocessing import FunctionTransformer [as 别名]
# 或者: from sklearn.preprocessing.FunctionTransformer import fit_transform [as 别名]
You are working with numeric data that needs imputation, and text data that needs to be converted into a bag-of-words. You'll create functions that separate the text from the numeric variables and see how the .fit() and .transform() methods work.

INSTRUCTIONS
100XP
Compute the selector get_text_data by using a lambda function and FunctionTransformer() to obtain all 'text' columns.
Compute the selector get_numeric_data by using a lambda function and FunctionTransformer() to obtain all the numeric columns (including missing data). These are 'numeric' and 'with_missing'.
Fit and transform get_text_data using the .fit_transform() method with sample_df as the argument.
Fit and transform get_numeric_data using the same approach as above.
'''
# Import FunctionTransformer
from sklearn.preprocessing import FunctionTransformer

# Obtain the text data: get_text_data
get_text_data = FunctionTransformer(lambda x: x['text'], validate=False)

# Obtain the numeric data: get_numeric_data
get_numeric_data = FunctionTransformer(lambda x: x[['numeric', 'with_missing']], validate=False)

# Fit and transform the text data: just_text_data
just_text_data = get_text_data.fit_transform(sample_df)

# Fit and transform the numeric data: just_numeric_data
just_numeric_data = get_numeric_data.fit_transform(sample_df)

# Print head to check results
print('Text Data')
print(just_text_data.head())
print('\nNumeric Data')
print(just_numeric_data.head())
开发者ID:shonkhochil,项目名称:Coursera-Repo,代码行数:31,代码来源:04-multiple-types-of-proessing-function-transformer.py


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