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.
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
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