Я получаю «KeyError: 1» из простой копии - Python Machine Learning - PullRequest
1 голос
/ 31 мая 2019

Я понятия не имею, почему я получаю эту ошибку, и я работаю с Mnist, кстати, и один и тот же набор данных и функции работали для разных моделей (т.е. LDA), и это та же реализация с SVM, что и для модели.

natural_targets_dict_woae = {}
non_natural_targets_dict_woae = {}
one_number_targets_dict_woae = {}
for ix, series in attacktargets_woae.iterrows():
    natural_targets_dict_woae[ix] = series.argmax()
    non_natural_targets_dict_woae[ix] = series.drop(ix).argmin()
    one_number_targets_dict_woae[ix] = y_test_woae[0]

natural_foolingtargets_woae = np.zeros((y_test_woae.shape[0]))
non_natural_foolingtargets_woae = np.zeros((y_test_woae.shape[0]))
one_number_foolingtargets_woae = np.zeros((y_test_woae.shape[0]))
for n in range(len(natural_foolingtargets_woae)):
    target_woae = y_test_woae[n]
    natural_foolingtargets_woae[n] = natural_targets_dict_woae[target_woae]
    non_natural_foolingtargets_woae[n] = non_natural_targets_dict_woae[target_woae]
    one_number_foolingtargets_woae[n] = one_number_targets_dict_woae[target_woae]

attack_woae.create_one_hot_targets(natural_foolingtargets_woae.astype(np.int))
attack_woae.attack_to_max_epsilon(targeted_gradient, epsilon_number)
natural_scores_woae = attack_woae.scores

attack_woae.create_one_hot_targets(non_natural_foolingtargets_woae.astype(np.int))
attack_woae.attack_to_max_epsilon(targeted_gradient, epsilon_number)
non_natural_scores_woae = attack_woae.scores

attack_woae.create_one_hot_targets(one_number_foolingtargets_woae.astype(np.int))
attack_woae.attack_to_max_epsilon(targeted_gradient, epsilon_number)
one_target_scores_woae = attack_woae.scores

Ошибка:

KeyError Traceback (most recent call last) <ipython-input-83-e52f71235839> in <module>
     12 for n in range(len(natural_foolingtargets_woae)):
     13     target_woae = y_test_woae[n]
---> 14     natural_foolingtargets_woae[n] = natural_targets_dict_woae[target_woae]
     15     non_natural_foolingtargets_woae[n] = non_natural_targets_dict_woae[target_woae]
     16     one_number_foolingtargets_woae[n] = one_number_targets_dict_woae[target_woae]

KeyError: 1
...