def fit(self, X, y=None, **fit_params):
# scikit-learn checks
X, y = check_X_y(X, y)
n_terms = min(self.n_terms, X.shape[1])
# Get a list of unique labels from y
labels = np.unique(y)
# Determine the n top terms per class
self.top_terms_per_class_ = {
c: set(np.argpartition(np.sum(X[y == c], axis=0), -n_terms)[-n_terms:])
for c in labels
}
# Return the classifier
return self
评论列表
文章目录