Python - list the content of an algorithm

Dear Experts,

Actually trying to analyze the machine learning logics behind in algorithms, for example the KNeighborsClassifier():

import pandas
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier()
print(model)

Open in new window


Could you please advise would it be possible to list the content of an algorithm in Python and with which syntax concretely? The above print(model) of course just provides some overall information about the algorithm, but not the content

Thanks in advance,
LVL 1
csehzIT consultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fermi ParadoxPhysicistCommented:
- You can check the official documentation.

- Some IDEs support clicking on the object (eg. on `KNeighborsClassifier`) while holding Ctr key. This would take you to the source file containing this object and then you can inspect the code. (personally I've only used PyCharm; I don't know which other IDEs support this functionality. When it comes to an IDE make sure you pick one that is not outdated and fits best your use case.).

- Also with those IDEs you can write (note the dot):
KNeighborsClassifier.

Open in new window

and it will suggest (that is, autocomplete) all attributes of that object.

- Alternatively, when it comes to open-source projects, you can check the source code on the internet.

There are several other ways to explore the contents of an object like:
- printing the contents of `dir(KNeighborsClassifier)`
- printing `help(KNeighborsClassifier)`
- printing `dir(KNeighborsClassifier())` or `dir(model)` in your code above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csehzIT consultantAuthor Commented:
Thank you for the answer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.