Created
September 21, 2018 06:36
-
-
Save li2hub/85db19babbf13f7b5e11a7b59a6e5f3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Store number features in variables | |
redcolor=0 | |
orangecolor=1 | |
smooth=0 | |
rough=1 | |
apple=0 | |
orange=1 | |
#Put all data points in an array - features and labels in seperate arrays | |
features=[[redcolor,smooth],[orangecolor,rough],[redcolor,smooth], | |
[redcolor,smooth],[orangecolor,rough],[orangecolor,rough],[redcolor,smooth]] | |
labels=[apple,orange,apple,apple,orange,orange,apple] | |
#import decision tree function from sklearn package and train it on your data | |
from sklearn import tree | |
classifier=tree.DecisionTreeClassifier() | |
classifier.fit(features,labels) | |
#take fresh input from user | |
inputcolor=input('Enter the color of the fruit: ') | |
if (inputcolor=='red' or inputcolor=='redcolor'): | |
inputcolornew=0 | |
else: | |
inputcolornew=1 | |
inputtexture=input('Enter the texture of the fruit: ') | |
if (inputtexture=='smooth'): | |
inputtexturenew=0 | |
else: | |
inputtexturenew=1 | |
#predict output for user's input and print output | |
if(classifier.predict([[inputcolornew,inputtexturenew]])==0): | |
print('Fruit is an Apple') | |
else: | |
print('Fruit is an Orange') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For beginners, it is an excellent code to understand ML.