library(caret)
## Loading required package: lattice
## Loading required package: ggplot2
library(e1071)
library(fastICA)
load("~/PED/prepareDataDay/PP_new.RData")
source('~/functions/normalizationFunction.R', echo=TRUE)
##
## > normalized <- function(x) {
## + (x - min(x)) * 0.8/(max(x) - min(x)) + 0.1
## + }
source('~/functions/calculateErrors.R', echo=TRUE)
##
## > modelErrors <- function(predicted, actual) {
## + sal <- vector(mode = "numeric", length = 3)
## + names(sal) <- c("MAE", "RMSE", "RELE")
## + me .... [TRUNCATED]
##
## > modelsErrorsTotal <- 0
##
## > allModelErrors <- function(models, inputsTest, targetsTest,
## + dataset) {
## + error <- function(model) {
## + pd <- predict(model, newdat .... [TRUNCATED]
PP_new[c("MONTHC" ,"DAYC" ,"WEEKDAYC" ,"SEASONC" ,"MAXO3P" , "MAXNOXP" , "MAXNO2P" , "MAXSO2P" ,"MAXCOP", "MAXTMPP", "MAXRHP" , "MAXWSPP" , "MAXWDRP" , "MINO3P", "MINNOxP" ,"MINNO2P","MINSO2P" , "MINCOP", "MINTMPP" ,"MINRHP" ,"MINWSPP","MINWDRP" ,"AVGO3P","AVGNOXP","AVGNO2P", "AVGSO2P" ,"AVGCOP" ,"AVGTMPP" , "AVGRHP" , "AVGWSPP" ,"AVGWDRP" ,"STDO3P" ,"STDNOxP" , "STDNO2P" , "STDSO2P" ,"STDCOP" , "STDTMPP", "STDRHP" , "STDWSPP" , "STDWDRP","MAXO3C")]->feature1
data.frame(apply(feature1,2,normalized))->feature1_norm
inTrain = createDataPartition(feature1_norm$MAXO3C, p = 2/3, list = FALSE)
train1=feature1_norm[inTrain ,]
test1=feature1_norm[-inTrain,]
train1[,ncol(train1)]->targetsTrain1
test1[,ncol(test1)]->targetsTest1
train1[,-ncol(train1)]->inputsTrain1
test1[,-ncol(test1)]->inputsTest1
svm
svm(inputsTrain1,targetsTrain1,gamma=0.01,cost=0.01,epsilon=0.0001)->svmFit
predict(svmFit,newdata=inputsTest1)->svm_pred_test
modelErrors(svm_pred_test,targetsTest1)
## MAE RMSE RELE
## 0.08187 0.10679 0.25829
PCA
inputsTrain_pca<-prcomp(inputsTrain1)
plot(inputsTrain_pca)
###select the first 6 components
inputsTrain_pca$x[,1:6]->pca6
###training svm and see the errors of training set
svm(pca6,targetsTrain1,gamma=10,cost=0.0001,epsilon=0.0001)->svmFit_pca
predict(svmFit_pca,newdata=pca6)->svm_pred_pca_train
modelErrors(svm_pred_pca_train,targetsTrain1)
## MAE RMSE RELE
## 0.0957 0.1221 0.3044
ICA
ica <- fastICA(inputsTrain1, 6, alg.typ = "parallel", fun = "logcosh", alpha = 1,
method = "R", row.norm = FALSE, maxit = 500,
tol = 0.0001, verbose = TRUE)
## Centering
## Whitening
## Symmetric FastICA using logcosh approx. to neg-entropy function
## Iteration 1 tol = 0.9326
## Iteration 2 tol = 0.9655
## Iteration 3 tol = 0.2565
## Iteration 4 tol = 0.01024
## Iteration 5 tol = 0.0002606
## Iteration 6 tol = 7.205e-05
ica6<-ica$S
svm(ica6,targetsTrain1,gamma=10,cost=0.0001,epsilon=0.0001)->svmFit_ica
predict(svmFit_ica,newdata=ica6)->svm_pred_ica_train
modelErrors(svm_pred_ica_train,targetsTrain1)
## MAE RMSE RELE
## 0.0957 0.1221 0.3044