試作モデル
2つの物体間の距離ごとに測定した重力のデータセットが与えられ、特定の距離から力を予測するシンプルなモデルを構築する課題です。まずは単回帰(線形回帰)で試してみたいと考えています。データは distance と force の120組からなり、newton として読み込まれています。
この演習はコースの一部です
Rで学ぶ特徴量エンジニアリング
演習の手順
- ベース
Rの線形モデル関数を使ってnewtonデータに対する線形モデルを構築し、lr_forceに代入します。 - 予測値を元の
newtonデータに結合して、新しいデータフレームdfを作成します。 ggplot()を使って、distanceに対するforceの散布図を作成します。- 散布図に当てはめ値を用いた回帰直線を追加します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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()