本文整理匯總了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
示例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')
示例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