1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gensvm.maxabs.scale.R
\name{gensvm.maxabs.scale}
\alias{gensvm.maxabs.scale}
\title{Scale each column of a matrix by its maximum absolute value}
\usage{
gensvm.maxabs.scale(x, x.test = NULL)
}
\arguments{
\item{x}{a matrix to scale}
\item{x.test}{(optional) a test matrix to scale as well.}
}
\value{
if x.test=NULL a scaled matrix where the maximum value of the
columns is 1 and the minimum value of the columns isn't below -1. If x.test
is supplied, a list with elements \code{x} and \code{x.test} representing
the scaled datasets.
}
\description{
Scaling a dataset can greatly decrease the computation time of
GenSVM. This function scales the data by dividing each column of a matrix by
the maximum absolute value of that column. This preserves sparsity in the
data while mapping each column to the interval [-1, 1].
Optionally a test dataset can be provided as well. In this case, the scaling
will be computed on the first argument (\code{x}) and applied to the test
dataset. Note that the return value is a list when this argument is
supplied.
}
\examples{
x <- iris[, -5]
# check the min and max of the columns
apply(x, 2, min)
apply(x, 2, max)
# scale the data
x.scale <- gensvm.maxabs.scale(x)
# check again (max should be 1.0, min shouldn't be below -1)
apply(x.scale, 2, min)
apply(x.scale, 2, max)
# with a train and test dataset
split <- gensvm.train.test.split(x)
x.train <- split$x.train
x.test <- split$x.test
scaled <- gensvm.maxabs.scale(x.train, x.test)
x.train.scl <- scaled$x
x.test.scl <- scaled$x.test
}
\references{
Van den Burg, G.J.J. and Groenen, P.J.F. (2016). \emph{GenSVM: A Generalized
Multiclass Support Vector Machine}, Journal of Machine Learning Research,
17(225):1--42. URL \url{https://jmlr.org/papers/v17/14-526.html}.
}
\seealso{
\code{\link{gensvm}}, \code{\link{gensvm.grid}},
\code{\link{gensvm.train.test.split}}, \code{\link{gensvm-package}}
}
\author{
Gerrit J.J. van den Burg, Patrick J.F. Groenen \cr
Maintainer: Gerrit J.J. van den Burg <gertjanvandenburg@gmail.com>
}
|