3
$\begingroup$

While performing a simple fitting operation on the Titanic dataset. The following is my code:

data = pd.read_csv(r'.\Desktop\DS\Titanic\train.csv')
sex_train = data['Sex'].map({'male':0,'female':1})
survived_train = data['Survived']
sex_survivor_tree = GaussianNB()
sex_survivor_tree.fit(sex_train,survived_train)
$\endgroup$
4
$\begingroup$

This is a bit tricky. Using pandas data, sklearn only accepts input variables (features) with type pandas.Dataframe. In your code variable sex_train in pandas.Series type. Try the following code :

sex_train = data['Sex'].map({'male':0,'female':1}).to_frame()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.