I tried to understand supervised learning of machine learning in an easy-to-understand manner even for server engineers 1

What is Supervised Learning?

For example, predict your annual income. As a result, it is an AI that can judge whether it is 5 million or more or less.

I'll get some information to make a prediction. Let's do the following this time

--Age --Education date ――How long do you work (week) -Is it over 5 million?

I expect these conditions. There are various ways to predict, but this time

Let's use a prediction method called logistic regression </ b>. Logistic regression is a predictable mechanism for classifying classes.

Let's draw it in python

//Argument description
////C Change the accuracy (the larger the number, the more detailed the answer is calculated)
////max_iter maximum number of iterations(Specify the maximum value so as not to calculate too much and increase the number of loops)
////random_state Isn't it exactly what you expected, with or without random numbers? Use when you feel something like (the same value is returned if it is an integer)
lr = LogisticRegression(C=1000.0, max_iter=100, random_state=0)
lr.fit("age,Education period,Matrix data of working hours"), column_or_1d("Evaluation line"))

For example, suppose you have data like this

age Country Education period working time Income over 500
30 JPN 12 40 0
15 USA 9 80 1
26 JPN 9 40 0
65 JPN 9 40 1

The original data is now complete.

Feed the data. And make a prediction

train_pred = lr.predict("age,Education period,Matrix data of working hours")

//score is precision.
lr.score("age,Education period,Matrix data of working hours",column_or_1d("Evaluation line"))

So in this case, if the score exceeds 1, it means that it exceeds 5 million. To check individual values, set the following values As an example) 30 years old, educational institution: 16 years, 40 hours a week

yhat = lr.predict(np.array([[30, 16, 40]]))[0]

print( yhat)
print('Your annual income is 5 million' + ('It is less than' if yhat == 0 else 'that's all'))

That's the answer that machine learning has come up with.

In summary

To summarize the flow

--I'll use logistic regression --fit --Get a score, see what kind of results are returned, and check --Get what the desired value will be with predict

Will be

Afterword

The purpose of this time was to try machine learning for the time being. If you know this, then you will naturally go to the place where you want to improve the accuracy. think. I would like to write it in another article.

I haven't touched on detailed grammar this time, so I think it will be another article (if you feel like it).

Recommended Posts

I tried to understand supervised learning of machine learning in an easy-to-understand manner even for server engineers 1
I tried to understand supervised learning of machine learning in an easy-to-understand manner even for server engineers 2
[For beginners] I want to explain the number of learning times in an easy-to-understand manner.
[Python] I tried to explain words that are difficult for beginners to understand in an easy-to-understand manner.
[Deep Learning from scratch] I tried to explain the gradient confirmation in an easy-to-understand manner.
[Python] I tried to summarize the set type (set) in an easy-to-understand manner.
An introductory reader of machine learning theory for IT engineers tried Kaggle
I tried to summarize Cpaw Level1 & Level2 Write Up in an easy-to-understand manner
I tried to summarize Cpaw Level 3 Write Up in an easy-to-understand manner
I tried to display the analysis result of the natural language processing library GiNZA in an easy-to-understand manner
Introduction to Deep Learning (1) --Chainer is explained in an easy-to-understand manner for beginners-
I tried to predict the change in snowfall for 2 years by machine learning
I tried to build an environment for machine learning with Python (Mac OS X)
[Machine learning] Let's summarize random forest in an easy-to-understand manner
[Machine learning] I tried to summarize the theory of Adaboost
I tried to understand it carefully while implementing the algorithm Adaboost in machine learning (+ I deepened my understanding of array calculation)
I tried to make an analysis base of 5 patterns in 3 years
How to use machine learning for work? 01_ Understand the purpose of machine learning
I will explain how to use Pandas in an easy-to-understand manner.
[Machine learning] I tried to do something like passing an image
An introduction to OpenCV for machine learning
An introduction to Python for machine learning
I tried to classify guitar chords in real time using machine learning
(Machine learning) I tried to understand Bayesian linear regression carefully with implementation.
(Machine learning) I tried to understand the EM algorithm in a mixed Gaussian distribution carefully with implementation.
I tried to understand the learning function in the neural network carefully without using the machine learning library (second half).
An introduction to machine learning for bot developers
[For beginners] Introduction to vectorization in machine learning
I tried to organize the evaluation indexes used in machine learning (regression model)
[Azure] I tried to create a Linux virtual machine in Azure of Microsoft Learn
I tried to predict the presence or absence of snow by machine learning.
I tried to implement various methods for machine learning (prediction model) using scikit-learn.
I tried to process and transform the image and expand the data for machine learning
I want to do machine learning even without a server --Time Series Edition -
I tried to understand the learning function of neural networks carefully without using a machine learning library (first half).
I tried to explain how to get the article content with MediaWiki API in an easy-to-understand manner with examples (Python 3)
I tried to move machine learning (ObjectDetection) with TouchDesigner
[Linux] I learned LPIC lv1 in 10 days and tried to understand the mechanism of Linux.
Build an interactive environment for machine learning in Python
I tried to compress the image using machine learning
Since I touched Tensorflow for 2 months, I explained the convolutional neural network in an easy-to-understand manner with 95.04% of "handwritten hiragana" identification.
I tried to compare the accuracy of machine learning models using kaggle as a theme.
Matching app I tried to take statistics of strong people & tried to create a machine learning model
I tried to verify the yin and yang classification of Hololive members by machine learning
The result of Java engineers learning machine learning in Python www
I tried using Tensorboard, a visualization tool for machine learning
I tried machine learning to convert sentences into XX style
I tried to implement ListNet of rank learning with Chainer
I tried to implement blackjack of card game in Python
I tried to create an article in Wiki.js with SQLAlchemy
An introduction to machine learning
[Machine learning] Understand from mathematics that standardization results in an average of 0 and a standard deviation of 1.
I tried to make Othello AI with tensorflow without understanding the theory of machine learning ~ Introduction ~
I tried HR Tech to develop an expert search engine by machine learning in-house meeting information
I tried to make Othello AI with tensorflow without understanding the theory of machine learning ~ Implementation ~
I tried to create an environment of MkDocs on Amazon Linux
Note that I understand the algorithm of the machine learning naive Bayes classifier. And I wrote it in Python.
I tried machine learning with liblinear
I wrote a book that allows you to learn machine learning implementations and algorithms in a well-balanced manner.
I tried to make Othello AI with tensorflow without understanding the theory of machine learning ~ Battle Edition ~
I tried calling the prediction API of the machine learning model from WordPress