I ran the following code for a binary classification task w/ an SVM in both R (first…
- User
I ran the following code for a binary classification task w/ an SVM in both R (first sample) and Python (second example). Given randomly generated data (X) and response (Y), this code performs leave group out cross validation 1000 times. Each entry of Y is therefore the mean of the prediction across CV iterations. Computing area under the curve should give ~0.5, since X and Y are completely random. However, this is not what we see. Area under the curve is frequently significantly higher than 0.5. The number of rows of X is very small, which can obviously cause problems. Any idea what could be happening here? I know that I can either increase the number of rows of X or decrease the number of columns to mediate the problem, but I am looking for other issues.
Y=as.factor(rep(c(1,2), times=14)) X=matrix(runif(length(Y)*100), nrow=length(Y))
library(e1071) library(pROC)
colnames(X) <- 1:ncol(X) iter <- 1000 ansMat <- matrix(NA,length(Y),iter) r <- numeric(iter) for(i in seq(iter)){
#get traintrain <- sample(seq(length(Y)),0.5*length(Y)) if(min(table(Y[train]))==0) next
#test from train test <- seq(length(Y))[-train]
#train model XX=X[train,] YY=Y[train] mod=svm(XX,YY,probability =FALSE) XXX=X[test,] predVec=predict(mod,XXX, decision.values = TRUE) RFans = attr(predVec,'decision.values') #ansMat[test,i]=RFans r[i] <- roc(Y[test], RFans)$auc } mean(r) ans=rowMeans(ansMat,na.rm=TRUE)
r1=roc(Y,ans)$auc print(r1)
- Assistant