Sklearn Pipeline Fit: Attributeerror: Lower Not Found
I would like to use a pipeline in sklearn, like this: corpus = load_files('corpus/train') stop_words = [x for x in open('stopwords.txt', 'r').read().split('\n')] # Uppercase! co
Solution 1:
You are not using correctly the pipeline. You don't need to pass the data vectorized, the idea is that the pipeline vectorizes the data.
# This is done by the pipeline
# x_train_counts = countvec.fit_transform(X_train)
# x_test_counts = countvec.transform(X_test)
k_fold = KFold(n=len(corpus.data), n_folds=6)
confusion = np.array([[0, 0], [0, 0]])
pipeline = Pipeline([
('vectorizer', CountVectorizer(stop_words=stop_words, ngram_range=(1, 2))),
('classifier', MultinomialNB()) ])
# also you are not using the indices...
for train_indices, test_indices in k_fold:
pipeline.fit(corpus.data[train_indices], corpus.target[train_indices])
predictions = pipeline.predict(corpus.data[test_indices])
Post a Comment for "Sklearn Pipeline Fit: Attributeerror: Lower Not Found"