#------------------ # Data Preparation #------------------ #Read datasets #Download the data from http://www.saedsayad.com/datasets/BikeRental.zip train <- read.csv("bike_rental_train.csv") test <- read.csv("bike_rental_test.csv") #Rows and Cols dim(train) dim(test) #Columns name colnames(train) colnames(test) #Show head(train) head(test) #Rows and Cols dim(train) dim(test) #Columns name colnames(train) colnames(test) #Show head(train) head(test) #Scatter plot pairs(~temp+humidity+windspeed+bike_rent_count, data=train, main="Scatterplot - train", col="darkgreen") pairs(~temp+humidity+windspeed+bike_rent_count, data=test, main="Scatterplot - test", col="brown") #-------------------------------------- # Support Vector Machines - Regression #-------------------------------------- library(e1071) #Train model.SVR <- svm(bike_rent_count~., train) summary(model.SVR) #Residual plot res.SVR = train$bike_rent_count-predict(model.SVR, newdata=train) plot(train$temp, res.SVR, ylab="Residuals", xlab="Temperature", main="Residual Plot") abline(0, 0) #Q-Q plot stdres.SVR = scale(res.SVR) qqnorm(stdres.SVR, ylab="Standardized Residuals", xlab="Normal Scores", main="QQ Plot") qqline(stdres.SVR) #Test pred.SVR <- predict(model.SVR, newdata=test) err.SVR <- test$bike_rent_count - pred.SVR rmse.SVR <- sqrt(mean((err.SVR^2))) #Errors histogram hist(err.SVR, main="bike_rent_count", sub="(Actual-Predicted)", xlab="Error", breaks=10, col="darkred")