임시 모델 만들어 보기
서로 다른 거리에서 두 물체 사이의 중력을 측정한 데이터셋이 주어졌습니다. 특정 거리를 입력하면 힘을 예측하는 간단한 모델을 만들어 보세요. 처음에는 단순 선형회귀에 집중하려고 합니다. 데이터는 distance와 force의 짝 120개로 이루어져 있으며, newton 객체로 로드되어 있습니다.
이 연습은 강의의 일부입니다
R로 배우는 Feature Engineering
연습 안내
- 기본
R의 선형모형 함수를 사용해newton데이터에 대한 선형모형을 만들고lr_force에 할당하세요. - 예측 값을 원본
newton데이터에 결합해 새로운 데이터 프레임df를 만드세요. ggplot()으로force대distance산점도를 생성하세요.- 적합값을 사용해 산점도에 회귀선을 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Build a linear model for the newton the data and assign it to lr_force
lr_force <- ___(force ~ distance, data = ___)
# Create a new data frame by binding the prediction values to the original data
df <- newton %>% ___(lr_pred = predict(lr_force))
# Generate a scatterplot of force vs. distance
df %>%
ggplot(aes(x = distance, y = force)) +
geom____() +
# Add a regression line with the fitted values
geom_line(aes(y = ___), color = "blue", lwd = .75) +
ggtitle("Linear regression of force vs. distance") +
theme_classic()