问题
在使用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_