Last Updated on November 18, 2021 by shibatau
I’m rewriting an old post now.
I. What do we learn?
We will learn Linear Regression using Python and R. It should make it clear for us to understand the difference between Machine Learning and traditional Statistics.
II. Linear regression with Python
Refer to: What is linear regression? A quick cover with a tutorial
Not completed yet.
III. Linear regression with R
Refer to: A quick introduction to machine learning in R with caret
Click on Run
library(ggplot2)
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point()
Training the data.
library(ggplot2)
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point()
# build model using train()
library(caret)
model.mtcars_lm <- train(mpg ~ wt
,data = mtcars
,method = "lm"
)
# Retrieve coefficients for - slope and - intercept
coef.icept <- coef(model.mtcars_lm$finalModel)[1]
coef.slope <- coef(model.mtcars_lm$finalModel)[2]
# Plot scatterplot and regression line using ggplot()
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point() +
geom_abline(slope = coef.slope, intercept = coef.icept, color = "red")
Creating a linear regression line without carot using ggplot2.
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(shape=1) + geom_smooth(method = lm)
データの分布を直線で表現するのは、統計学では線形回帰分析と呼ばれます。
線形回帰分析について詳しくは次のリンクを参照してください。
Linear Regression for Machine Learning
IV. Machine Learning and Statistics
Refer to: Machine Learning vs. Statistics
Not completed yet.