Tedana error: AttributeError: 'PCA' object has no attribute 'n_features_'

Howdy-

I got the following error when running MEICA with tedana via afni_proc.py in the APMULTI demo (running script do_26*tcsh), an example that I have run before and things worked. Please see the error below.

tedana ver: 23.0.2
afni ver: 25.0.04
python ver: 3.11.7
OS: Ubuntu 22.04

This is the output in the terminal from running afni_proc.py:

tedana v23.0.2
foreach run ( 01 )
tedana -d pb04.sub-005.r01.e01.volreg+tlrc.HEAD pb04.sub-005.r01.e02.volreg+tlrc.HEAD pb04.sub-005.r01.e03.volreg+tlrc.HEAD -e 12.5 27.6 42.7 --mask mask_epi_anat.sub-005+tlrc.HEAD --out-dir tedana_r01 --convention orig
INFO     tedana:tedana_workflow:482 Using output directory: /data/PROJECTS/APMULTI_Demo1_rest/data_26_ap_me_bT/sub-005/ses-01/sub-005.results/tedana_r01
INFO     tedana:tedana_workflow:500 Loading input data: ['pb04.sub-005.r01.e01.volreg+tlrc.HEAD', 'pb04.sub-005.r01.e02.volreg+tlrc.HEAD', 'pb04.sub-005.r01.e03.volreg+tlrc.HEAD']
INFO     io:__init__:154 Generating figures directory: /data/PROJECTS/APMULTI_Demo1_rest/data_26_ap_me_bT/sub-005/ses-01/sub-005.results/tedana_r01/figures
INFO     tedana:tedana_workflow:564 Using user-defined mask
WARNING  utils:make_adaptive_mask:111 3 voxels in user-defined mask do not have good signal. Removing voxels from mask.
INFO     tedana:tedana_workflow:612 Computing T2* map
INFO     combine:make_optcom:191 Optimally combining data with voxel-wise T2* estimates
INFO     tedana:tedana_workflow:637 Writing optimally combined data set: /data/PROJECTS/APMULTI_Demo1_rest/data_26_ap_me_bT/sub-005/ses-01/sub-005.results/tedana_r01/ts_OC.nii.gz
INFO     pca:tedpca:202 Computing PCA of optimally combined multi-echo data with selection criteria: aic
Traceback (most recent call last):
  File "/home/ptaylor/miniconda3/envs/py3_afni_ted_py11/bin/tedana", line 8, in <module>
    sys.exit(_main())
             ^^^^^^^
  File "/home/ptaylor/miniconda3/envs/py3_afni_ted_py11/lib/python3.11/site-packages/tedana/workflows/tedana.py", line 918, in _main
    tedana_workflow(**kwargs, tedana_command=tedana_command)
  File "/home/ptaylor/miniconda3/envs/py3_afni_ted_py11/lib/python3.11/site-packages/tedana/workflows/tedana.py", line 641, in tedana_workflow
    dd, n_components = decomposition.tedpca(
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ptaylor/miniconda3/envs/py3_afni_ted_py11/lib/python3.11/site-packages/tedana/decomposition/pca.py", line 214, in tedpca
    _ = ma_pca.fit_transform(data_img, mask_img)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ptaylor/miniconda3/envs/py3_afni_ted_py11/lib/python3.11/site-packages/mapca/mapca.py", line 478, in fit_transform
    self._fit(img, mask, subsample_depth=subsample_depth)
  File "/home/ptaylor/miniconda3/envs/py3_afni_ted_py11/lib/python3.11/site-packages/mapca/mapca.py", line 404, in _fit
    self.n_features_ = ppca.n_features_
                       ^^^^^^^^^^^^^^^^
AttributeError: 'PCA' object has no attribute 'n_features_'. Did you mean: 'n_features_in_'?

thanks,
pt

Hi Paul,

This looks like a sklearn version issue. You probably have a newer version of sklearn that is not compatible with an old version of maPCA.

I would recommend you update maPCA to the latest version (v0.0.5). You may need to update tedana as well, but I can’t tell off the top of my head.

1 Like

Howdy, Eneko-

Thanks, OK, I did make a new conda environment with a new installation of tedana, and hence a more modern version of both that and dependencies. So, I don’t know what was the magic aspect of the update (whether it was Python, sklearn, maPCA, or tedana itself), but it works now!

My new version of tedana is 24.0.2, and new version of Python is 3.13.2.

The new env*yml file I made, in case anyone is interested, is:

new:
name: py3_afni_ted_py2025     # conda env create -f env*afni_ted_py2025.yml
channels:
  - conda-forge
  - defaults
dependencies:
  - "python"                  # try not specifying specific ver
  - "matplotlib>=2.2.3"       # minimal ver for 'pythonic' APQC HTML
  - numpy
  - scipy
  - pillow
  - "ipython>=8.0"            # minimal ver for tab-autocomplete to work
  - jupyter
  - prompt_toolkit=3.0.*      # >=2 for jupyter to autocomplete; >=3 for ipython
  - "flask>=2.1.2"            # for local server for APQC HTML
  - "flask-cors>=3.0.10"      # for local server for APQC HTML
  - pip                       # used for TEDANA
  - pip:
    - tedana                  # getting TEDANA

The old one, which did work for a long time but suddenly no more, was:

name: py3_afni_ted_py11       # conda env create -f env*afni_ted_py11.yml
channels:
  - conda-forge
  - defaults
dependencies:
  - "python=3.11"             # 3.12 has annoying 'imp' issue
  - "matplotlib>=2.2.3"       # minimal ver for 'pythonic' APQC HTML
  - numpy
  - scipy
  - pillow
  - "ipython>=8.0"            # minimal ver for tab-autocomplete to work
  - jupyter
  - prompt_toolkit=3.0.*      # >=2 for jupyter to autocomplete; >=3 for ipython
  - "flask>=2.1.2"            # for local server for APQC HTML
  - "flask-cors>=3.0.10"      # for local server for APQC HTML
  - pip                       # used for TEDANA
  - pip:
    - tedana                  # getting TEDANA

Thanks,
pt

maPCA v0.0.5 uses n_features_in_ instead of n_features_ to comply with newer versions of sklearn. It also increases the minimum sklearn version that is needed to run maPCA.

Glad to see it worked!