I am attempting to use Python MultinomialNB from sklearn to classify some data but it returns a Value Error

user3062448

I am attempting to use MultinomialNB from sklearn to classify some data. I have made a sample csv with some labelled training data, which I want to use to train the model but I receive the following error message:

ValueError: Expected 2D array, got 1D array instead: array=[0 1 2 2].

I know it is a very small data set but I will eventually add more data once the code is working.

Here is my data: enter image description here

Here is my code:

import numpy as np
import pandas as pd
import array as array
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
data_file = pd.read_csv("CSV_Labels.csv", engine='python')
data_file.tail()
vectorizer = CountVectorizer(stop_words='english')
all_features = vectorizer.fit_transform(data_file.Word)
all_features.shape
x_train = data_file.label
y_train = data_file.Word
x_train.values.reshape(1, -1)
y_train.values.reshape(1, -1)
classifer = MultinomialNB()
classifer.fit(x_train, y_train)
Tinu

Try this:

x_train = x_train.values.reshape(-1, 1)
y_train = y_train.values.reshape(-1, 1)

numpy reshape operations are not inplace. So the array's you're passing to the classifier have actual the old shapes.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

I am trying to extract a values from column in postgressql with python. But i always get this error :

분류에서Dev

Why am I getting an additional "*" on some lines of my python app?

분류에서Dev

Can I get data from my MSSql server and upload it to app engine via some python scripts?

분류에서Dev

Get synonyms from synset returns error - Python

분류에서Dev

Why am I getting garbage value from a function call?

분류에서Dev

I am trying to perform the Euler method in python but I am getting a 'type error', why?

분류에서Dev

I am trying to use a class to hold a string value but it is not returning the value I inputted

분류에서Dev

I am trying to get a data from a list of objects

분류에서Dev

I am Trying to run a titanium project in ios simulator but getting some node error

분류에서Dev

I want to use memset to remove some characters from string

분류에서Dev

Method not allowed error when attempting to get session data with Flask

분류에서Dev

I have to return a value from a function that is called multiple times and I am unable to do that

분류에서Dev

Why isn't my code printing anything while I am attempting to reverse the words in a string

분류에서Dev

I am getting the following error need more than 1 value to unpack

분류에서Dev

HP LaserJet Pro MFP M127fn returns Supply Memory Error attempting to print long documents

분류에서Dev

I have json data and i want to select some items only how can i do it in python?

분류에서Dev

where am i going wrong in my extraction of value from mysql database?

분류에서Dev

When I open gedit from terminal, I am unable to use terminal for anything else until I close gedit. Why?

분류에서Dev

Why am I getting the error "Incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray *'." while sorting keys?

분류에서Dev

Sklearn을 MultinomialNB의 긍정적 인쪽으로 바이어스

분류에서Dev

Although value is not null, I am getting NullReferenceException

분류에서Dev

when i am cloning in to website it shows error

분류에서Dev

Why am I getting this syntax logic error?

분류에서Dev

Why am I getting unexpected string error?

분류에서Dev

Why Am I getting this Input Error?

분류에서Dev

How do I get the data of a returned value from a spinner?

분류에서Dev

How do I use JSON from a Jekyll _data directory?

분류에서Dev

The R^2 score I get from GridSearchCV is very different from the one I get from cross_val_score, why? (sklearn, python)

분류에서Dev

I'm working with R. I am performing a k-NN analysis on the training data, but I keep getting an error on my knn function. How can I fix this

Related 관련 기사

  1. 1

    I am trying to extract a values from column in postgressql with python. But i always get this error :

  2. 2

    Why am I getting an additional "*" on some lines of my python app?

  3. 3

    Can I get data from my MSSql server and upload it to app engine via some python scripts?

  4. 4

    Get synonyms from synset returns error - Python

  5. 5

    Why am I getting garbage value from a function call?

  6. 6

    I am trying to perform the Euler method in python but I am getting a 'type error', why?

  7. 7

    I am trying to use a class to hold a string value but it is not returning the value I inputted

  8. 8

    I am trying to get a data from a list of objects

  9. 9

    I am Trying to run a titanium project in ios simulator but getting some node error

  10. 10

    I want to use memset to remove some characters from string

  11. 11

    Method not allowed error when attempting to get session data with Flask

  12. 12

    I have to return a value from a function that is called multiple times and I am unable to do that

  13. 13

    Why isn't my code printing anything while I am attempting to reverse the words in a string

  14. 14

    I am getting the following error need more than 1 value to unpack

  15. 15

    HP LaserJet Pro MFP M127fn returns Supply Memory Error attempting to print long documents

  16. 16

    I have json data and i want to select some items only how can i do it in python?

  17. 17

    where am i going wrong in my extraction of value from mysql database?

  18. 18

    When I open gedit from terminal, I am unable to use terminal for anything else until I close gedit. Why?

  19. 19

    Why am I getting the error "Incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray *'." while sorting keys?

  20. 20

    Sklearn을 MultinomialNB의 긍정적 인쪽으로 바이어스

  21. 21

    Although value is not null, I am getting NullReferenceException

  22. 22

    when i am cloning in to website it shows error

  23. 23

    Why am I getting this syntax logic error?

  24. 24

    Why am I getting unexpected string error?

  25. 25

    Why Am I getting this Input Error?

  26. 26

    How do I get the data of a returned value from a spinner?

  27. 27

    How do I use JSON from a Jekyll _data directory?

  28. 28

    The R^2 score I get from GridSearchCV is very different from the one I get from cross_val_score, why? (sklearn, python)

  29. 29

    I'm working with R. I am performing a k-NN analysis on the training data, but I keep getting an error on my knn function. How can I fix this

뜨겁다태그

보관