我在使用Naive Bayes的CategoricalNB算法时遇到了这个错误。
在第二次运行代码后出现了上述错误。这意味着第一次运行代码没有出现任何错误,但是当我尝试更改一些东西(即使只是一个注释)并重启Notebook再次运行时,就会出现这个错误:
IndexError: index 38 is out of bounds for axis 1 with size 38
我不知道哪里出错了以及如何解决。当我重新启动内核并尝试再次运行时,它可以正常工作,但在第一次尝试之后的每一次尝试中都会失败并给出上述错误。
%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)
n
个元素,则有效(正)索引从0到n-1(包括n-1)。 - norok2X_train
和X_test
的行数相等,X_test
和y_test
也是如此。 - Escort Personal Adzhttps://drive.google.com/open?id=19gWVwuXS3my9C77D9unG53tuivPzZdqJ
- Escort Personal Adz