[PYTHON] When I try to go back using chainer, it fits a little

Overview

Source code

Where I got stuck

python


#target is correct answer data
#mnist.If it is py, it is written like ↓
target = diabetes['target'].astype(np.float32) #With this, it will not work if the number of mini batches is 2 or more

If it is ↑, a Value Error like ↓ will appear (13 is batch size).

ValueError: non-broadcastable output operand with shape (1,30) doesn't match the broadcast shape (13,30)

As a result of trial and error, it worked.

python


#I have to reshape
target = diabetes['target'].astype(np.float32).reshape(len(diabetes['target']), 1)

Changes from example / mnist.py

environment

Regarding the installation of chainer

change point

data set

model

python


n_units   = 30
model = FunctionSet(l1=F.Linear(10, n_units),                                 
                    l2=F.Linear(n_units, n_units),
                    l3=F.Linear(n_units, 1)) 

Adjustment of learning rate

python


optimizer = optimizers.AdaDelta(rho=0.9)

Error function and evaluation method

python


# Neural net architecture
def forward(x_data, y_data, train=True):
    x, t = Variable(x_data), Variable(y_data)
    h1 = F.dropout(F.relu(model.l1(x)),  train=train)
    h2 = F.dropout(F.relu(model.l2(h1)), train=train)
    y  = model.l3(h2)
    #Returns mean squared error and prediction results
    #The prediction result is returned because the correlation coefficient is calculated later with the prediction result and the correct answer data.
    return F.mean_squared_error(y, t), y

python


pearson = np.corrcoef(np.asarray(preds).reshape(len(preds),), np.asarray(y_test).reshape(len(preds),))

Impressions

Recommended Posts

When I try to go back using chainer, it fits a little
When I try to push with heroku, it doesn't work
When I try to make Apache SSL, it doesn't start.
A memorandum when I tried to get it automatically with selenium
When I try matplotlib in Python, it says'cairo.Context'
When I tried to make a VPC with AWS CDK but couldn't make it
When I tried to create a virtual environment with Python, it didn't work
I tried to make a ○ ✕ game using TensorFlow
Linux Ubuntu16.04 I got a little scary error when I ran a command using sudo
When I tried to create a project using Python on Docker with PyCharm, it didn't work, but it worked with Docker Compose.
Every time I try to read a csv file using pandas, I get a numpy error.
A beginner tried coloring line art with chainer. I was able to do it.
A little trick to know when writing a Twilio application using Python on AWS Lambda
I get an error when I try to raise Python to 3 series using pyenv on Catalina
(Python) Try to develop a web application using Django
I tried to approximate the sin function using chainer
[Go + Gin] I tried to build a Docker environment
What I was addicted to when using Python tornado
I tried to draw a configuration diagram using Diagrams
Precautions when using Chainer
I wrote a class that makes it easier to divide by specifying part of speech when using Mecab in python
I'm always impatient when ordering a cafe, so I made a React app to solve it.
When I tried the AtCoder Beginner Contest, it was a terrible result, so I look back
[Solution] When I try to connect to CloudSQL with GAE, I get an ImportError only when using dev_appserver.
The story I was addicted to when I specified nil as a function argument in Go
Try to make it using GUI and PyQt in Python
[Go language] Try to create a uselessly multi-threaded line counter
I wrote it in Go to understand the SOLID principle
I tried to automate [a certain task] using Raspberry Pi
I stumbled when I tried to install Basemap, so a memorandum
I tried to make a stopwatch using tkinter in python
Try to model a multimodal distribution using the EM algorithm
I tried to approximate the sin function using chainer (re-challenge)
I tried to make a simple text editor using PyQt
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
When I try to divide a list with MeCab, I get'TypeError: in method'Tagger_parse', argument 2 of type'char const *''
Try to select a language
I tried to get a database of horse racing using Pandas
I got a TypeError:'int' object is not iterable when using keras
Make it possible to output a log to a file with go echo
I tried to make a regular expression of "amount" using Python
I tried to make a regular expression of "time" using Python
I tried to implement anomaly detection using a hidden Markov model
A note I was addicted to when making a beep on Linux
Try to edit a new image using the trained StyleGAN2 model
I tried to make a regular expression of "date" using Python
I tried to get a list of AMI Names using Boto3
A note I was addicted to when creating a table with SQLAlchemy
When I try to use pip, SSL module is not available.
I want to create a pipfile and reflect it in docker
I get a can't set attribute when using @property in python
I tried to make a todo application using bottle with python
[Django] I wanted to test when POSTing a large file [TDD]
When a Python beginner tried using Bottle, it worked unexpectedly easily.
Try it when Visual Studio Code can't load a Python module
I tried to make a mechanism of exclusive control with Go
What I stumbled upon when using CodeIgniter on a Linux server