我发现很难理解如何修复我创建的Pipeline(阅读:主要是从教程中粘贴).这是python 3.4.2:
df = pd.DataFrame
df = DataFrame.from_records(train)
test = [blah1, blah2, blah3]
pipeline = Pipeline([('vectorizer', CountVectorizer()), ('classifier', RandomForestClassifier())])
pipeline.fit(numpy.asarray(df[0]), numpy.asarray(df[1]))
predicted = pipeline.predict(test)
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到:
TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.
Run Code Online (Sandbox Code Playgroud)
这是为了线pipeline.fit(numpy.asarray(df[0]), numpy.asarray(df[1])).
我已经通过numpy,scipy等方式尝试了很多解决方案,但我仍然不知道如何修复它.是的,之前出现过类似的问题,但不是在管道内.我必须在哪里申请toarray或todense?