The first step of machine learning ~ For those who want to implement with python ~

The beginning of machine learning part1

Introduction

Hello. My name is mizutakawater and I will be a member of society from April 2020. I like baseball and lacrosse. I'm learning about reinforcement learning in my graduation research, but machine learning! Artificial intelligence! AI! Isn't there anything that explains it in an easy-to-understand manner? I felt that. (In the first place, I often think that academic books and technical books of engineers are too unfriendly to beginners compared to liberal arts studies. Is it the culture of engineers to say things that are easy to understand incomprehensible? ??) ← It seems to be killed by a skilled engineer

By the way, _It's really easy for beginners to understand (← important concept) _Introduction of machine learning, I would like to use python! !! There may be differences in the details, but I will pursue easy-to-understand, like an engineer from a liberal arts background.

Introduction

Terms you want to remember

It's a sudden word, but I have to put up with it because there are only two (laughs). Even if you don't remember the words, there is no problem if you can understand only the outline.

Overview Notation(Custom)
Explanatory variable Data used for prediction, also called features X
Objective variable Numerical values and data you want to predict y

Example: Predict the 100m dash time (objective variable) from the height, weight, and age (explanatory variable) of track and field athletes.

Types of machine learning

Machine learning can be divided into three main categories! Immediately, I will learn while using the explanatory variables and objective variables that came out earlier (also as a review).

―― 1 Supervised learning

Explanatory variable(X)Objective variable using(y)Predict.
Correct answer data(Explanatory variable)Prepare the data you want from there(Objective variable)Image to predict

―― 2 Unsupervised learning

Predict what the objective variable itself is good from the explanatory variable when the objective variable is unknown

―― 3 Reinforcement learning

The program learns better choices on its own

This time, the concept is __ easy for anyone to understand, so let's learn about supervised learning, which is the basis of the basics! Unsupervised learning and reinforcement learning are different programs!

In learning supervised learning

There are two types of supervised learning.

type Contents Example
Regression Numerical forecast 100m dash time forecast
Classification Category prediction Prediction of male or female

Regression, classification, and other difficult words ... → In the end, it's the difference between predicting numbers (= regression) and predicting attributes (= classification)!

Now, let's learn while practicing __supervised learning __regression!

Practice

Numerical forecast

First of all a simple problem. Let's think

There are A ~ D. Their height and weight are as follows. Mr. A: 40kg, 150cm Mr. B: 50kg, 160cm Mr. C: 60kg, 170cm Mr. D: 70kg, 180cm

Then, what is the height of Mr. E, who weighs 55 kg (can be predicted)?

question1

Probably, as shown in the figure, connect the four lines with a straight line, and that straight line overlaps just 55 kg! !! !! Yes, 165 cm! I think it's like that. This is the first-order formula for x (the one I learned in 1!)

y(height) = x(body weight) + 110

