Reputation: 181
After replacing values of some features from integer to a string, I am getting error after fit() command:
Error - ValueError: could not convert string to float: 'M'
replace_val_sex = {0:'F', 1:'M'}
df = df.replace({"Sex": replace_val_sex})
.
.
.
GNB = GaussianNB().fit(x_train, y_train)
<ERROR>
Note: This didn't happen when I did not replace the values.
Upvotes: 1
Views: 1860
Reputation: 812
As I understand from your question, you are getting confused between Naive Bayes Algo & Gaussian Naive Bayes Algo. Lets see one by one in the context that we have issue,
Naive Bayes: Naive Bayes or Naive Bayes Classifier algo is about calculating the probabilities of events with conditional independence. So, probabilities are calculated using the number of classes in an feature. This inputs for the features is dependent on the tool you are using.
Gaussian Naive Bayes: Basic assumption for this algo is that all the features are continuous. The term "Gaussian" is synonymous with continuous. In this algo, we are trying to predict a continuous output feature with other continuous output feature. So, irrespective of software (or) the tool we use, features are constrained to be numerical (or) continuous.
As you are using GaussianNB(anticipate this is from ScikitLearn), the input feature should be Numerical
Upvotes: 1