Intel® DevCloud
Help for those needing help starting or connecting to the Intel® DevCloud
1626 Discussions

Part 3 Model Analysis: Type Error

Wendo__Brian
Beginner
698 Views

Hi guys, I am on Part 3: Model Analysis and I am getting this error when I run the code. I updated the first variable to true_classes and the second variables to predicted_classes, and then clicked Run. How do I solve this?

import matplotlib.pyplot as plt
%matplotlib inline  
import scikitplot as skplt

[print(k, ":", v) for k,v in enumerate(class_labels)]
true_classes = [class_labels for x in true_classes]
predicted_classes = [class_labels for x in predicted_classes]

skplt.metrics.plot_confusion_matrix(
    true_map_classes,
    predicted_map_classes,
    labels=class_labels,
    x_tick_rotation=90,
    figsize=(12,12))

I get this error:

TypeError Traceback (most recent call last) <ipython-input-7-7667dcf96029> in <module>

4

5 [print(k, ":", v) for k,v in enumerate(class_labels)]

----> 6 true_classes = [class_labels for x in true_classes]

7 predicted_classes = [class_labels for x in predicted_classes]

8

TypeError: list indices must be integers or slices, not str

0 Kudos
3 Replies
AthiraM_Intel
Moderator
698 Views

Hi,

Thanks for reaching out to us.

Could you please try the below code snippet. 

 

import matplotlib.pyplot as plt
%matplotlib inline  
import scikitplot as skplt

[print(k, ":", v) for k,v in enumerate(class_labels)]
true_classes = [class_labels for x in true_classes]
predicted_classes = [class_labels for x in predicted_classes]

skplt.metrics.plot_confusion_matrix(
    true_classes, 
    predicted_classes,
    labels=class_labels,
    x_tick_rotation=90,
    figsize=(12,12))

If you are again getting the same error, before running this code please run the jupyter cell which is just above this code snippet in part 3 of the course.

If you face any further issue please let us know.

0 Kudos
Wendo__Brian
Beginner
698 Views

Thanks, it finally worked. I just copy pasted the code above.

0 Kudos
AthiraM_Intel
Moderator
698 Views

Thanks for your confirmation. We are closing this thread. Feel free to open a new thread if you have any further issues.

0 Kudos
Reply