factor_analysis.py 文件源码

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

项目:ottertune 作者: cmu-db 项目源码 文件源码
def fit(self, X, feature_labels=None, estimator_params=None):
        """Fits an Sklearn FA model to X.

        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Training data.

        feature_labels : array-like, shape (n_features), optional
                         Labels for each of the features in X.

        estimator_params : dict, optional
                           The parameters to pass to Sklearn's FA estimators.


        Returns
        -------
        self
        """
        self._reset()
        if feature_labels is None:
            feature_labels = ["feature_{}".format(i) for i in range(X.shape[1])]
        self.feature_labels_ = feature_labels
        self.model_ = SklearnFactorAnalysis()
        if estimator_params is not None:
            # Update Sklearn estimator params
            assert isinstance(estimator_params, dict)
            self.model_.set_params(**estimator_params)
        self.model_.fit(X)

        # Remove zero-valued components (n_components x n_features)
        components_mask = np.sum(self.model_.components_ != 0.0, axis=1) > 0.0
        self.components_ = self.model_.components_[components_mask]

        # Compute the % variance explained (with/without noise)
        c2 = np.sum(self.components_ ** 2, axis=1)
        self.total_variance_ = np.sum(c2)
        self.pvars_ = 100 * c2 / self.total_variance_
        self.pvars_noise_ = 100 * c2 / (self.total_variance_ +
                                        np.sum(self.model_.noise_variance_))
        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号