search for: trainset

Displaying 20 results from an estimated 42 matches for "trainset".

2020 Oct 23
5
How to shade area between lines in ggplot2
...norm(100, mean = 0.2, sd = 0.1) x2 = rnorm(100, mean = 0.75, sd = 0.1) df = data.frame(x = c(x1,x2), y=c(y1,y2), z=c(rep(0, length(x1)), rep(1, length(x2)))) df$z = factor(c(rep(0, length(x1)), rep(1, length(x2)))) df[, "train"] <- ifelse(runif(nrow(df)) < 0.8, 1, 0) trainset <- df[df$train == 1, ] testset <- df[df$train == 0, ] trainColNum <- grep("train", names(df)) trainset <- trainset[, -trainColNum] testset <- testset[, -trainColNum] head(trainset); str(df) svm_model<- svm(z ~ ., data = trainset, type = &...
2020 Oct 23
0
How to shade area between lines in ggplot2
...= 0.1) > x2 = rnorm(100, mean = 0.75, sd = 0.1) > df = data.frame(x = c(x1,x2), y=c(y1,y2), > z=c(rep(0, length(x1)), rep(1, length(x2)))) df$z = factor(c(rep(0, > length(x1)), rep(1, length(x2)))) df[, "train"] <- ifelse(runif(nrow(df)) < 0.8, 1, 0) > trainset <- df[df$train == 1, ] testset <- df[df$train == 0, ] trainColNum <- > grep("train", names(df)) trainset <- trainset[, -trainColNum] testset <- testset[, > -trainColNum] head(trainset); str(df) > > svm_model<- svm(z ~ ., > data = trainset,...
2012 Dec 02
2
How to re-combine values based on an index?
I am able to split my df into two like so: dataset <- trainset index <- 1:nrow(dataset) testindex <- sample(index, trunc(length(index)*30/100)) trainset <- dataset[-testindex,] testset <- dataset[testindex,-1] So I have the index information, how could I re-combine the data using that back into a single df? I tried what I thought might work, but...
2011 Jan 24
5
Train error:: subscript out of bonds
...xample when I set seed to 357 following code produced result only for 8 iterations and for 9th iteration it reaches to an error that ?subscript out of bonds? error. I don?t understand why Any help would be great thanks ####### for (i in 1:10) { fit1<-NULL; x<-NULL; x<-which(number==i) trainset<-d[-x,] testset<-d[x,] train1<-trainset[,-ncol(trainset)] train1<-train1[,-(1)] test_t<-testset[,-ncol(testset)] species_test<-as.factor(testset[,ncol(testset)]) test_t<-test_t[,-(1)] #### #CARET::TRAIN #### fit1<-train(train1,as.factor(trainset[,ncol(trainset)]),...
2020 Oct 23
2
How to shade area between lines in ggplot2
also from this site: https://plotly.com/ggplot2/geom_ribbon/ I get the answer is geom_ribbon but I am still missing something ``` #! plot p = ggplot(data = trainset, aes(x=x, y=y, color=z)) + geom_point() + scale_color_manual(values = c("red", "blue")) # show support vectors df_sv = trainset[svm_model$index, ] p = p + geom_point(data = df_sv, aes(x=x, y=y), color="purple", size=4, alpha=0.5) # show hyperplane...
2020 Oct 23
2
How to shade area between lines in ggplot2
...lp at r-project.org> > > Subject: Re: [R] How to shade area between lines in ggplot2 > > > > also from this site: https://plotly.com/ggplot2/geom_ribbon/ > > I get the answer is geom_ribbon but I am still missing something ``` #! plot > > p > > = ggplot(data = trainset, aes(x=x, y=y, color=z)) + > > geom_point() + scale_color_manual(values = c("red", "blue")) # show > > support vectors df_sv = trainset[svm_model$index, ] p = p + > > geom_point(data = df_sv, aes(x=x, y=y), > > color="purple&quot...
2012 Nov 29
1
Help with this error "kernlab class probability calculations failed; returning NAs"
...l simplify my problem to a basic data set which produces the same problem. I have read the caret vignettes as well as documentation for ?train. I appreciate any direction you can give. I realize this is a very small dataset, the actual data is much larger, I am just using 10 rows as an example: trainset <- data.frame( outcome=factor(c("0","1","0","1","0","1","1","1","1","0")), age=c(10, 23, 5, 28, 81, 48, 82, 23, 11, 9), amount=c(10.11, 22.23, 494.2, 2.0, 29.2, 39.2, 39.2, 39.0, 11.1, 12.2...
2013 Jul 06
1
problem with BootCV for coxph in pec after feature selection with glmnet (lasso)
...rediction matrix has wrong dimensions: 368 rows and 318 columns. But requested are predicted probabilities for 118 subjects (rows) in newdata and 356 time points (columns) This may happen when some covariate values are missing in newdata!? Here are the relevant sections of the code: trainSet <- na.omit (dataset) #creat Y (survival matrix) for glmnet surv_obj <- Surv(trainSet$time,trainSet$status) ## tranform categorical variables into binary variables with dummy for trainSet predict_matrix <- model.matrix(~ ., data=trainSet,...
2020 Oct 23
0
How to shade area between lines in ggplot2
...> > Cc: r-help <r-help at r-project.org> > Subject: Re: [R] How to shade area between lines in ggplot2 > > also from this site: https://plotly.com/ggplot2/geom_ribbon/ > I get the answer is geom_ribbon but I am still missing something ``` #! plot > p > = ggplot(data = trainset, aes(x=x, y=y, color=z)) + > geom_point() + scale_color_manual(values = c("red", "blue")) # show > support vectors df_sv = trainset[svm_model$index, ] p = p + > geom_point(data = df_sv, aes(x=x, y=y), > color="purple", size=4, alpha=0.5...
2013 Jan 08
0
bagging SVM Ensemble
...ibrary(colorspace) library(rpart) library(e1071) library(MASS) dataset <- read.csv("E:/thesis/SVM/hepatitis data csv.csv",header=T,sep=";") attach(dataset) index <- 1:nrow(dataset) testindex <- sample(index, trunc(length(index)*30/100)) testset <- dataset[testindex,] trainset <- dataset[-testindex,] trainindex <- sample(index, trunc(length(index)*70/100)) tuned <- tune.svm(class~., data = trainset, gamma = 10^(-6:-1), cost = 10^(-1:1)) cc <- as.numeric(tuned$best.parameters[2]) gg <- as.numeric(tuned$best.parameters[1]) modelolin <- svm(class ~ ., trai...
2020 Oct 26
0
How to shade area between lines in ggplot2
...eom_ribbon(aes(ymin = slope_1*x + intercept_1 - 1/w[2], ymax = slope_1*x + intercept_1 + 1/w[2]), fill = "blue", alpha=0.1) The "hole" is because you have two levels of data (red and blue). To get rid of this you should put new data in ribbon call. Something like newdat <- trainset newdat$z <- factor(0) p+geom_ribbon(data=newdat, aes(ymin = slope_1*x + intercept_1 - 1/w[2], ymax = slope_1*x + intercept_1 + 1/w[2]), fill = "yellow", alpha=0.1) Cheers Petr > -----Original Message----- > From: Luigi Marongiu <marongiu.luigi at gmail.com> > Sent: Fri...
2010 Nov 23
5
cross validation using e1071:SVM
...k my result based on Accuracy and Kappa value generated by caret:confusionMatrix. ########################################## Code ######################################### x<-NULL index<-cvsegments(nrow(data),10) for(i in 1:length(index)) { x<-matrix(index[i]) testset<-data[x[[1]],] trainset<-data[-x[[1]],] species<-as.factor(trainset[,ncol(trainset)]) train1<-trainset[,-ncol(trainset)] train1<-train1[,-(1)] test_t<-testset[,-ncol(testset)] species_test<-as.factor(testset[,ncol(testset)]) test_t<-test_t[,-(1)] model_true1 <- svm(train1,species) pred_t...
2020 Oct 27
3
R for-loop to add layer to lattice plot
...= 0.2, sd = 0.15) x2 = rnorm(100, mean = 0.75, sd = 0.15) df = data.frame(x = c(x1,x2), y=c(y1,y2), z=c(rep(0, length(x1)), rep(1, length(x2)))) df$z = factor(c(rep(0, length(x1)), rep(1, length(x2)))) df[, "train"] <- ifelse(runif(nrow(df)) < 0.8, 1, 0) trainset <- df[df$train == 1, ] testset <- df[df$train == 0, ] trainColNum <- grep("train", names(df)) trainset <- trainset[, -trainColNum] testset <- testset[, -trainColNum] svm_model <- svm(z ~ ., data = trainset, type = "C-cla...
2013 Jan 15
1
Random Forest Error for Factor to Character column
...is the limit in randomForest but I guess I don't understand enough about factors because I thought by subsetting the data this no longer would be an issue. BTW I can run randomForest on this dataset if I exclude "JOBTITLE". So I then converted that column to a character vector: > TRAINSET$JOBTITLE<-as.character(TRAINSET$JOBTITLE) I ran Random Forest and got the below error. Why isn't this working? What do I need to do to get this working? > library(randomForest) > FOREST_model <- randomForest(as.factor(TARGET)~., data=trainset, mtry=4, ntree=1000, +...
2005 Sep 04
2
Help: PLSR
Hello, I have a data set with 15 variables (first one is the response) and 1200 observations. Now I use pls package to do the plsr as below. trainSet = as.data.frame(scale(trainSet, center = T, scale = T)) trainSet.plsr = mvr(formula, ncomp = 14, data = trainSet, method = "kernelpls", model = TRUE, x = TRUE, y = TRUE) from the model, I wish to know the values of Xvar (the amount of X-variance explained by e...
2009 Mar 11
1
prediction error for test set-cross validation
...AgGr + FaHx + PrHx + PrSr + PaLp + SvD + IndExam + Rad +BrDn + BRDS + PrinFin+ SkRtr + NpRtr + SkThck +TrThkc + SkLes + AxAdnp + ArcDst + MaDen + CaDt + MaMG + MaMrp + MaSh + SCTub + SCFoc + MaSz, family=binomial(link=logit)); Where the variables are taken from the trainSet of size 1989x31. The test set is sized 222x31. Now my question is when I try to predict on the test set it gives me the error: > predict.glm(model, testSet, type ="response") "Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) : subscript out of bounds" It does...
2011 Nov 30
1
Replace columns in a data.frame randomly splitted
...I typed: df1<- read.xls("C:/... dir .../df1.xls",colNames= TRUE, rowNames= TRUE) Then I splited randomly df1 using splitdf function (http://gettinggeneticsdone.blogspot.com/2011/03/splitting- dataset-revisited-keeping.html) So now, I have df1 divided in another 2 dataframes: trainset and testset. (They both have the same row names and column names as df1) I'd like to change df1$v1 and df1$v2 values in the trainset and testset by the ones in df2 ( http://r.789695.n4.nabble.com/file/n4122926/df2.xls df2.xls ) How can I explain R to identify in trainset/testset$v1 and $...
2020 Oct 28
0
R for-loop to add layer to lattice plot
...rnorm(100, mean = 0.75, sd = 0.15) > df = data.frame(x = c(x1,x2), y=c(y1,y2), > z=c(rep(0, length(x1)), rep(1, length(x2)))) > df$z = factor(c(rep(0, length(x1)), rep(1, length(x2)))) > df[, "train"] <- ifelse(runif(nrow(df)) < 0.8, 1, 0) > trainset <- df[df$train == 1, ] > testset <- df[df$train == 0, ] > trainColNum <- grep("train", names(df)) > trainset <- trainset[, -trainColNum] > testset <- testset[, -trainColNum] > svm_model <- svm(z ~ ., > data = trainset, >...
2012 Nov 20
3
data after write() is off by 1 ?
...label : Factor w/ 10 levels "0","1","2","3",..: 2 1 2 5 1 1 8 4 6 4 ... $ pixel0 : int 0 0 0 0 0 0 0 0 0 0 ... $ pixel1 : int 0 0 0 0 0 0 0 0 0 0 ... $ pixel2 : int 0 0 0 0 0 0 0 0 0 0 ... [list output truncated] # I make a sampling testset and trainset > index <- 1:nrow(dataset) > testindex <- sample(index, trunc(length(index)*30/100)) > testset <- dataset[testindex,] > trainset <- dataset[-testindex,] # build model, predict, view > model <- svm(label~., data = trainset, type="C-classification", kernel=&q...
2012 Sep 27
1
Random Forest - Extract
Hello, I have two Random Forest (RF) related questions. 1. How do I view the classifications for the detail data of my training data (aka trainset) that I used to build the model? I know there is an object called predicted which I believe is a vector. To view the detail for my testset I use the below-bind the columns together. I was trying to do something similar for my trainset but without putting it through the predict function. Instead ta...