Building a simple classifier
Let's see how to build a simple classifier using some training data.
How to do it…
- We will use the
simple_classifier.py
file that is already provided to you as reference. Assuming that you imported thenumpy
andmatplotlib.pyplot
packages like we did in the last chapter, let's create some sample data:X = np.array([[3,1], [2,5], [1,8], [6,4], [5,2], [3,5], [4,7], [4,-1]])
- Let's assign some labels to these points:
y = [0, 1, 1, 0, 0, 1, 1, 0]
- As we have only two classes, the
y
list contains 0s and 1s. In general, if you have N classes, then the values iny
will range from 0 to N-1. Let's separate the data into classes based on the labels:class_0 = np.array([X[i] for i in range(len(X)) if y[i]==0]) class_1 = np.array([X[i] ...
Get Python: Real World Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.