code/chapter_15.py
def print_top10(vectorizer, clf, class_labels):
    """Prints features with the highest coefficient values, per class"""
    feature_names = vectorizer.get_feature_names()
    for i, class_label in enumerate(class_labels):
        top10 = np.argsort(clf.coef_[i])[-10:]
        print("%s: %s" % (class_label,
              " ".join(feature_names[j] for j in top10)))
Prints features with the highest coefficient values, per class
Prints features with the highest coefficient values, per class
Prints features with the highest coefficient values per class
def print_top10(vectorizer, clf, class_labels):
    feature_names = vectorizer.get_feature_names()
    for i, class_label in enumerate(class_labels):
        top10 = np.argsort(clf.coef_[i])[-10:]
        print("%s: %s" % (class_label,
              " ".join(feature_names[j] for j in top10)))
def print_top10 ( vectorizer , clf , class_labels ) : feature_names = vectorizer . get_feature_names ( ) for i , class_label in enumerate ( class_labels ) : top10 = np . argsort ( clf . coef_ [ i ] ) [ - 10 : ] print ( "%s: %s" % ( class_label , " " . join ( feature_names [ j ] for j in top10 ) ) )
Prints features with the highest coefficient values, per class
Prints features with the highest coefficient values per class
"""Prints features with the highest coefficient values, per class"""
vectorizer
clf
class_labels