K
K
kolomiec_artiom2018-12-12 22:30:58
Python
kolomiec_artiom, 2018-12-12 22:30:58

How to parse strings in naive bayes classifier?

Good evening friends! Created a program that makes classification using a naive bayes classifier. I am implementing a program in python3.6
First, I connect the module: Then the classifier itself
from sklearn.naive_bayes import GaussianNB

model = GaussianNB()
model.fit(x_training, y_training)

As a result, this error:
FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).
FutureWarning)

Tried to fix it like this:
x_training = np.array(x_training, dtype=np.complex)

But this resulted in a new error:
builtins.TypeError: must be real number, not str (on the same line)

Any ideas for a solution? I would be very grateful

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2018-12-13
@Sabin

I have never used this module and most likely I am writing nonsense, but according to the description from here , you must specify the parameters in the form model.fit((array: number of samples, sample?),(x_training or array x_training, y_training)):

fit(X, y, sample_weight=None)[source]
Fit Gaussian Naive Bayes according to X, y
Parameters:
X : array-like, shape (n_samples, n_features)
Training vectors, where n_samples is the number of samples and n_features is the number of features.
y : array-like, shape (n_samples,)
Target values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question