iris 데이터프레임에서 petal.width로 petal.length를 예측하는 선형회귀모형

네이버 지식인에서 나온 질문 이다.  



R프로그래밍 질문입니다.

iris 데이터프레임에서 petal.width로 petal.length를 예측하는 선형회귀모형은 어떻게 만드나요..?

산점도는 또 어떤 식으로 해야하는지 궁금합니다!



아래와 같이 정리 하였다. 
# 선형회귀 분석
fit <- lm(Petal.Length ~ Petal.Width, data = iris)

# fitting 화 결과
fit
## 
## Call:
## lm(formula = Petal.Length ~ Petal.Width, data = iris)
## 
## Coefficients:
## (Intercept)  Petal.Width  
##       1.084        2.230
# fitting 요약 
summary(fit)
## 
## Call:
## lm(formula = Petal.Length ~ Petal.Width, data = iris)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.33542 -0.30347 -0.02955  0.25776  1.39453 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.08356    0.07297   14.85   <2e-16 ***
## Petal.Width  2.22994    0.05140   43.39   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4782 on 148 degrees of freedom
## Multiple R-squared:  0.9271, Adjusted R-squared:  0.9266 
## F-statistic:  1882 on 1 and 148 DF,  p-value: < 2.2e-16
# ggplot 으로 그래프 그리기
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

iris %>% 
  ggplot(aes(Petal.Width, Petal.Length)) +
  geom_point() +
  geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'


petal.length를 예측 한다면, petal.length가 종속 변수 입니다. petal.width는 독립 변수 이다. 즉 독립 변수가지고 종속 변수를 예측 한다. 


그리고,  ggplot 으로 산점도를 그릴 수 있고,   geom_smoth를 그리면 예측 곡선도 같이 그린다. 



댓글 없음:

댓글 쓰기

[주식 클로드 자동매매 프로젝트] 제2편. 데이터 인프라 구축 — 모델보다 데이터가 먼저다

 머신러닝 모델을 이야기하기 전에, 그 모델이 먹는 데이터가 어디서 어떻게 왔는지부터 정직하게 밝혀야 한다. 이 프로젝트에서 가장 많은 시간이 들어간 부분은 화려한 모델 튜닝이 아니라, "내가 정말 그 데이터를 갖고 있는가"를 확인하...