開始使用免費開始

對多個模型進行對映

你在工作空間可使用的 gap_nested 資料框,包含依國家巢狀化的 gapminder 資料集。

你將用這個資料,為每個國家建立一個線性模型,使用 year 特徵來預測 life expectancy

注意:feature(特徵)」與「variable(變數)」或「predictor(預測因子)」同義。它指的是資料中的一個屬性,可用來建立機器學習模型。

本練習屬於課程

Tidyverse 的 Machine Learning

檢視課程

練習說明

  • 為每個國家建立一個線性模型,使用 year 特徵來預測 life_expectancy。請使用 lm(),並將包含模型的新資料框儲存為 gap_models
  • 從這個資料框中擷取第一個模型,並將其儲存為 algeria_model
  • 使用 summary() 檢視該模型的資訊。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Build a linear model for each country
gap_models <- gap_nested %>%
    mutate(model = map(___, ~lm(formula = life_expectancy~year, data = ___)))
    
# Extract the model for Algeria    
algeria_model <- gap_models$model[[___]]

# View the summary for the Algeria model
summary(___)
編輯並執行程式碼