使用sklearn和pandas在一个模型中组合听写向量器

2024-06-24 13:31:40 发布

您现在位置:Python中文网/ 问答频道 /正文

from sklearn.pipeline import FeatureUnion
vectorizer = DictVectorizer()
feature_vectorstest = vectorizer.fit_transform(train['tokens'].apply(featurize))
feature_vectorstest2 = vectorizer.fit_transform(train['tokens'].apply(featurize2my))

combined_features = FeatureUnion([('Dicvectorizer',feature_vectorstest),('DicVect',feature_vectorstest2)])
combined_features.transform(train['tokens'])

TypeError:输入类型不支持ufunc“isnan”,并且无法根据强制转换规则“安全”//行内组合功能将输入安全强制为任何支持的类型

如果“feature_vectorstest”和“feature_vectorstest2”都包含单词“sad”,那么特征将是“feature_vectorstest_name_sad”和“feature_Vectorste2_name_sad”


Tags: name类型transformtrainfeaturefitfeaturesapply