Created
October 20, 2017 16:51
-
-
Save magixer/ae6048ab46e74fe3d0149fc8c8ce9259 to your computer and use it in GitHub Desktop.
Beginners guide to their first machine learning program.
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
''' | |
The program predicts if a fruit is an apple or an orange from examining a | |
given data set of four fruits with two labels - apple or orange. | |
''' | |
import sklearn # Import SciKit Learn | |
from sklearn import tree # Import a classifier called 'DescisionTreeClassifier' | |
# Dataset of 4 fruits with 2 labels, apple and orange | |
''' | |
Feeding data in form [x, y] where, | |
x is weight of fruit in grams and, y is texture of the fruit - smooth or bumpy. | |
0 for smooth and 1 for bumpy. | |
''' | |
features = [[140, 0], [130, 0], [150, 1], [145, 1]] # Feeding features of the data in 'features' | |
labels = ['apple','apple','orange','orange'] # Feeding output labels of the data in 'labels' | |
classifier = tree.DecisionTreeClassifier() # Initializing the tree classifier | |
classifier.fit(features, labels) # Feeding the data to the classifier | |
# Ask your program to evaluate a fruit from the given data. | |
print(classifier.predict([[147, 1]])) # Predicting a New Fruit of 147 grams and bumpy texture. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment