I am facing this error with the Naive Bayes's CategoricalNB algorithm
It gives the above error after the 2nd attempt I run the cells. That means it works without any errors during the 1st time and when I try to change something (as small as a comment) and run the notebook again, it gives the error:
IndexError: index 38 is out of bounds for axis 1 with size 38
I don't know what is going wrong and how to fix. When I restart the kernel and try again it works and every attempt after the 1st attempt it fails and gives the above error.
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
dataframe = pd.read_csv("hr_dataset.csv")
# dataframe = pd.read_csv("WA_Fn-UseC_-HR-Employee-Attrition.csv")
dataframe.head(2)
from sklearn.naive_bayes import CategoricalNB
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
# inputs = scaled_df
X_train, X_test, y_train, y_test = train_test_split(inputs, target, test_size=0.2)
categoricalNB_ = CategoricalNB()
categoricalNB_.fit(X_train, y_train)
X_train.shape, X_test.shape, y_train.shape, y_test.shape
pred = categoricalNB_.predict(X_test) # --------------> gives the error for every attempt after the 1st attempt. weird
categoricalNB_.score(X_test, y_test)
# accuracy_score(y_test,pred)