test_pca.py 文件源码

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

项目:prince 作者: MaxHalford 项目源码 文件源码
def setup_class(cls):
        # Load a dataframe
        dataframe = pd.read_csv('tests/data/decathlon.csv', index_col=0)

        # Determine the categorical columns
        cls.df_categorical = dataframe.select_dtypes(exclude=[np.number])

        # Determine the numerical columns
        cls.df_numeric = dataframe.drop(cls.df_categorical.columns, axis='columns')

        # Determine the size of the numerical part of the dataframe
        (cls.n, cls.p) = cls.df_numeric.shape

        # Determine the covariance matrix
        X = cls.df_numeric.copy()
        cls.center_reduced = ((X - X.mean()) / X.std()).values
        cls.cov = cls.center_reduced.T @ cls.center_reduced

        # Calculate a full PCA
        cls.n_components = len(cls.df_numeric.columns)
        cls.pca = PCA(dataframe, n_components=cls.n_components, scaled=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号