0

I have issue while predicting the forecast using Multiple Regression-GAM in R. Objective is to predict the forecast of a dependent variable using various independent variables and dummy variables and I have around more than 2 years data which i am splitting between Testing and Training Data. But while predicting the dependent variable, it forecasts in negative, which is wrong. None of the data given as input both, dependent and independent variable have negative values. Dependent variable (being forecasted) is generally a small value mostly between 0 to 25. Where as few of the independent variables being used as factors are as low as 0-20 and few are in millions.

Can somebody help me on this? What is the issue and how can it be rectified? Thanks in advance.

@Oliver - Code which i have been using:

setwd("C:/Users/11th Aug")
ImpZs <- read.table("Train2.csv",sep=",",quote="\"",header=TRUE)
ImpZs <- ImpZs[complete.cases(ImpZs),]
PredZs <- read.table("Test2.csv",sep=",",quote="\"",header=TRUE)
library(base)
Zs <- unique(ImpZs$Z)
attach(PredZs)
attach(ImpZs)
ZsPred <- unique(PredZs$Z)
length(ZsPred)
bP <- 1
PGW2 <- data.frame(cbind(bP,1))
GResults1 <- data.frame(cbind(b,summary(GAM)$adj.r.squared,Accur))
Predict <- Accuracy
for (i in 1:length(Zs)){ 
  b <- Zs[i]
  temp <- ImpZs[ImpZs$Z==Zs[i],]
  temp <- temp[complete.cases(temp),]
  attach(temp)
  GAM <- lm(X~ns(TU,df=10)+ns(OU,df=10)+ ns(TPO,df=9)+ ns(OPO,df=9)+ ns(XT,df=5)+ V + Oct + Nov+ Dec +Jan+Feb + Mar +Apr+May+June+July+ Aug+ Sep+ WK1+ WK2 +WK3 +WK4+WK5+Year)
  Accuracy <- data.frame(cbind(b,round(GAM$fitted,digits=1),X, Week))
  Predict <- rbind(Predict,Accuracy)
  Accur <- round((1-(sum(abs((round((GAM$fitted),digits=0))-(X))))/sum(X)),digits=2)
  t1 <- data.frame(cbind(b,summary(GAM)$adj.r.squared,Accur))
  GResults1 <- rbind(GResults1,t1)
  predP <- PredZs[PredZs$Z==Zs[i],]
  bP <- Zs[i]
  AG <- predict(GAM, newdata = predP , type = "response", se.fit = TRUE)
  PGW1 <- data.frame(cbind(bP,AG$fit))
  PGW2 <- rbind(PGW2,PGW1)
}
Bharat
  • 1
  • 1

0 Answers0