Python & Machine Learning Study Memo ③: Neural Network

Continued

Reference materials

Udemy Everyone's AI Course Artificial Intelligence and Machine Learning Learned from Zero with Python

Issue setting

Given the latitude and longitude, create a program that determines whether it belongs to Tokyo or Kanagawa.

Judgment method

Judgment is made by a neural network with two input layers, two intermediate layers, and one output layer.

Neuron class

class Neuron:
    input_sum = 0.0
    output = 0.0

    def setInput(self, inp):
        self.input_sum += inp

    def getOutput(self):
        self.output = sigmoid(self.input_sum)
        return self.output

    def reset(self):
        self.input_sum = 0
        self.output = 0

setInput Sum the inputs.

getOutput Outputs the value obtained by converting the input value with the activation function. Neurons have the characteristic of firing when the input value exceeds the threshold value, which is mimicked by applying the sigmoid function to the activation function as described above.

reset Reset the input value.

neural network

class NeuralNetwork:
    #Input weight
    w_im = [[0.496, 0.512], [-0.501, 0.990], [0.490, -0.502]] # [[i1-m1, i1-m2], [i2-m1, i2-m2], [bias1-m1, bias1-m2]]
    w_mo = [0.121, -0.4996, 0.200] # [m1-o, m2-o, bias2-0]
    #Declaration of each layer
    input_layer = [0.0, 0.0, 1.0]
    middle_layer = [Neuron(), Neuron(), 1.0]
    ouput_layer = Neuron()
    ...

ʻThe third element of input_layer and middle_layer` is bias.

Input format and file reading

Input file

Read a file that describes longitude and latitude on one line.

35.48,137.76
35.47,137.81
35.29,138.06
...

Results obtained

Figure_1.png

It is possible to distinguish between Tokyo and Kanagawa for complicated boundaries. To make a proper judgment, it is necessary to set the weight and threshold of each input appropriately. The setting method will be learned from the next time onwards.

Recommended Posts

Python & Machine Learning Study Memo ③: Neural Network
Python & Machine Learning Study Memo: Environment Preparation
Python & Machine Learning Study Memo ④: Machine Learning by Backpropagation
Python & Machine Learning Study Memo ⑥: Number Recognition
[Python / Machine Learning] Why Deep Learning # 1 Perceptron Neural Network
Python & Machine Learning Study Memo ⑤: Classification of irises
Python & Machine Learning Study Memo ②: Introduction of Library
Python & Machine Learning Study Memo ⑦: Stock Price Forecast
Python learning memo for machine learning by Chainer Chapter 13 Neural network training ~ Chainer completed
"Scraping & machine learning with Python" Learning memo
[Memo] Machine learning
I installed Python 3.5.1 to study machine learning
Python class (Python learning memo ⑦)
Python module (Python learning memo ④)
Machine learning course memo
Python learning memo for machine learning by Chainer Chapter 13 Basics of neural networks
Python exception handling (Python learning memo ⑥)
Neural network with Python (scikit-learn)
Python learning memo for machine learning by Chainer from Chapter 2
Python learning memo for machine learning by Chainer Chapters 1 and 2
Machine learning with Python! Preparation
Machine Learning Study Resource Notepad
Practical machine learning system memo
Python Machine Learning Programming> Keywords
Neural network implementation in python
Beginning with Python machine learning
Memo for building a machine learning environment using Python
Python learning memo for machine learning by Chainer Chapter 7 Regression analysis
Python control syntax, functions (Python learning memo ②)
Neural network with OpenCV 3 and Python 3
Machine learning with python (1) Overall classification
Machine learning summary by Python beginners
PRML Chapter 5 Neural Network Python Implementation
Input / output with Python (Python learning memo ⑤)
<For beginners> python library <For machine learning>
Python: Preprocessing in Machine Learning: Overview
Interval scheduling learning memo ~ by python ~
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
python memo
Python learning memo for machine learning by Chainer Chapter 10 Introduction to Cupy
Python memo
Machine learning
python memo
python learning
Python learning memo for machine learning by Chainer Chapter 9 Introduction to scikit-learn
Python memo
Python memo
Notes on PyQ machine learning python grammar
Python numbers, strings, list types (Python learning memo ①)
[Learning memo] Basics of class by python
Amplify images for machine learning with python
Use machine learning APIs A3RT from Python
Implementation of 3-layer neural network (no learning)
[python] Frequently used techniques in machine learning
Why Python is chosen for machine learning
"Python Machine Learning Programming" Summary Note (Jupyter)
Python: Preprocessing in machine learning: Data acquisition
[Shakyo] Encounter with Python for machine learning
Python data structure and operation (Python learning memo ③)
[Python] First data analysis / machine learning (Kaggle)
[Python] When an amateur starts machine learning