TypeError: '<' not supported between instances of 'int' and 'str'

I have the following code

rf = RandomForestClassifier()
rf.fit(X_train, Y_train)
print(Features sorted by their score:)
print(sorted(zip(map(lambda x: round(x, 2), rf.feature_importances_), X_train), reverse=True))

and I get the following error:

 TypeError Traceback (most recent call last)

 ipython-input-109-c48c3ffd74e2 in module()
 
 2 rf.fit(X_train, Y_train)
 
 3 print (Features sorted by their score:)
 
 ---- 4 print (sorted(zip(map(lambda x: round(x, 2),
 rf.feature_importances_), X_train), reverse=True))
 
 TypeError: '' not supported between instances of 'int' and 'str'

I am not sure what I am doing wrong. I only have int and float in my dataframe.

Topic error-handling scikit-learn python machine-learning

Category Data Science


Based on our discussion, omit reverse = True and use list instead of sorted and print it. I guess you will see what you want.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.