Skip to content

Instantly share code, notes, and snippets.

@tdomhan
tdomhan / coef_weight_plot.py
Created September 8, 2013 18:16
plotting the largest weights of a L2 regularized classifier + their names
import matplotlib.pyplot as plt
import numpy as np
figsize(20,8)
#clf is a sklearn classifier e.g. clf = LogisticRegression()
#vecotorizer is a sklearn vectorizer, e.g. vectorizer = TfidfVectorizer()
#let's get the coefficients:
coef = clf.coef_.ravel()
important = np.argsort(np.abs(coef))[-100:]