1

I trying to explore different classifier for this example in scikit-learn website http://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html. However, the code below produced an error: ValueError: setting an array element with a sequence.

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)
4

1 回答 1

2

TensorFlowLinearClassifier不处理 CSR 矩阵作为输入,您可以关注该问题进展。


您现在可以做的是在将X_train_tfidf其输入之前转换为 numpy 矩阵clf.fit()

clf.fit(X_train_tfidf.toarray(), label)
于 2016-06-28T08:47:35.570 回答