Search code examples
python-3.xscikit-learndeep-learninglstmsklearn-pandas

AttributeError: module 'sklearn.metrics' has no attribute 'items'


Here is my code..

    import imp
    from sklearn.metrics import classification_report
    from sklearn import metrics
    from sklearn.metrics import accuracy_score

    for title, metric in metrics.items():
        print(title, metric(labels_categorical_dev.argmax(axis=1), y_pred.argmax(axis=1)))
    print(classification_report(labels_categorical_dev.argmax(axis=1), y_pred.argmax(axis=1)))
    y_pred = model.predict([message_first_message_test, message_second_message_test, message_third_message_test])

Iam getting below error..

Traceback (most recent call last):

File "getopt.py", line 6, in

for title, metric in metrics.items():

AttributeError: module 'sklearn.metrics' has no attribute 'items'

I have tried with versions from scikit-learn=0.20.0 to scikit-learn=0.24.2

But still getting this error. Please give me a solution for this.


Solution

  • Can you share more details about what is the purpose of your code? As you can see here, there isn't any attribute of sklearn.metrics named items().

    .items() is used for dictionaries in order to get the values pertaining to different keys in that dictionary.

    Also, you have defined y_pred after it has been referenced, so that will cause an error as well.