Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Machine Learning for OpenCV

You're reading from   Machine Learning for OpenCV Intelligent image processing with Python

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781783980284
Length 382 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Michael Beyeler Michael Beyeler
Author Profile Icon Michael Beyeler
Michael Beyeler
Michael Beyeler (USD) Michael Beyeler (USD)
Author Profile Icon Michael Beyeler (USD)
Michael Beyeler (USD)
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. A Taste of Machine Learning FREE CHAPTER 2. Working with Data in OpenCV and Python 3. First Steps in Supervised Learning 4. Representing Data and Engineering Features 5. Using Decision Trees to Make a Medical Diagnosis 6. Detecting Pedestrians with Support Vector Machines 7. Implementing a Spam Filter with Bayesian Learning 8. Discovering Hidden Structures with Unsupervised Learning 9. Using Deep Learning to Classify Handwritten Digits 10. Combining Different Algorithms into an Ensemble 11. Selecting the Right Model with Hyperparameter Tuning 12. Wrapping Up

Implementing your first perceptron

Perceptrons are easy enough to be implemented from scratch. We can mimic the typical OpenCV or scikit-learn implementation of a classifier by creating a Perceptron object. This will allow us to initialize new perceptron objects that can learn from data via a fit method and make predictions via a separate predict method.

When we initialize a new perceptron object, we want to pass a learning rate (lr, or η in the previous section) and the number of iterations after which the algorithm should terminate (n_iter):

In [1]: import numpy as np
In [2]: class Perceptron(object):
... def __init__(self, lr=0.01, n_iter=10):
... self.lr = lr
... self.n_iter = n_iter
...

The fit method is where most of the work is done. This method should take as input some data samples (X) and their associated target labels (y). We will then create an array...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image