• Notes
• 4

This preview shows page 2 - 3 out of 4 pages.

svmfit=svm(y~.,data=dat,kernel="linear",cost=.01,scale=FALSE) ypred=predict(svmfit,testdat) table(predict=ypred,truth=testdat\$y) x[y==1,]=x[y==1,]+.5 plot(x,col=(y+5)/2,pch=19) dat=data.frame(x=x,y=as.factor(y)) svmfit=svm(y~.,data=dat,kernel="linear",cost=1e+05) summary(svmfit) plot(svmfit,dat) svmfit=svm(y~.,data=dat,kernel="linear",cost=1) summary(svmfit) plot(svmfit,dat) #Support Vector Machine set.seed(1) x=matrix(rnorm(200*2),ncol=2) x[1:100,]=x[1:100,]+2 x[101:150,]=x[101:150,]-2 y=c(rep(1,150),rep(2,50)) dat=data.frame(x=x,y=as.factor(y)) plot(x,col=y) train=sample(200,100) svmfit=svm(y~.,data=dat[train,],kernel="radial",gamma=1,cost=1) plot(svmfit,dat[train,]) summary(svmfit) svmfit=svm(y~.,data=dat[train,],kernel="radial",gamma=1,cost=1e5) plot(svmfit,dat[train,]) set.seed(1) tune.out=tune(svm,y~.,data=dat[train,],kernel="radial",ranges=list(cost=c(.1,1,1 0,100,1000),gamma=c(.5,1,2,3,4))) summary(tune.out) table(true=dat[-train,"y"],pred=predict(tune.out\$best.model,newdata=dat[- train,])) #ROC Curves library(ROCR) rocplot = function(pred,truth,...) { predob=prediction(pred,truth) perf=performance(predob,"tpr","fpr") plot(perf,...) } svmfit.opt=svm(y~., data=dat[train,],kernel="radial",gamma=2,cost=1,decision.values=T) fitted=attributes(predict(svmfit.opt,dat[train,],decision.values=TRUE)) \$decision.values par(mfrow=c(1,2)) rocplot(fitted,dat[train,"y"],main="Training Data") svmfit.flex=svm(y~.,data=dat[train,],kernel="radial",gamma=50,cost=1,decision.va

Subscribe to view the full document.

• Fall '16
• alec schimdt

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern