linear_laplacian_rls.py 文件源码

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

项目:TextCategorization 作者: Y-oHr-N 项目源码 文件源码
def fit(self, X, y, L):
        """Fit the model according to the given training data.

        Prameters
        ---------
        X : array-like, shpae = [n_samples, n_features]
            Training data.

        y : array-like, shpae = [n_samples]
            Target values (unlabeled points are marked as 0).

        L : array-like, shpae = [n_samples, n_samples]
            Graph Laplacian.
        """

        labeled               = y != 0
        X_labeled             = X[labeled]
        y_labeled             = y[labeled]
        n_samples, n_features = X.shape
        n_labeled_samples     = y_labeled.size
        I                     = sp.eye(n_features)
        M                     = X_labeled.T @ X_labeled \
            + self.gamma_a * n_labeled_samples * I \
            + self.gamma_i * n_labeled_samples / n_samples**2 * X.T @ L**self.p @ X

        # Train a classifer
        self.coef_            = LA.solve(M, X_labeled.T @ y_labeled)

        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号