BestNormalize给人误解的结果?

问题描述 投票:0回答:1

我想知道为什么每次运行此代码都会得到不同的结果:

# arcsinh transformation
(arcsinh_obj <- arcsinh_x(df$Var1))
# Box Cox's Transformation
(boxcox_obj <- boxcox(df$Var1))
# Yeo-Johnson's Transformation
(yeojohnson_obj <- yeojohnson(df$Var1))
# orderNorm Transformation
(orderNorm_obj <- orderNorm(df$Var1))
# Pick the best one automatically
(BNobject <- bestNormalize(df$Var1))
# Last resort - binarize
(binarize_obj <- binarize(df$Var1))

summary(df$Var1)
xx <- seq(min(12), max(56), length = 295)

plot(xx, predict(arcsinh_obj, newdata = xx), type = "l", col = 1, ylim = c(-4, 4),
     xlab = 'df$Var1', ylab = "g(df$Var1)")
lines(xx, predict(boxcox_obj, newdata = xx), col = 2)
lines(xx, predict(yeojohnson_obj, newdata = xx), col = 3)
lines(xx, predict(orderNorm_obj, newdata = xx), col = 4)

legend("bottomright", legend = c("arcsinh", "Box Cox", "Yeo-Johnson", "OrderNorm"), 
       col = 1:4, lty = 1, bty = 'n')

par(mfrow = c(2,2))
MASS::truehist(arcsinh_obj$x.t, main = "Arcsinh transformation", nbins = 100)
MASS::truehist(boxcox_obj$x.t, main = "Box Cox transformation", nbins = 100)
MASS::truehist(yeojohnson_obj$x.t, main = "Yeo-Johnson transformation", nbins = 100)
MASS::truehist(orderNorm_obj$x.t, main = "orderNorm transformation", nbins = 100)

par(mfrow = c(1,2))
MASS::truehist(BNobject$x.t, 
               main = paste("Best Transformation:", 
                            class(BNobject$chosen_transform)[1]), nbins = 100)
plot(xx, predict(BNobject, newdata = xx), type = "l", col = 1, 
     main = "Best Normalizing transformation", ylab = "g(x)", xlab = "x")

dev.off()
boxplot(log10(BNobject$oos_preds), yaxt = 'n')
axis(2, at=log10(c(.1,.5, 1, 2, 5, 10)), labels=c(.1,.5, 1, 2, 5, 10))

[我甚至在每次重新运行分析时都尝试过此操作,以防他实际上影响了

 rm(list = ls())

您能帮我一下吗?

谢谢lil

variables normalization predict
1个回答
0
投票

您可能会得到不同的结果,因为bestNormalize()函数使用了重复的交叉验证(并且不会自动设置种子),因此每次运行时结果都会略有不同。

尝试设置种子(例如set.seed(3))。

或者,您可以通过设置out_of_sample = FALSE来告诉该功能不要执行重复的CV,或者通过设置loo = TRUE来使用留一式CV。

© www.soinside.com 2019 - 2024. All rights reserved.