Classification Benchmark: Mode Based on Passenger Class (Titanic Dataset)

I am obtaining an accuracy of 1.0 (not correct) using the code below. Could someone correct the code please?

Code:

Pclass_mode = pd.crosstab(train[‘Survived’],train[‘Pclass’])
Pclass_mode

test[‘Pclass_mode’] = test[‘Survived’]

for every unique value in column

for i in test[‘Pclass’].unique():

Calculate and Assign mode to new column, corresponding to unique values in “Pclass”

test[‘Pclass_mode’][test[‘Pclass’] == str(i)] = train[‘Survived’][train[‘Pclass’] == str(i)].mode()

Pclass_accuracy = accuracy_score(test[‘Survived’], test[‘Pclass_mode’])
Pclass_accuracy

1 Like

First edit question, select code and format it using button </> or Ctrl+Shift+C

© Copyright 2013-2019 Analytics Vidhya