一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

prep, bake, juice三步說(shuō)的真清楚

 醫(yī)學(xué)數(shù)據(jù)科學(xué) 2021-04-26

Let's walk through what each of these functions does. First, let's define a recipe with a couple of steps. Notice that the data going into the recipe is the training data.

library(recipes)

cars_train <- mtcars[1:20,]
cars_test <- mtcars[21:32,]

cars_rec <- recipe(mpg ~ ., data = cars_train) %>%
  step_log(disp) %>%
  step_center(all_predictors())
cars_rec#> Data Recipe#> #> Inputs:#> #>       role #variables#>    outcome          1#>  predictor         10#> #> Operations:#> #> Log transformation on disp#> Centering for all_predictors

The preprocessing recipe cars_rec has been defined but no values have been estimated. For example, the log has not been taken for disp, and the mean has not been calculated for predictors so that they can be centered.

The prep() function takes that defined object and computes everything so that the preprocessing steps can be executed. For example, the mean of each predictor is calculated in this example so the predictors can be centered. This is done with the training data.

cars_prep <- prep(cars_rec)
cars_prep#> Data Recipe#> #> Inputs:#> #>       role #variables#>    outcome          1#>  predictor         10#> #> Training data contained 20 data points and no missing data.#> #> Operations:#> #> Log transformation on disp [trained]#> Centering for cyl, disp, hp, drat, wt, qsec, vs, am, ... [trained]

Notice that before, with the unprepped recipe, it just said Centering for all_predictors because it had not been evaluated yet. Now it has been evaluated and we know which columns are predictors and what their means are.

The bake() and juice() functions both return data, not a preprocessing recipe object. The bake() function takes a prepped recipe (one that has had all quantities estimated from training data) and applies it to new_data. That new_data could be the training data again...

bake(cars_prep, new_data = cars_train)#> # A tibble: 20 x 11#>      cyl   disp    hp   drat      wt   qsec    vs    am  gear   carb   mpg#>    <dbl>  <dbl> <dbl>  <dbl>   <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>#>  1  -0.2 -0.222 -26.2  0.355 -0.778  -1.98   -0.5   0.7   0.5  1.30   21  #>  2  -0.2 -0.222 -26.2  0.355 -0.523  -1.42   -0.5   0.7   0.5  1.30   21  #>  3  -2.2 -0.615 -43.2  0.305 -1.08    0.169   0.5   0.7   0.5 -1.7    22.8#>  4  -0.2  0.256 -26.2 -0.465 -0.183   0.999   0.5  -0.3  -0.5 -1.7    21.4#>  5   1.8  0.589  38.8 -0.395  0.0415 -1.42   -0.5  -0.3  -0.5 -0.7    18.7#>  6  -0.2  0.119 -31.2 -0.785  0.0615  1.78    0.5  -0.3  -0.5 -1.7    18.1#>  7   1.8  0.589 109.  -0.335  0.172  -2.60   -0.5  -0.3  -0.5  1.30   14.3#>  8  -2.2 -0.309 -74.2  0.145 -0.208   1.56    0.5  -0.3   0.5 -0.7    24.4#>  9  -2.2 -0.350 -41.2  0.375 -0.248   4.46    0.5  -0.3   0.5 -0.7    22.8#> 10  -0.2 -0.176 -13.2  0.375  0.0415 -0.141   0.5  -0.3   0.5  1.30   19.2#> 11  -0.2 -0.176 -13.2  0.375  0.0415  0.459   0.5  -0.3   0.5  1.30   17.8#> 12   1.8  0.323  43.8 -0.475  0.672  -1.04   -0.5  -0.3  -0.5  0.300  16.4#> 13   1.8  0.323  43.8 -0.475  0.332  -0.841  -0.5  -0.3  -0.5  0.300  17.3#> 14   1.8  0.323  43.8 -0.475  0.382  -0.441  -0.5  -0.3  -0.5  0.300  15.2#> 15   1.8  0.860  68.8 -0.615  1.85   -0.461  -0.5  -0.3  -0.5  1.30   10.4#> 16   1.8  0.834  78.8 -0.545  2.03   -0.621  -0.5  -0.3  -0.5  1.30   10.4#> 17   1.8  0.790  93.8 -0.315  1.95   -1.02   -0.5  -0.3  -0.5  1.30   14.7#> 18  -2.2 -0.932 -70.2  0.535 -1.20    1.03    0.5   0.7   0.5 -1.7    32.4#> 19  -2.2 -0.970 -84.2  1.38  -1.78    0.079   0.5   0.7   0.5 -0.7    30.4#> 20  -2.2 -1.03  -71.2  0.675 -1.56    1.46    0.5   0.7   0.5 -1.7    33.9

Or it could be the testing data. In this case, the column means from the training data are applied to the testing data, because that is what happens IRL in a modeling workflow. To do otherwise is data leakage.

