classify_sklean keyerror

I am using Python to run the following code:

//////////// start of code

Importing data

from qiime2 import Artifact

artifact = Artifact.import_data(‘SampleData[PairedEndSequencesWithQuality]’, ‘Samples’, view_type=‘CasavaOneEightSingleLanePerSampleDirFmt’)

Dada2 denoise-paired

from qiime2.plugins.dada2.methods import denoise_paired

denoised = denoise_paired(artifact, 290, 290, 8, 8)

Phylogeny align to tree mafft fasttree

from qiime2.plugins.phylogeny.pipelines import align_to_tree_mafft_fasttree

fasttree = align_to_tree_mafft_fasttree(denoised.representative_sequences)

Classify sklearn

from qiime2.plugins.feature_classifier.methods import classify_sklearn

classifier_artifact = Artifact.load(‘classifier_2019.4.qza’)
classify = classify_sklearn(denoised.representative_sequences, classifier_artifact)

//////////////// end of code

the output of the terminal is:

the error comes from the last command. Ive searched the internet for people with the same issue but i cant find a solution.

Welcome to the community, @lute_oosten !

This is a strange error, I have not seen it before. Notably, it is not actually coming from QIIME 2 itself, it appears to be an error during unpickling the saved classifier.

I have an idea of what might be causing this, related to this line:

This seems to imply that you are using a very old classifier, trained in an earlier version of QIIME 2. It looks like now you are using QIIME 2 version 2020.11. While all other artifact types are meant to be compatible between versions, the trained feature classifiers are not guaranteed to be cross-compatible, because the version of scikit-learn used for training and classifying must be the same.

So my theory is that pickle has been updated in the past 2 years, and is no longer compatible with this ancient pickle object (:spider_web: :cucumber: )

I would investigate further, but it is quite pointless. Because even if this command did not fail at unpickling, it would certainly fail one line later, at the validation stage (raising an error that you are using an incompatible classifier because it was trained using the wrong version of q2-feature-classifier).

So the fix in this case is to download or re-train a new classifier that is compatible with the version of QIIME 2 that you are running.

I hope that helps!

1 Like

SOLLUTION FOUND! So I was using qiime2 2021.2 and the classifier was created with qiime2 2019.4, after installing the right qiime version it workes flawless.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.