AI14 - MachineLearning
AI14 - MachineLearning
Basic
Concepts of
Machine Learning
Table of contents
• 14.1 Introduction
• 14.2 Linear regression
• 14.3 k-NN algorithm
• 14.4 Overfitting and
underfitting
14.1 Introduction
Go has many
game rules.
Apply machine
learning
Classification
Introduction
Labeling
cat
• Regression is the problem of finding the straight line or curve that best describes
the data, usually after plotting the data in a multidimensional space.
• In other words, predicting the function 𝑓(𝑥) while looking at the input 𝑥 and the
output 𝑦 at 𝑦=𝑓(𝑥) is called a regression technique.
Linear regression
• Scikit-learn
• If we could create a formula to quantify the correlation between height and weight, we
?
would be able to estimate the weight of student A, whose weight is unknown.
Linear regression
Let's implement linear regression with the Scikit-Learn library
• Four students were randomly extracted to measure the height and weight, and
the height was 164, 179, 162, and 170 cm, and their weight was 53, 63, 55, and
59 kg, respectively.
Height
weight
Linear regression
Let's implement linear regression with the Scikit-Learn library
Caution: Input value is a person’s height, 164, 179, 162, 170, respectively.
-> The input of linear regression must be used to use a multi-dimensional array.
Target value
Now, for students with a height of 180 or 185, I would like to find out
how the Regrin Linear Return model we created predicts weight.
To do this, prepare the input data.
180 63.71
regr.predict()
185 66.47
Question: Use a linear regression model to predict the weights of [166, 0] and [170, 1]?
I am a I am a
woman (1) man (0)
This data includes data used as an input, targets used as a result of learning, and
feature_names that store the names of the input features.
Linear regression
• Extract only one third item corresponding to the body mass index bmi out of 10 features
• The data used as the input of the function must be a two-dimensional array.
We will just extract only bmi data and use it as an input of linear regression.
Linear regression
Diabetes examples: What is the correlation between the body mass index and the
diabetes level?
train_test_split()
X_train X_test
y_train y_test
Final performance
evaluation
linear
regression Model Accuracy
learning
regr.fit() regr.predict()
Linear regression
Diabetes examples:
Separate the diabetes example into training and test data
• Only 80%of the total 442 are used for learning (or training)
• Using the remaining 20%for testing
Diabetes examples: Use all the features in the dataset for linear regression
Linear regression
Diabetes examples: Use all the features in the dataset for linear regression
predicted
value
actual value
Linear regression
There are various methods of calculating the error between y_pred and y_test.
One of them is Mean squared error(MSE):
N
1
MSE =
N
(H ( X ) − y )
i =1
i i
Samoyed dog
Height
Dachsund dog
Length
• The Samoyed has a high height value compared to its length, and the lower
Dachshund has a low height value compared to its length.
k-NN algorithm
If you classify by looking at 3
Class A of the number of nearest neig
hbors, you belong to class B,
but if you classify by looking
at 5, you belong to class A.
Class B
sepal length
petal length
sepal width
petal width
Setosa : 0
Versicolor : 1
Virginica: 2.
k-NN algorithm
Setosa : 0
Versicolor : 1
Virginica: 2.
k-NN algorithm