[PYTHON] I tried to classify dragon ball by adaline

Introduction

--What is adaline? --Data used this time

What is adaline

There was a very easy-to-understand article, so I will post it. It's an improved version of the so-called Perset Pron. 2.ADALINE

Data used this time

This time, I will use the data of quite famous iris. https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data Please download this.

Implementation

This time I would like to implement it in python. As part of the lesson, I wrote it without much research, so please understand that there are some parts that are not functionalized.

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

df = pd.read_csv(‘iris-data.csv’,header=None)
df_new = df.drop(columns=[1,3])
df_new = df_new.replace(‘Iris-setosa’,0)
df_new = df_new.replace(‘Iris-versicolor’,1)
df_new

eta = 0.001
epoch = 100
cost_=[]
t = np.array(df_new[4])
X = np.array([df_new[0],df_new[2]]).T
w = np.random.normal(0.0, 0.01, size=X.shape[1] + 1)

# Check the initial value of the weight
print(w)

for I in range(epoch):
        input_ = np.dot(X,w[1:])+w[0]
        predict = np.where(input_>= 0, 1, 0)
        errors = t - predict

 #Update to weight
        w[1:] += eta * np.dot(errors,X)
        w[0] += eta * errors.sum()

 #Calculation of cost function
        cost = (errors**2).sum() / 2.0
        cost_.append(cost)

# Checking the weight
print(w)


# Plot for the time being
x_a = range(4,8)
y_a = [-(w[1]/w[2])*xi-(w[0]/w[2]) for xi in x_a]
plt.scatter(df_new.iloc[:50,0],df_new.iloc[:50,1],label = ‘Iris-versicolor’)  
plt.scatter(df_new.iloc[50:,0],df_new.iloc[50:,1],label = ‘Iris-setosa’)
plt.ylabel(“petal length[cm]”)
plt.xlabel(“sepal length[cm]”)
plt.plot(x_a,y_a)
plt.legend()
plt.show()

image.png

I wrote it almost sequentially, but the graph is plotted well. I am glad that I was able to deepen my understanding of adaline.

Finally

How was that? It's not very clean code, but I posted it because I also wrote python. In the future, I would like to post higher-level items.

Recommended Posts

I tried to classify dragon ball by adaline
I tried to move the ball
I tried to classify MNIST by GNN (with PyTorch geometric)
I tried to classify text using TensorFlow
I tried to implement ADALINE in Python
I tried to program bubble sort by language
I tried to get an image by scraping
I tried to debug.
I tried to paste
I tried to classify mnist numbers by unsupervised learning [PCA, t-SNE, k-means]
I tried to classify Oba Hana and Emiri Otani by deep learning
I tried to classify Oba Hana and Emiri Otani by deep learning (Part 2)
I tried to implement Dragon Quest poker in Python
I tried to classify the voices of voice actors
I tried to learn PredNet
I tried to implement PCANet
I tried to introduce Pylint
I tried to touch jupyter
I tried to implement StarGAN (1)
I tried to implement anomaly detection by sparse structure learning
I tried to speed up video creation by parallel processing
I wanted to classify Shadowverse card images by reader class
[Django] I tried to implement access control by class inheritance.
[Introduction to Pandas] I tried to increase exchange data by data interpolation ♬
I tried to classify music major / minor on Neural Network
I tried to classify Shogi players Takami 7th Dan and Masuda 6th Dan by CNN [For CNN beginners]
I tried to implement Deep VQE
I tried to create Quip API
I tried to touch Python (installation)
I tried to implement adversarial validation
I tried Watson Speech to Text
I tried to touch Tesla's API
I tried to implement hierarchical clustering
I tried to implement Realness GAN
I tried to estimate the interval.
I tried to create a simple credit score by logistic regression.
[Introduction to simulation] I tried playing by simulating corona infection ♬ Part 2
I tried to visualize the Beverage Preference Dataset by tensor decomposition.
I tried to implement sentence classification by Self Attention with PyTorch
I tried to summarize the commands used by beginner engineers today
I tried to predict by letting RNN learn the sine wave
I tried to solve the shift scheduling problem by various methods
I tried to create a linebot (implementation)
I tried moving the image to the specified folder by right-clicking and left-clicking
I tried to implement Autoencoder with TensorFlow
I tried to summarize the umask command
I tried to implement permutation in Python
I tried to communicate with a remote server by Socket communication with Python.
I tried to create a linebot (preparation)
I tried to summarize the general flow up to service creation by self-education.
I tried to visualize AutoEncoder with TensorFlow
I tried to recognize the wake word
I tried to get started with Hy
I tried to implement PLSA in Python 2
Python3 standard input I tried to summarize
765 I tried to identify the three professional families by CNN (with Chainer 2.0.0)
I tried to implement Bayesian linear regression by Gibbs sampling in python
I tried to classify guitar chords in real time using machine learning
I tried to summarize the graphical modeling.
I tried adding post-increment to CPython Implementation
I tried to let optuna solve Sudoku