【问题标题】:python error setting an array element with a sequencepython错误使用序列设置数组元素
【发布时间】:2016-10-30 11:30:03
【问题描述】:

我试图在 scikit-learn 中为这个例子探索不同的分类器 网站http://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html。但是,下面的代码产生了错误: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)

【问题讨论】:

    标签: python numpy scikit-learn tensorflow skflow


    【解决方案1】:

    TensorFlowLinearClassifier不处理CSR矩阵作为输入,你可以关注that issue的进度。


    您现在可以做的是将 X_train_tfidf 转换为 numpy 矩阵,然后再将其提供给 clf.fit()

    clf.fit(X_train_tfidf.toarray(), label)
    

    【讨论】:

      猜你喜欢
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 2018-09-01
      • 2015-08-10
      相关资源
      最近更新 更多