перебрать категориальный индекс pandas склеарн - PullRequest
0 голосов
/ 29 января 2020
cm = np.array(confusion_matrix(y_test, pred, labels=[0,1]))

b=str(df["topic"].factorize()[1][0])
print(b)
print(df["topic"].factorize()[1].categories.to_numpy)

np=df["topic"].factorize()[1].categories.to_numpy



from IPython.display import display
#print( df["topic"].factorize().CategoricalIndex)
#df["topic"].factorize()
for predicted in df["topic"].factorize()[1].categories:
   for actual in df["topic"].factorize()[1].categories:
      if predicted != actual and int(conf_mat[actual, predicted]) >= 10:

       display(df.loc[indices_test[(y_test == actual) & (pred == predicted)]][['topic', 'body_wakati']])
       print('')

Я хочу проверить, какой из них неправильный в классификации, используя матрицу путаницы. Я хочу перебрать категориальный индекс pandas, но я не уверен, массив это или нет?

enter image description here

это категорический индекс, когда я печатаю print(df["topic"].factorize()[1])

CategoricalIndex(['computer_graphics', 'operating_systems',
                  'computer_security', 'application_service',
                  'computer_software', 'artificial_intelligence',
                  'search_engine', 'information_society'],
                 categories=['application_service', 'artificial_intelligence', 'computer_graphics', 'computer_security', 'computer_software', 'information_society', 'operating_systems', 'search_engine'], ordered=False, dtype='category')
---------------------------------------------------------------------------

и получаю ошибку при попытке выполнить итерацию

--> 385       if predicted != actual and int(conf_mat[actual, predicted]) >= 10:
    386 
    387        display(df.loc[indices_test[(y_test == actual) & (pred == predicted)]][['topic', 'body_wakati']])

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...