如何使用 R 中的repices 包应用反双曲正弦?
我正在探索 recipes
包来为线性回归准备数据。但即使使用反双曲正弦对两个变量进行简单变换也不会产生我期望的结果。我在这里犯了什么错?
library(tidyverse)
library(recipes)
set.seed(1)
df <- tibble(
x = runif(4) * 10,
y = runif(4) * 10
)
# manual transformation
df %>%
mutate(x = asinh(x),
y = asinh(y))
#> # A tibble: 4 × 2
#> x y
#> <dbl> <dbl>
#> 1 1.70 1.45
#> 2 2.02 2.89
#> 3 2.45 2.94
#> 4 2.90 2.59
# transformation using recipes
rec_obj <- recipe(y ~ x, data = df)
rec_obj %>%
step_hyperbolic(x, y, func = "sin", inverse = TRUE) %>%
prep() %>%
bake(new_data = NULL)
#> Warning in func(getElement(new_data, col_names[i])): NaNs produced
#> Warning in func(getElement(new_data, col_names[i])): NaNs produced
#> # A tibble: 4 × 2
#> x y
#> <dbl> <dbl>
#> 1 NaN NaN
#> 2 NaN NaN
#> 3 NaN NaN
#> 4 NaN NaN
由 reprex 软件包 (v2.0.1) 创建于 2022 年 3 月 1 日
I am exploring the recipes
package to prepare my data for linear regression. But even a simple transformation of two variables using inverse hyperbolic sine does not yield the results I am expecting. What am I getting wrong here?
library(tidyverse)
library(recipes)
set.seed(1)
df <- tibble(
x = runif(4) * 10,
y = runif(4) * 10
)
# manual transformation
df %>%
mutate(x = asinh(x),
y = asinh(y))
#> # A tibble: 4 × 2
#> x y
#> <dbl> <dbl>
#> 1 1.70 1.45
#> 2 2.02 2.89
#> 3 2.45 2.94
#> 4 2.90 2.59
# transformation using recipes
rec_obj <- recipe(y ~ x, data = df)
rec_obj %>%
step_hyperbolic(x, y, func = "sin", inverse = TRUE) %>%
prep() %>%
bake(new_data = NULL)
#> Warning in func(getElement(new_data, col_names[i])): NaNs produced
#> Warning in func(getElement(new_data, col_names[i])): NaNs produced
#> # A tibble: 4 × 2
#> x y
#> <dbl> <dbl>
#> 1 NaN NaN
#> 2 NaN NaN
#> 3 NaN NaN
#> 4 NaN NaN
Created on 2022-03-01 by the reprex package (v2.0.1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论