通过插入符号包装中的预处理功能完成的Yeo Johnson变量转换的逆操作,以获取原始目标值和预测值

时间:2019-11-10 13:37:04

标签: r machine-learning analytics

我已经通过使用插入符号包中的预处理完成了Yeo Johnson转换。我已经使用线性回归预测了目标变量。现在,我想反转目标和预测值的转换。我知道这个问题之前已经回答过,但是我仍然无法解决我的问题。这个问题在这里被回答了:Revert transformation preprocess caret 和这里-: https://rdrr.io/github/jknowles/ModelEWS/src/R/exportPrep.R 对于Yeo Johnson,我无法对其进行修改。

链接到数据集-:https://drive.google.com/file/d/1MePcWhe9zghozgZ90flRMBBTH0wR-aJ0/view?usp=sharing

#Yeo Johnson transformation through preprocess in caret package

#calculating transforming parameters
normModel<-preProcess(dataset[,-c(4,39,40)], method="YeoJohnson") 
#Excluding categorical variables

#transform the dataset using the parameters
norm.dataset<-predict(normModel, dataset[,-c(4,39,40)])
norm.dataset<-cbind(dataset[,c(4,39,40)], norm.dataset)

#Paritioning the data into training and test dataset
set.seed(2000)
n=nrow(norm.dataset)
split= sample(c(TRUE, FALSE), n, replace=TRUE, prob=c(0.70, 0.30))
ptrain = norm.dataset[split, ]
ptest = norm.dataset[!split,]

#After treating outliers, imputing missing values and performing factor analysis, we perform regression

#Linear model for prediction
fmla <- as.formula(paste("Target.Variable ~ ", paste(colnames(ptrain[,-1]), collapse=" +")))
linearmod<-lm(formula = fmla, data = ptrain)
summary(linearmod)
ptest$lmPred <- predict(linearmod, ptest)

0 个答案:

没有答案