mold()
應用將訓練數據輸入模型所需的適當處理步驟。它通過使用各種藍圖來實現這一點,這些藍圖了解如何預處理各種形式的數據,例如公式或配方。
所有藍圖都具有與其他藍圖一致的返回值,但每個藍圖都足夠獨特,有自己的幫助頁麵。單擊下麵了解如何將每一個與 mold()
結合使用。
-
XY 方法 -
default_xy_blueprint()
-
公式方法 -
default_formula_blueprint()
-
食譜方法 -
default_recipe_blueprint()
值
包含 4 個元素的命名列表:
-
predictors
:包含要在模型中使用的模製預測變量的 tibble。 -
outcome
:包含模型中使用的成型結果的標題。 -
blueprint
:進行預測時使用的特定於方法的"hardhat_blueprint"
對象。 -
extras
:如果藍圖不返回額外信息,則為NULL
,或者包含額外信息的命名列表。
例子
# See the method specific documentation linked in Description
# for the details of each blueprint, and more examples.
# XY
mold(iris["Sepal.Width"], iris$Species)
#> $predictors
#> # A tibble: 150 × 1
#> Sepal.Width
#> <dbl>
#> 1 3.5
#> 2 3
#> 3 3.2
#> 4 3.1
#> 5 3.6
#> 6 3.9
#> 7 3.4
#> 8 3.4
#> 9 2.9
#> 10 3.1
#> # ℹ 140 more rows
#>
#> $outcomes
#> # A tibble: 150 × 1
#> .outcome
#> <fct>
#> 1 setosa
#> 2 setosa
#> 3 setosa
#> 4 setosa
#> 5 setosa
#> 6 setosa
#> 7 setosa
#> 8 setosa
#> 9 setosa
#> 10 setosa
#> # ℹ 140 more rows
#>
#> $blueprint
#> XY blueprint:
#>
#> # Predictors: 1
#> # Outcomes: 1
#> Intercept: FALSE
#> Novel Levels: FALSE
#> Composition: tibble
#>
#> $extras
#> NULL
#>
# Formula
mold(Species ~ Sepal.Width, iris)
#> $predictors
#> # A tibble: 150 × 1
#> Sepal.Width
#> <dbl>
#> 1 3.5
#> 2 3
#> 3 3.2
#> 4 3.1
#> 5 3.6
#> 6 3.9
#> 7 3.4
#> 8 3.4
#> 9 2.9
#> 10 3.1
#> # ℹ 140 more rows
#>
#> $outcomes
#> # A tibble: 150 × 1
#> Species
#> <fct>
#> 1 setosa
#> 2 setosa
#> 3 setosa
#> 4 setosa
#> 5 setosa
#> 6 setosa
#> 7 setosa
#> 8 setosa
#> 9 setosa
#> 10 setosa
#> # ℹ 140 more rows
#>
#> $blueprint
#> Formula blueprint:
#>
#> # Predictors: 1
#> # Outcomes: 1
#> Intercept: FALSE
#> Novel Levels: FALSE
#> Composition: tibble
#> Indicators: traditional
#>
#> $extras
#> $extras$offset
#> NULL
#>
#>
# Recipe
library(recipes)
mold(recipe(Species ~ Sepal.Width, iris), iris)
#> $predictors
#> # A tibble: 150 × 1
#> Sepal.Width
#> <dbl>
#> 1 3.5
#> 2 3
#> 3 3.2
#> 4 3.1
#> 5 3.6
#> 6 3.9
#> 7 3.4
#> 8 3.4
#> 9 2.9
#> 10 3.1
#> # ℹ 140 more rows
#>
#> $outcomes
#> # A tibble: 150 × 1
#> Species
#> <fct>
#> 1 setosa
#> 2 setosa
#> 3 setosa
#> 4 setosa
#> 5 setosa
#> 6 setosa
#> 7 setosa
#> 8 setosa
#> 9 setosa
#> 10 setosa
#> # ℹ 140 more rows
#>
#> $blueprint
#> Recipe blueprint:
#>
#> # Predictors: 1
#> # Outcomes: 1
#> Intercept: FALSE
#> Novel Levels: FALSE
#> Composition: tibble
#>
#> $extras
#> $extras$roles
#> NULL
#>
#>
相關用法
- R hardhat model_offset 提取模型偏移
- R hardhat model_matrix 構建設計矩陣
- R hardhat model_frame 構建模型框架
- R hardhat validate_prediction_size 確保預測具有正確的行數
- R hardhat default_recipe_blueprint 默認配方藍圖
- R hardhat is_blueprint x 是預處理藍圖嗎?
- R hardhat validate_column_names 確保數據包含所需的列名
- R hardhat default_formula_blueprint 默認公式藍圖
- R hardhat update_blueprint 更新預處理藍圖
- R hardhat weighted_table 加權表
- R hardhat validate_outcomes_are_univariate 確保結果是單變量
- R hardhat get_levels 從 DataFrame 中提取因子水平
- R hardhat add_intercept_column 向數據添加截距列
- R hardhat is_frequency_weights x 是頻率權重向量嗎?
- R hardhat standardize 標準化結果
- R hardhat is_importance_weights x 是重要性權重向量嗎?
- R hardhat run-mold 根據藍圖 Mold()
- R hardhat get_data_classes 從 DataFrame 或矩陣中提取數據類
- R hardhat fct_encode_one_hot 將一個因子編碼為 one-hot 指標矩陣
- R hardhat new_frequency_weights 構建頻率權重向量
- R hardhat validate_no_formula_duplication 確保公式中不出現重複項
- R hardhat default_xy_blueprint 默認 XY 藍圖
- R hardhat shrink 僅對所需列進行子集化
- R hardhat validate_outcomes_are_numeric 確保結果都是數字
- R hardhat scream ? 尖叫。
注:本文由純淨天空篩選整理自Davis Vaughan等大神的英文原創作品 Mold data for modeling。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。