【发布时间】:2018-10-14 08:09:27
【问题描述】:
这是我的输入矩阵enter image description here
我的示例代码:
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.naive_bayes import MultinomialNB
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
X_train, X_test, y_train, y_test = train_test_split(data['Extract'],
data['Expense Account code Description'], random_state = 0)
from sklearn.pipeline import Pipeline , FeatureUnion
text_clf = Pipeline([('vect', CountVectorizer(ngram_range=(1,1))),
('tfidf', TfidfTransformer(use_idf = False)),
('clf', RandomForestClassifier(n_estimators =100,
max_features='log2',criterion = 'entropy')),
])
text_clf = text_clf.fit(X_train, y_train)
在这里,我正在应用“提取”列的词袋模型对“费用帐户代码描述”进行分类,在这里我得到了大约 92% 的准确度,但如果我想将“供应商名称”作为另一个集合包含输入功能我该怎么做。有没有什么办法可以和词袋一起做? ,
【问题讨论】:
-
您可以使用FeatureUnion来组合这些功能。但首先您必须将供应商名称转换为数字,(将分类编码为数字形式)。
-
对于转换供应商名称,我可以使用相同的词袋模型吗?然后我使用 featureUnion 来组合这些功能。我是新手,我可能听起来很傻。
-
供应商名称与一般文本不同。因此,我认为 Bag of words 的行为与简单的 one-hot 编码没有任何不同。尝试对它们进行 one-hot 编码。
标签: python machine-learning scikit-learn nlp text-classification