我试图在scikit-learn中探索这个例子的不同分类器 网站http://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html。但是,下面的代码产生了一个错误:ValueError:使用序列设置数组元素。
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
import tensorflow.contrib.learn as skflow
data = ["I so handsome. I just broke the mirror!","I am a normal guy."]
label = np.array([0,1])
#CountVectoriser
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(data)
#TfidfTransformer
tfidf_transformer = TfidfTransformer()
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
#Classifier
clf = skflow.TensorFlowLinearClassifier(n_classes=2)
clf.fit(X_train_tfidf, label)
答案 0 :(得分:2)
X_train_tfidf
不会将CSR矩阵作为输入处理,您可以按照that issue中的进度进行操作。
您现在可以做的是将clf.fit()
转换为numpy矩阵,然后再将其转换为clf.fit(X_train_tfidf.toarray(), label)
:
CREATE FULLTEXT INDEX idx_name_ft ON cities (`name`);