Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my output
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-11-178ac3932616> in <module>
      1 import pandas as pd
----> 2 from sk.learn import DecisionTreeClassifier
      3 
      4 music_data = pd.read_csv('music1.csv')
      5 X = music_data.drop(columns=['genre'])

ModuleNotFoundError: No module named 'sk'


What I have tried:

import pandas as pd
from sk.learn import DecisionTreeClassifier

music_data = pd.read_csv('music1.csv')
X = music_data.drop(columns=['genre'])
y = music_data['genre']

model = DecisionTreeClassifier()
model.fit(x,y)
music_data

Posted
Updated 2-Aug-19 11:51am
v2

1 solution

Did you mean to use sklearn, instead of sk.learn? That is something that this error code is telling you.

Try this,
Python
import pandas as pd
from sklearn import tree # tree scope contains the classifier

# then in the code, access the DecisionTreeClassifier like, 
model = tree.DecisionTreeClassifier()
This will help you if you have scikit-learn installed. If you get issue on sklearn, then you need to install the framework first; python - ModuleNotFoundError: No module named 'sklearn' - Stack Overflow[^]

See more on the DecisionTreeClassifier[^].

See an example of this usage here, 1.10. Decision Trees — scikit-learn 0.21.3 documentation[^].

Before, I close this answer, here is a food for thought: Can you make it work with, from sklearn.tree import DecisionTreeClassifier?
 
Share this answer
 
v2
Comments
Member 14549093 3-Aug-19 7:25am    
Now i got this error when i entered sklearn.
ImportError Traceback (most recent call last)
<ipython-input-2-685ef44b2b7a> in <module>
1 import pandas as pd
----> 2 from sklearn import DecisionTreeClassifier
3
4 music_data = pd.read_csv('music1.csv')
5 X = music_data.drop(columns=['genre'])

ImportError: cannot import name 'DecisionTreeClassifier' from 'sklearn' (E:\Python\lib\site-packages\sklearn\__init__.py)
Afzaal Ahmad Zeeshan 3-Aug-19 9:07am    
Please use from sklearn.test import DecisionTreeClassifier. This should work.
Member 14549093 3-Aug-19 7:26am    
i am now installing pip as you told me.
But i have sklearn in my anaconda but why i am getting this error.
Afzaal Ahmad Zeeshan 3-Aug-19 9:07am    
If sklearn is installed in Anaconda, then make sure you are using the same environment where sklearn is installed.
Member 14549093 4-Aug-19 7:28am    
I am using the same environment. On the other hand, sklearn.test is also not working.
......
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-ae8b1bd24108> in <module>
1 import pandas as pd
----> 2 from sklearn.Test import DecisionTreeClassifier
3
4 music_data = pd.read_csv('music1.csv')
5 X = music_data.drop(columns=['genre'])

ModuleNotFoundError: No module named 'sklearn.Test'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900