How to resolve IndexError while doing Monte Carlo for 1000 runs?
Below code runs without any problem, however when I run the same code using Monte Carlo Analysis for 1000 runs, it gives IndexError. Can someone explain why this happens. Thanks
X = df1.drop(Gender, axis = 1)
y = df1.Gender
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2)
nb = CategoricalNB()
nb.fit(X_train,y_train)
nb_pred = nb.predict(X_test)
nb_accuracy = accuracy_score(y_test,nb_pred)
nb_accuracy
output: 0.6279486413854882
X = df1.drop(Gender, axis = 1)
y = df1.Gender
for i in range(1000):
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2, random_state = i)
#CategoricalNB Naive Bayes Model
nb = CategoricalNB()
nb.fit(X_train,y_train)
nb_pred = nb.predict(X_test)
nb_accuracy = accuracy_score(y_test,nb_pred)
print(CategoricalNB Naive Bayes Accuracy:{}.format(nb_accuracy))
IndexError: index 74 is out of bounds for axis 1 with size 74
Topic monte-carlo jupyter pandas python machine-learning
Category Data Science