R package – LiblineaR

This package is the linear predictive models based on the LIBLINEAR C/C++ Library. Here is one example using the iris dataset. The program tries to predict which category a plant belongs to by using training data:

library(LiblineaR)data(iris)attach(iris)x=iris[,1:4]y=factor(iris[,5])train=sample(1:dim(iris)[1],100)xTrain=x[train,];xTest=x[-train,]yTrain=y[train]; yTest=y[-train]s=scale(xTrain,center=TRUE,scale=TRUE)#tryTypes=c(0:7)tryCosts=c(1000,1,0.001)bestCost=NAbestAcc=0bestType=NA#for(ty in tryTypes){   for(co in tryCosts){     acc=LiblineaR(data=s,target=yTrain,type=ty,cost=co,bias=1,cross=5,verbose=FALSE)     cat("Results for C=",co,": ",acc," accuracy.\n",sep="")     if(acc>bestAcc){         bestCost=co         bestAcc=acc         bestType=ty     }

Get Hands-On Data Science with Anaconda now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.