[PYTHON] What I was addicted to when I built my own neural network using the weights and biases I got with scikit-learn's MLP Classifier.

What I was addicted to

The predictions made by the multi-layer perceptron (MLP Classifer) implemented in scikit-learn did not match the predictions of the self-made neural network using the weights and bias matrices that had been learned in advance.

Conclusion first

I didn't standardize the input data ...

How I got hooked

Bonus: Build a neural network with weights and biases acquired by MLP Classifier

import numpy as np
import os
import sys
 Import pandas as pd # library for handling dataFrame
from math import exp, expm1

 input = [[array of input data]]
input = np.array(input)

 df = pd.read_csv ("Data used for standardization of input data (data when trained)")
 df_x = pd.get_dummies (column where you want to generate dummy variables)

# Standardization! (I forgot here)
sc = StandardScaler()
sc.fit_transform(df_x)
input = sc.transform(input)

 bias0 = pd.read_csv ("bias csv output from MLP Classiefer", header = None)
bias0 = bias0.iloc[1:,1:].as_matrix()

 weight0 = pd.read_csv ("weight csv output from MLP Classiefer", header = None)
weight0 = weight0.iloc[1:,1:].as_matrix()

# Weight / Input + Bias
layer0 = np.dot(weight0.T, dummy.T) + bias0

# Activation of the hidden layer. This time it was activated by the ramp function.
layer0 = np.clip(layer0, 0, np.finfo(layer0.dtype).max, out=layer0)

Only in the hidden layer, let the linear combination of input and weight flow through the activation function. .. .. In the final output layer, activated by a sigmoid function

 output_layer = np.dot (weight of last hidden layer, data entering last hidden layer) + bias of last hidden layer

# Activated by sigmoid function
1 / (1 + exp(-output_layer[0, 0]))

I think that it is [0, 0] here because it deals with binary problems.

Recommended Posts

What I was addicted to when I built my own neural network using the weights and biases I got with scikit-learn's MLP Classifier.
Three things I was addicted to when using Python and MySQL with Docker
What I was addicted to when using Python tornado
I made my own 3-layer forward propagation neural network and tried to understand the calculation deeply.
I tried how to improve the accuracy of my own Neural Network
What I was addicted to when combining class inheritance and Joint Table Inheritance in SQLAlchemy
What I did when I was angry to put it in with the enable-shared option
Error and solution when trying to run a classifier made with Labellio with my own ubuntu
What I was addicted to when dealing with huge files in a Linux 32bit environment
What I was addicted to when migrating Processing users to Python
Note that I was addicted to accessing the DB with Python's mysql.connector using a web application.
When I put Django in my home directory, I was addicted to static files with permission errors
The record I was addicted to when putting MeCab on Heroku
What I was addicted to when introducing ALE to Vim for Python
What I was addicted to with json.dumps in Python base64 encoding
A note I was addicted to when creating a table with SQLAlchemy
When I cut the directory for UNIX Socket under / var / run with systemd, I got stuck in a pitfall and what to do
The file name was bad in Python and I was addicted to import
I tried to control the network bandwidth and delay with the tc command
The result was better when the training data of the mini-batch was made a hybrid of fixed and random with a neural network.
What I was addicted to Python autorun
What I was addicted to when creating a web application in a windows environment
What I did when I got stuck in the time limit with lambda python
A note I was addicted to when running Python with Visual Studio Code
A story that I was addicted to when I made SFTP communication with python
When I tried to do socket communication with Raspberry Pi, the protocol was different
I tried to score the syntax that was too humorous and humorous using the COTOHA API.
The story when I was using IntelliJ on Linux and could not input Japanese
[Go language] Be careful when creating a server with mux + cors + alice. Especially about what I was addicted to around CORS.
How to use the C library in Python
Log in to the remote server with SSH
Specify the Python executable to use with virtualenv
The easiest way to use OpenCV with python
How to use tkinter with python in pyenv
Use pygogo to get the log in json.
Convert the image in .zip to PDF with Python
How to use the exists clause in Django's queryset
Specify MinGW as the compiler to use with Python
How to use the model learned in Lobe in Python
I want to use the R dataset in python
use something other than the default profile with boto3
What I was addicted to when I built my own neural network using the weights and biases I got with scikit-learn's MLP Classifier.
Survey on the use of machine learning in real services
How to use the __call__ method in a Python class
How to manipulate the DOM in an iframe with Selenium
[Python] I want to use the -h option with argparse
I can't log in to the admin page with Django3
Notes on how to use marshmallow in the schema library