nbsvm.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:document_classification 作者: scotthlee 项目源码 文件源码
def fit(self, x, y):
        # Convert non-binary features to binary
        bin_x = tfidf_to_counts(x)

        # Calculating the log-count ratio
        X_pos = bin_x[np.where(y == 1)]
        X_neg = bin_x[np.where(y == 0)]
        self.r = log_count_ratio(X_pos, X_neg)
        X = np.multiply(self.r, bin_x)

        # Training linear SVM with NB features but no interpolation
        svm = LinearSVC(C=self.C)
        svm.fit(X, y)
        self.coef_ = svm.coef_
        self.int_coef_ = interpolate(self.coef_, self.beta)
        self.bias = svm.intercept_

    # Scores the interpolated model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号