Import a random forest classifier trained using scikit into qiime2 as a sample_estimator.qza.

Hello QIIME2 team,

I am trying to import a random forest classifier that I trained using scikit into QIIME2. Is there a straightforward way of doing this?

I tried to save my classifier as an sklearn_pipeline.tar and added a sklearn_version.json to the "clf" directory and ran the following command on qiime2-2023.5:
qiime tools import
--input-path clf
--output-path rf_classifier_457training.qza
--type 'SampleEstimator[Classifier]'

The command seems to run fine but when I use the rf_classifier_457training.qza file for predictions in the following command, I get an error:

qiime sample-classifier predict-classification
--i-table otu_table.qza
--i-sample-estimator rf_classifier_457training.qza
--o-predictions new_predictions_457training.qza
--o-probabilities new_probabilities_457training.qza
Plugin error from sample-classifier: [Errno 2] No such file or directory: '/var/folders/46/37q2f70d54zd23k0kk17p3wc0000gn/T/q2-DirectoryFormat-aj2u33uq/sklearn_pipeline.pkl' Debug info has been saved to /var/folders/46/37q2f70d54zd23k0kk17p3wc0000gn/T/qiime2-q2cli-err-eb6eyydj.log

Thank you very much in advance!

Hi @meghna_swayambhu,

Can you try re running the command with the --verbose flag and posting the full error message here?
Also, you might consider updating your qiime environment, the current release is 2024.2.

-- Hannah

Hi Hannah,
Thank you for your reply! I am not updating my qiime only becuase I have already done lots of analyses with this version and if possible I would like to keep the same version. However, if the update is needed for importing a classifier, then I will update the environment.

Please fine the entire error message below.

Traceback (most recent call last):
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/q2cli/", line 468, in call
results = action(**arguments)
File "", line 2, in predict_classification
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/qiime2/sdk/", line 271, in bound_callable
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/qiime2/core/type/", line 390, in transform_and_add_callable_args_to_prov
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/qiime2/core/type/", line 423, in _transform_and_add_input_to_prov
transformed_input = _input._view(spec.view_type, recorder)
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/qiime2/sdk/", line 401, in _view
result = transformation(self._archiver.data_dir)
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/qiime2/core/", line 70, in transformation
new_view = transformer(view)
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/q2_sample_classifier/", line 140, in _a
pipeline = joblib.load(os.path.join(dirname, 'sklearn_pipeline.pkl'))
File "/Users/meghnaswayambhu/miniconda3/envs/qiime2-2023.5/lib/python3.8/site-packages/joblib/", line 650, in load
with open(filename, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/46/37q2f70d54zd23k0kk17p3wc0000gn/T/q2-DirectoryFormat-wf7750_b/sklearn_pipeline.pkl'

Plugin error from sample-classifier:

[Errno 2] No such file or directory: '/var/folders/46/37q2f70d54zd23k0kk17p3wc0000gn/T/q2-DirectoryFormat-wf7750_b/sklearn_pipeline.pkl'

See above for debug info.

Hello @meghna_swayambhu,

Can you run ls -l clf and post the output so we can see the contents of the directory you imported? Can you also run file sklearn_pipeline.tar? I don't think the .tar file was created properly--how did you make that/where did you download it from?