Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Reverse of Yeo Johnson variable transformation done by preprocess function in caret package to get original Target and predicted values

$
0
0

I have done a Yeo Johnson transformation by using preprocess from caret package. I have predicted the Target Variable using linear regression. Now I want to reverse the transformation for both the Target and the predicted values. I know this question has been answered before but I still couldn't solve my problem. This question was answered here-: Revert transformation preprocess caret and here-: https://rdrr.io/github/jknowles/ModelEWS/src/R/exportPrep.R I couldn't modify it for Yeo Johnson.

Link to dataset-: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)

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>