From 474b560aeba8e26a2f03930cf42f04ae5e648670 Mon Sep 17 00:00:00 2001 From: WeiZhou2372 Date: Thu, 9 Mar 2017 12:53:11 -0500 Subject: [PATCH] Update spam_class_r.r fixed "Error in train.default(x, y, weights = w, ...)" --- spam_class_r.r | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spam_class_r.r b/spam_class_r.r index 9e5d690..a4cac56 100644 --- a/spam_class_r.r +++ b/spam_class_r.r @@ -9,6 +9,10 @@ names <- read.csv("names.csv",header=FALSE,sep=";") #Set the names of the dataset dataframe: names(dataset) <- sapply((1:nrow(names)),function(i) toString(names[i,1])) +#Or there will be a "not a valid R variable name" error +dataset$y[dataset$y == 1] = "yes" +dataset$y[dataset$y == 0] = "no" + #make column y a factor variable for binary classification (spam or non-spam) dataset$y <- as.factor(dataset$y) @@ -19,6 +23,7 @@ sample <- dataset[sample(nrow(dataset), 1000),] #Set up the packages: +#require(e1071) #better installed before sourcing #install.packages(“caret”) require(caret) @@ -29,7 +34,7 @@ require(kernlab) #install.packages(“doMC”) -require(doMC) +#require(doMC) #It is not valid from CRAN for R 3.3.2 Windows, but you may install it manually. #Split the data in dataTrain and dataTest @@ -38,7 +43,7 @@ dataTrain <- sample[ trainIndex,] dataTest <- sample[-trainIndex,] #set up multicore environment -registerDoMC(cores=5) +#registerDoMC(cores=5) #Create the SVM model: @@ -59,4 +64,4 @@ x <- train(y ~ ., #Evaluate the model pred <- predict(x,dataTest[,1:57]) -acc <- confusionMatrix(pred,dataTest$y) \ No newline at end of file +acc <- confusionMatrix(pred,dataTest$y)