-3

My code:

import numpy as np 
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

BMI = pd.read_csv('c://500_Person_Gender_Height_Weight_Index.csv')

from sklearn.model_selection import train_test_split 

X_train, X_test, y_train, y_test = train_test_split(BMI, BMI.gender_lbl, test_size=0.3,random_state=42) 


from sklearn.naive_bayes import GaussianNB

gnb = GaussianNB()

gnb.fit(X_train, y_train) --> shows error

y_pred = gnb.predict(X_test)
y_pred

I am not sure of what to do here. If anyone could help would be very much appreciated. Thank you.

urvashi koladiya
  • 168
  • 1
  • 11
raja
  • 1
  • 1

1 Answers1

0

Like the comments said, you are trying to convert a string or object (in this case "Male") into a float.

Try to output your variables and their types to makes you see where you are trying to convert the float.

Like described in the error and in the documentation :

Raised when an operation or function receives an argument that has the right type but an inappropriate value [...] link

For further debugging tricks, you can consult this thread : How to step through Python code to help debug issues?

Otherwise, some debugger (like PyCharm) can help you by inserting breakpoints and getting values of active variables

Syb
  • 39
  • 3
  • Could you show me the coding to help with that because I am not sure how to convert to float – raja Mar 31 '20 at 08:01