Book Image

Python Machine Learning Cookbook

By : Prateek Joshi, Vahid Mirjalili
Book Image

Python Machine Learning Cookbook

By: Prateek Joshi, Vahid Mirjalili

Overview of this book

Machine learning is becoming increasingly pervasive in the modern data-driven world. It is used extensively across many fields such as search engines, robotics, self-driving cars, and more. With this book, you will learn how to perform various machine learning tasks in different environments. We’ll start by exploring a range of real-life scenarios where machine learning can be used, and look at various building blocks. Throughout the book, you’ll use a wide variety of machine learning algorithms to solve real-world problems and use Python to implement these algorithms. You’ll discover how to deal with various types of data and explore the differences between machine learning paradigms such as supervised and unsupervised learning. We also cover a range of regression techniques, classification algorithms, predictive modeling, data visualization techniques, recommendation engines, and more with the help of real-world examples.
Table of Contents (19 chapters)
Python Machine Learning Cookbook
About the Author
About the Reviewer

Building an optical character recognizer using neural networks

Now that we know how to interact with the data, let's build a neural network-based optical character-recognition system.

How to do it…

  1. Create a new Python file, and import the following packages:

    import numpy as np
    import neurolab as nl
  2. Define the input filename:

    # Input file
    input_file = ''
  3. When we work with neural networks that deal with large amounts of data, it takes a lot of time to train. To demonstrate how to build this system, we will take only 20 datapoints:

    # Number of datapoints to load from the input file
    num_datapoints = 20
  4. If you look at the data, you will see that there are seven distinct characters in the first 20 lines. Let's define them:

    # Distinct characters
    orig_labels = 'omandig'
    # Number of distinct characters
    num_output = len(orig_labels)
  5. We will use 90% of the data for training and remaining 10% for testing. Define the training and testing parameters:

    # Training and testing parameters
    num_train = int...