【发布时间】:2014-03-15 07:20:00
【问题描述】:
我有一个脚本在大约一年前成功运行,但现在不再运行。我使用 pandas 将数据处理成这样:
df_train
dtu_docid dtu_topic_split y_train
0 2012-1553 [Energy Taxation, State & Local Taxation] [3, 23]
2 2010-0227 [Quantitative Economics and Statistics] [34]
3 2010-0215 [International Taxation, Asia] [0, 19]
然后使用scikit如下:
classifier = Pipeline([
('vectorizer', CountVectorizer(stop_words='english',
ngram_range=(1,3),
max_df = 1.0,
min_df = 0.0,
analyzer='word')),
('tfidf', TfidfTransformer()),
('clf', OneVsRestClassifier(LinearSVC(verbose=1)))])
classifier.fit(df_train.dtu_content, df_train.y_train)
现在得到一个让我抓狂的错误:
ValueError: Expected array-like (array or non-string sequence), got 0 [3, 23]
2 [34]
3 [0, 19]
4 []
5 [3]
8 [8, 27]
9 [10]
11 [15]
12 [0, 7]
13 [1, 4]
14 [1, 4, 13] ... (truncated)
15 [11] ... (truncated)
看起来大约 9 个月前对 multiclass.py 模块进行了增强,导致额外检查,但我不知道如何修复。有人以前见过这个或有想法吗?
【问题讨论】:
-
我今天早上又在研究这个问题,并在 github 中发现了一些关于可能修复的神秘注释。似乎熊猫或 scikit 的最新版本破坏了一些非常重要的东西。恕我直言,这是使用 pandas 和 scikit 的一个关键方面——它们曾经以无缝、简单和自然的方式协同工作。是否有已知的解决方法或估计何时会纠正不兼容性?
-
df_train是如何构造的?请发帖SSCCE。 -
DF train 是用 pandas 中的大量数据处理创建的,有问题的属性是 y_train。 Ytrain 是与训练示例关联的类的列表。使用该列表是因为这是一种多类情况,其中每个样本可以低于一个类。
-
'''code# 将 y_train 构建并填充为整数 def get_ytrain(x): catlist = [] for icat in range(len(label)): if label[icat] in x: catlist. append(icat) return catlist df_train.y_train = df_train.dtu_topic_split.apply(get_ytrain) df_holdout.y_train = df_holdout.dtu_topic_split.apply(get_ytrain) print df_train[['dtu_docid','dtu_topic_split','y_train','predicted'] ][:20] 打印 df_holdout[['dtu_docid','dtu_topic_split','y_train','predicted']][:20] 打印 df_train.dtypes
标签: python pandas scikit-learn