Did you try: pipeline.named_steps["the_string_name_for_knn"].kneighbours
? pipeline should be replaced by the name you gave to your pipeline and the string in named_steps is the name you have to the knn when setting the pipe. Sole Sent with Proton Mail secure email. ------- Original Message ------- On Friday, September 23rd, 2022 at 10:16 PM, Gregory, Matthew <matt.greg...@oregonstate.edu> wrote: > Hi all, > > I have what is probably a silly question. I read this passage on [1]: > > """ > The pipeline has all the methods that the last estimator in the pipeline has, > i.e. if the last estimator is a classifier, the Pipeline can be used as a > classifier. If the last estimator is a transformer, again, so is the pipeline. > """ > > I'm trying to create a pipeline where my last estimator is a > KNeighborsClassifier and, instead of predict(), I was hoping to use > kneighbors(). But unfortunately, when in a pipeline, I'm getting this > AttributeError: > > AttributeError: 'Pipeline' object has no attribute 'kneighbors' > > Is kneighbors() really available from the Pipeline? Or is there an > alternative way to call an element in the Pipeline to use it? I tried > "pipe[-1].kneighbors(X)", but that doesn't seem to be applying the earlier > transforms in the pipeline. > > Thanks for any pointers, > matt > > [1] https://scikit-learn.org/stable/modules/compose.html > _______________________________________________ > scikit-learn mailing list > scikit-learn@python.org > https://mail.python.org/mailman/listinfo/scikit-learn _______________________________________________ scikit-learn mailing list scikit-learn@python.org https://mail.python.org/mailman/listinfo/scikit-learn