May I know how to import
DecisionTreeClassifier
fromsklearn.tree
as there is an error shown:ModuleNotFoundError: No module named 'sklearn'
Also, every time when I want to import functions like
pandas
, I need topip install
them which is time-consuming. Is there any other methods to avoid installing each time for new importing function? p.s. I have downloadedanaconda
already, but not sure if it could work. Much Thanks!
Asked
Active
Viewed 1,227 times
0

rickhg12hs
- 10,638
- 6
- 24
- 42

Janice Ng
- 11
- 3
-
"every time when I want to import ... I need to pip install them" - this shouldn't happen. The entire point of installing packages is to have them available without installing each time. The error with sklearn happens because Scikit-Learn is not installed: `pip install scikit-learn` – ForceBru Feb 12 '22 at 09:12
-
1If you are using `conda`, you may need to use it rather than `pip`. – rickhg12hs Feb 13 '22 at 03:57
-
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Feb 22 '22 at 16:16
-
Please [edit] your post to add code and data as text ([using code formatting](https://stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](https://meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. See [mcve] on what code is required. – Adriaan Jan 17 '23 at 12:30
2 Answers
0
Just Re-install Anaconda with the latest version and use this code:
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
music_d=pd.read_csv('music.csv')
X=music_d.drop(columns=['genre'])
y=music_d['genre']
model=DecisionTreeClassifier()
model.fit(X,y)
prediction=model.predict([[21,1],[22,0]])
prediction
-1
You need to install the package Sklearn
-
OP already imports from `sklearn.tree`. This answer therefore is either useless, or severely underexplained. – Adriaan Jan 17 '23 at 12:30
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 18 '23 at 10:06