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?


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

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’])

1 Like

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

© Copyright 2013-2019 Analytics Vidhya