def fit(self, x, y, verbose=True):
#setting data attributes for the model instance
X = tfidf_to_counts(x)
#splitting by target class so we can calculate the log-count ratio
X_pos = X[np.where(y == 1)]
X_neg = X[np.where(y == 0)]
self.r = log_count_ratio(X_pos, X_neg)
#setting the npos and nneg variables
n_pos = X_pos.shape[0]
n_neg = X_neg.shape[0]
#getting the bais for the MNB model
self.nb_bias = np.log(np.true_divide(n_pos, n_neg))
#trains, tests, and assesses the performance of the model
评论列表
文章目录