bake(cars_prep, new_data = cars_test)#> # A tibble: 12 x 11#>      cyl   disp    hp     drat      wt   qsec    vs    am  gear  carb   mpg#>    <dbl>  <dbl> <dbl>    <dbl>   <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>#>  1  -2.2 -0.509 -39.2  0.155   -0.933   1.57    0.5  -0.3  -0.5 -1.7   21.5#>  2   1.8  0.465  13.8 -0.785    0.122  -1.57   -0.5  -0.3  -0.5 -0.7   15.5#>  3   1.8  0.420  13.8 -0.395    0.0366 -1.14   -0.5  -0.3  -0.5 -0.7   15.2#>  4   1.8  0.561 109.   0.185    0.442  -3.03   -0.5  -0.3  -0.5  1.30  13.3#>  5   1.8  0.694  38.8 -0.465    0.447  -1.39   -0.5  -0.3  -0.5 -0.7   19.2#>  6  -2.2 -0.928 -70.2  0.535   -1.46    0.459   0.5   0.7   0.5 -1.7   27.3#>  7  -2.2 -0.507 -45.2  0.885   -1.26   -1.74   -0.5   0.7   1.5 -0.7   26  #>  8  -2.2 -0.742 -23.2  0.225   -1.89   -1.54    0.5   0.7   1.5 -0.7   30.4#>  9   1.8  0.564 128.   0.675   -0.228  -3.94   -0.5   0.7   1.5  1.30  15.8#> 10  -0.2 -0.320  38.8  0.075   -0.628  -2.94   -0.5   0.7   1.5  3.3   19.7#> 11   1.8  0.410 199.  -0.00500  0.172  -3.84   -0.5   0.7   1.5  5.3   15  #> 12  -2.2 -0.501 -27.2  0.565   -0.618   0.159   0.5   0.7   0.5 -0.7   21.4

The juice() function is a nice little shortcut. Because the prepped recipe was estimated from the training data, you can process the training data only from it. Picture yourself squeezing the prepped recipe to get the training data back out that you used to estimate the preprocessing parameters with to start with.

juice(cars_prep)#> # A tibble: 20 x 11#>      cyl   disp    hp   drat      wt   qsec    vs    am  gear   carb   mpg#>    <dbl>  <dbl> <dbl>  <dbl>   <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>#>  1  -0.2 -0.222 -26.2  0.355 -0.778  -1.98   -0.5   0.7   0.5  1.30   21  #>  2  -0.2 -0.222 -26.2  0.355 -0.523  -1.42   -0.5   0.7   0.5  1.30   21  #>  3  -2.2 -0.615 -43.2  0.305 -1.08    0.169   0.5   0.7   0.5 -1.7    22.8#>  4  -0.2  0.256 -26.2 -0.465 -0.183   0.999   0.5  -0.3  -0.5 -1.7    21.4#>  5   1.8  0.589  38.8 -0.395  0.0415 -1.42   -0.5  -0.3  -0.5 -0.7    18.7#>  6  -0.2  0.119 -31.2 -0.785  0.0615  1.78    0.5  -0.3  -0.5 -1.7    18.1#>  7   1.8  0.589 109.  -0.335  0.172  -2.60   -0.5  -0.3  -0.5  1.30   14.3#>  8  -2.2 -0.309 -74.2  0.145 -0.208   1.56    0.5  -0.3   0.5 -0.7    24.4#>  9  -2.2 -0.350 -41.2  0.375 -0.248   4.46    0.5  -0.3   0.5 -0.7    22.8#> 10  -0.2 -0.176 -13.2  0.375  0.0415 -0.141   0.5  -0.3   0.5  1.30   19.2#> 11  -0.2 -0.176 -13.2  0.375  0.0415  0.459   0.5  -0.3   0.5  1.30   17.8#> 12   1.8  0.323  43.8 -0.475  0.672  -1.04   -0.5  -0.3  -0.5  0.300  16.4#> 13   1.8  0.323  43.8 -0.475  0.332  -0.841  -0.5  -0.3  -0.5  0.300  17.3#> 14   1.8  0.323  43.8 -0.475  0.382  -0.441  -0.5  -0.3  -0.5  0.300  15.2#> 15   1.8  0.860  68.8 -0.615  1.85   -0.461  -0.5  -0.3  -0.5  1.30   10.4#> 16   1.8  0.834  78.8 -0.545  2.03   -0.621  -0.5  -0.3  -0.5  1.30   10.4#> 17   1.8  0.790  93.8 -0.315  1.95   -1.02   -0.5  -0.3  -0.5  1.30   14.7#> 18  -2.2 -0.932 -70.2  0.535 -1.20    1.03    0.5   0.7   0.5 -1.7    32.4#> 19  -2.2 -0.970 -84.2  1.38  -1.78    0.079   0.5   0.7   0.5 -0.7    30.4#> 20  -2.2 -1.03  -71.2  0.675 -1.56    1.46    0.5   0.7   0.5 -1.7    33.9

Created on 2020-06-04 by the reprex package (v0.3.0)

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    国产中文另类天堂二区| 久久精品中文字幕人妻中文 | 夫妻性生活真人动作视频| 青青操视频在线播放免费| 91插插插外国一区二区婷婷| 国产黑人一区二区三区| 好吊日在线视频免费观看| 亚洲欧美视频欧美视频| 日本人妻熟女一区二区三区| 欧美小黄片在线一级观看| 久草国产精品一区二区| 国产又长又粗又爽免费视频| 亚洲人妻av中文字幕| 精品欧美日韩一区二区三区| 我的性感妹妹在线观看| 98精品永久免费视频| 扒开腿狂躁女人爽出白浆av| 国产成人精品一区二三区在线观看| 麻豆欧美精品国产综合久久| 亚洲女同一区二区另类| 国产传媒精品视频一区| 日韩一区二区三区嘿嘿| 日韩精品一区二区不卡| 日本女优一区二区三区免费| 国内胖女人做爰视频有没有| 亚洲精品一区二区三区免| 色综合久久六月婷婷中文字幕| 欧美亚洲三级视频在线观看| 欧美日韩一区二区午夜| 久热在线视频这里只有精品| 欧美精品一区二区三区白虎| 视频一区日韩经典中文字幕| 五月天丁香婷婷狠狠爱| 国产精品午夜福利免费阅读| 亚洲内射人妻一区二区| 日本视频在线观看不卡| 日本午夜精品视频在线观看| 一级片二级片欧美日韩| 免费国产成人性生活生活片| 精品国产亚洲区久久露脸| 亚洲一区二区三区有码|