【bug】‘CustomPCA‘ object has no attribute ‘n_features_in_‘

问题

在使用pyEOF包(load sample data — pyEOF 0.0.0 documentation)做旋转因子正交分解时出错(运行官方的示例代码时就出错了)

'CustomPCA' object has no attribute 'n_features_in_'

解决

额,好像是因为新的sklearn库将n_features_废弃了,用的是n_features_in_,给CustomPCA类加个n_features_in_属性就好了
我是这样改的,改了可以运行了:


/* pyEOF.py文件 71-75行替换为*/


if pca_type=="varimax":
    skpca = CustomPCA(n_components=n_components, 
                        rotation='varimax',n_features_in_ = data_dropna.shape[1]) #zb data_dropna (time,current features)
    skpca.fit(data_dropna)
    self._EOFs = np.full([n_components, self._space], np.nan)

/* custom_pca.py文件 60-83行替换为*/

def __init__(self, rotation=None, feature_selection='all', n_features_in_=10086, **kws): #zb 240505
    '''
    rotation: string, name of the rotation method.
                'varimax': varimax rotation
                None: no rotation by by default

    feature_selection: string, Features selection method
                        'all': All features are selected, means principal
                                components are output of tranformation
                        'significant': Only features with significant weights
                                        and communalities are selected
                        'surrogate': Only features with highest loading
                                    with principal components are used
                        'summated scales': Summated scales consturcted as
                                            sum of features having significant
                                            loadings on principal components,
                                            not implemented yet.
    '''

    super().__init__(**kws)
    self.rotation = rotation
    self.feature_selection = feature_selection
    # self.n_features_in_ = 10086 #zb 240505 这个初始数字是不是没用 算了做成参数吧
    self.n_features_in_ = n_features_in_

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值