machine learning - SVM is not generating forecast using R -
i have sales data 5 different product along weather information.to read data, have daily sales data @ particular store , daily weather information temperature, average speed of area store located. using support vector machine prediction. works products except one. giving me following error:
tunedmodellog named numeric(0)
below code:
# load packages library(zoo) library(mass) library(e1071) library(rpart) library(caret) normalize <- function(x) { <- min(x, na.rm=true) b <- max(x, na.rm=true) (x - a)/(b - a) } # define train , test data test_data <- train[1:23,] train_data<-train[24:nrow(train),] # define factors categorical data names<-c("year","month","dom","holiday","blackfriday","after1","back1","after2","back2","after3","back3","is_weekend","weeday") train_data[,names]<- lapply(train_data[,names],factor) test_data[,names] <- lapply(test_data[,names],factor) # normalized continuous data normalized<-c("snowfall","depart","cool","preciptotal","sealevel","stnpressure","resultspeed","resultdir") train_data[,normalized] <- data.frame(lapply(train_data[,normalized], normalize)) test_data[,normalized] <- data.frame(lapply(test_data[,normalized], normalize)) # define same level in train , test data levels(test_data$month)<-levels(train_data$month) levels(test_data$dom)<-levels(train_data$dom) levels(test_data$year)<-levels(train_data$year) levels(test_data$after1)<-levels(train_data$after1) levels(test_data$after2)<-levels(train_data$after2) levels(test_data$after3)<-levels(train_data$after3) levels(test_data$back1)<-levels(train_data$back1) levels(test_data$back2)<-levels(train_data$back2) levels(test_data$back3)<-levels(train_data$back3) levels(test_data$holiday)<-levels(train_data$holiday) levels(test_data$is_weekend)<-levels(train_data$is_weekend) levels(test_data$blackfriday)<-levels(train_data$blackfriday) levels(test_data$is_weekend)<-levels(train_data$is_weekend) levels(test_data$weeday)<-levels(train_data$weeday) # fit svm model , tune parameters svmrefitlog=tune(svm,logunits~year+month+dom+holiday+blackfriday+after1+after2+after3+back1+back2+back3+is_weekend+depart+cool+preciptotal+sealevel+stnpressure+resultspeed+resultdir,data=train_data,ranges = list(epsilon = c(0,0.1,0.01,0.001), cost = 2^(2:9))) retunedmodelog <- svmrefitlog$best.model tunedmodellog <- predict(retunedmodelog,test_data)
working file available @ below link https://drive.google.com/file/d/0bzcj8ytbecpmvvj1uug2rhhqnfk/view?usp=sharing
what doing wrong? appreciate kind of help. in advance.
Comments
Post a Comment