Machine Learning (Classification) Intro Tutorial

Ben Brown
2 min readApr 9, 2020

Classification is a type of supervised machine learning.

Diagram showing classification in the machine learning spectrum.

Python is the main programming language today used in machine learning applications and research. Scikit learn is a library that is used in python that allows creating objects that can ultimately fit data.

First, install the Scikit learn library so that the functionality of the library will be taken advantage of. Below is the code snippet to do that. (I am using a mac.)

$pip3 install sklearn

A classifier has inputs and outputs. The output is what the prediction is; which a computer will transmit with a 0 or 1. The inputs are the characteristics of the object that gets predicted.

from sklearn import tree

Sci kit learn has a lot of machine learning objects in it. The one you will use is ‘tree’.

Next, the characteristics of the thing that is being predicted:

features = [[140,1],[130,1],[150,0],[170,0]]labels = [0,0,1,1]

Next, making the machine learning algorithm object that will create the set of rules around the classifier.

# set of rules (classifier)classifier = tree.DecisionTreeClassifier()

Next, the classifier that is built upon these ‘set of rules’ (algorithm).

# algorithm that sets the rulesclassifier = classifier.fit(features,labels)

Finally, test the classifier on the data it has yet to see before and display the result.

print(classifier.predict([[165,0]]))

Thanks

--

--