It's really easy, that's right. And this straight line is the objective function for predicting the objective variable. __ Machine learning (regression) is almost the goal of finding this objective function __! (There are different approaches for different algorithms, but ignore them! I'm sorry!) Because If you know the formula of this straight line, you can find the height by substituting X = 55 It's easy But I don't think there is such convenient data!

So, it will be long, so next time, let's learn how to find the objective function when the data (explanatory variable) is more complicated ~ (Oh, what's the purpose? The purpose is __ to learn about the return of supervised machine learning __! How do you predict the height of a person weighing 55 kg when the explanatory variables are a little more complicated? ?? I'm glad if you understand the story ~)

This is the end of part 1 for theory. The following is the code implementation by python.

Implementation of the above graph by python!

We also sang __using __python as a theme, so let's learn how to make this graph. It may be just right for beginners! Since it is for beginners, let's start with the environment construction! (Full-scale implementation of machine learning with python will be available next time!)

Environment

--Environment used: Anaconda, MacOs --Editor, execution environment: JupyterNotebook

Benefits of using Anaconda and Jupyter Notebook

Anaconda is a tool that allows you to easily manage the execution environment of Pytho. Building an environment for the first barrier to programming. You can do it quickly with Anaconda. There is no way not to use this.

Installation of Anaconda

Here, go to the official homepage instead of the terminal and install.

https://www.anaconda.com/distribution/#macos

Follow the on-screen instructions to install, but install the python3 version instead of python2. If you get lost, please refer to this page Anaconda Install

Open JupyterNoteBook and jump to the page below and you're done!

Below, the code to be implemented in the above editor

#Import of module to mural graph
import matplotlib.pyplot as plt
#Setting explanatory variables
X = [40, 50, 60, 70]
#Setting the objective variable
y = [x+110 for x in X]
#Graph mural
#Instantiation of graph
plt.figure(facecolor="w", figsize=(8, 6))
#grid(Mesh)Put in
plt.grid(True)
#Height and weight of each person
plt.scatter(X, y)
plt.scatter(55, 165, color="red")
#Pink straight line of objective function
plt.plot(X, y, color="pink")

#Graph overview
plt.xlabel("weight(kg)")
plt.ylabel("height(cm)")
plt.title("predict")
# plt.savefig("Directory path you want to save"/File name you want to save") #If you want to save the graph

Now, if you press something like the play button on the upper left, the graph should be displayed!

At the end Next notice

This time, I learned the introduction of "Learn Machine Learning", the construction of a programming execution environment, and the implementation of simple graphs. I wrote all of them that I wish I had. next time

-What is simple regression analysis I would like to write. Thank you!

Recommended Posts

The first step of machine learning ~ For those who want to implement with python ~
The first step for those who are amateurs of statistics but want to implement machine learning models in Python
For those who want to start machine learning with TensorFlow2
For those who want to write Python with vim
Python techniques for those who want to get rid of beginners
For those of you who glance at the log while learning with machine learning ~ Muscle training with LightGBM ~
Summary of the basic flow of machine learning with Python
Record of the first machine learning challenge with Keras
For those who want to learn Excel VBA and get started with Python
5 Reasons Processing is Useful for Those Who Want to Get Started with Python
Align the number of samples between classes of data for machine learning with Python
[Python] The first step to making a game with Pyxel
Environment construction for those who want to study python easily with VS Code (for Mac)
I'm an amateur on the 14th day of python, but I want to try machine learning with scikit-learn
Summary of sites and learning procedures that will be helpful for those who are trying to make games with pygame for the first time
What kind of environment should people who are learning Python for the first time build?
I want to output the beginning of the next month with Python
How to use machine learning for work? 01_ Understand the purpose of machine learning
Amplify images for machine learning with python
[Shakyo] Encounter with Python for machine learning
An introduction to Python for machine learning
A modern environment building procedure for those who want to get started with Python right away
[Short sentence] easygui for those who want to use a simple GUI with Python very easily
Take the free "Introduction to Python for Machine Learning" online until 4/27 application
A beginner of machine learning tried to predict Arima Kinen with python
Memorandum of means when you want to make machine learning with 50 images
Python learning memo for machine learning by Chainer until the end of Chapter 2
[Python] Easy introduction to machine learning with python (SVM)
The story of low learning costs for Python
Upgrade the Azure Machine Learning SDK for Python
[Python] Collect images with Icrawler for machine learning [1000 images]
100 language processing knocks for those who do not understand the meaning of problem sentences Chapter 8 Machine learning
Join Azure Using Go ~ For those who want to start and know Azure with Go ~
What you want to memorize with the basic "string manipulation" grammar of python
Note: How to get the last day of the month with python (added the first day of the month)
GTUG Girls + PyLadiesTokyo Meetup I went to machine learning for the first time
Python learning notes for machine learning with Chainer Chapters 11 and 12 Introduction to Pandas Matplotlib
[Introduction to Python] How to get the index of data with a for statement
The first algorithm to learn with Python: FizzBuzz problem
I want to inherit to the back with python dataclass
Predict the gender of Twitter users with machine learning
Preparing to start "Python machine learning programming" (for macOS)
The first step to getting Blender available from Python
Anxible points for those who want to introduce Ansible
Predicting the goal time of a full marathon with machine learning-③: Visualizing data with Python-
For those who are new to programming but have decided to analyze data with Python
I tried to build an environment for machine learning with Python (Mac OS X)
Machine learning with Python! Preparation
Beginning with Python machine learning
I tried to find the entropy of the image with python
I want to specify another version of Python with pyvenv
Try to evaluate the performance of machine learning / regression model
The result of Java engineers learning machine learning in Python www
The first API to make with python Djnago REST framework
The first step to creating a serverless application with Zappa
Try to evaluate the performance of machine learning / classification model
How to use machine learning for work? 03_Python coding procedure
[Python] I want to use the -h option with argparse
How to increase the number of machine learning dataset images
Try to automate the operation of network devices with Python
I tried to implement ListNet of rank learning with Chainer