Learn R Programming

FactoRizationMachines (version 0.35)

SVM.train: Method training a Support Vector Machine

Description

SVM.train is a method training a Support Vector Machine with a linear kernel.

factors specifies whether linear weights are used (1) or not (0). If linear weights are not used intercept is set to TRUE.

Usage

SVM.train(data, target, factors = 1, intercept = T, 
  iter = 100, regular = NULL, stdev = 0.1)

Arguments

data

an object of class dgTMatrix, matrix or data.frame (or an object coercible to dgTMatrix): a matrix containing training data, each row representing a training example and each column representing a feature.

target

numeric: vector specifying the target value of each training example (length must match rows of object data).

factors

either 0 or 1: specifying whether linear weights are used (1) or not (0). If linear weights are not used intercept is set to TRUE.

intercept

logical: specifying whether a global intercept is used (TRUE) or not (FALSE).

iter

integer: the number of iterations the learning method is applied.

regular

numeric: regularization value for the linear weights. If regular is NULL, automatic regularization using Markov Chain Monte Carlo (MCMC) method is applied.

stdev

numeric: the standard deviation used to initialize the model parameters.

See Also

FactoRizationMachines

Examples

Run this code
# NOT RUN {
### Example to illustrate the usage of the method
### Data set very small and not sparse, results not representative
### Please study major example in general help 'FactoRizationMachines'

# Load data set
library(FactoRizationMachines)
library(MASS)
data("Boston")

# Subset data to training and test data
set.seed(123)
subset=sample.int(nrow(Boston),nrow(trees)*.8)
data.train=Boston[subset,-ncol(Boston)]
target.train=Boston[subset,ncol(Boston)]
data.test=Boston[-subset,-ncol(Boston)]
target.test=Boston[-subset,ncol(Boston)]


# Predict with linear weights and intercept with MCMC regularization
model=SVM.train(data.train,target.train)

# RMSE resulting from test data prediction
sqrt(mean((predict(model,data.test)-target.test)^2))


# Predict with linear weights but without intercept with MCMC regularization
model=SVM.train(data.train,target.train,intercept=FALSE)

# RMSE resulting from test data prediction
sqrt(mean((predict(model,data.test)-target.test)^2))


# Predict with linear weights and manual regularization
model=SVM.train(data.train,target.train,regular=0.1)

# RMSE resulting from test data prediction
sqrt(mean((predict(model,data.test)-target.test)^2))

# }

Run the code above in your browser using DataLab