Back to godoc.org
github.com/pa-m/sklearn / preprocessing

Package preprocessing

v0.0.0-...-beb861e
Latest Go to latest

The latest major version is .

Published: Jul 11, 2020 | License: MIT | Module: github.com/pa-m/sklearn

Overview

Package preprocessing includes scaling, centering, normalization, binarization and imputation methods.

Index

Examples

func AddDummyFeature

func AddDummyFeature(X *mat.Dense)

AddDummyFeature insert a column of ones to fit intercept

Example

Code:

X := mat.NewDense(2, 5, []float64{2, 3, 4, 5, 6, 7, 8, 9, 10, 11})
AddDummyFeature(X)
fmt.Printf("X %v\n", X.RawRowView(0))
fmt.Printf("X %v\n", X.RawRowView(1))
X [1 2 3 4 5 6]
X [1 7 8 9 10 11]

func DenseMean

func DenseMean(Xmean *mat.Dense, X mat.Matrix) *mat.Dense

DenseMean puts in Xmean[1,nFeatures] the mean of X rows

func IncrementalMeanAndVar

func IncrementalMeanAndVar(X, lastMean, lastVariance *mat.Dense,
	lastSampleCount int) (updatedMean, updatedVariance *mat.Dense, updatedSampleCount int)

IncrementalMeanAndVar Calculate mean update and a Youngs and Cramer variance update. lastMean and lastVariance are statistics computed at the last step by the function. Both must be initialized to 0.0. In case no scaling is required lastVariance can be None. The mean is always required and returned because necessary for the calculation of the variance. lastNSamplesSeen is the number of samples encountered until now. From the paper "Algorithms for computing the sample variance: analysis and recommendations", by Chan, Golub, and LeVeque. Parameters ---------- X : array-like, shape (nSamples, nFeatures)

Data to use for variance update

lastMean : array-like, shape: (nFeatures,) lastVariance : array-like, shape: (nFeatures,) lastSampleCount : int Returns ------- updatedMean : array, shape (nFeatures,) updatedVariance : array, shape (nFeatures,)

If None, only mean is computed

updatedSampleCount : int References ---------- T. Chan, G. Golub, R. LeVeque. Algorithms for computing the sample

variance: recommendations, The American Statistician, Vol. 37, No. 3,
pp. 242-247

Also, see the sparse implementation of this in `utils.sparsefuncs.incrMeanVarianceAxis` and `utils.sparsefuncsFast.incrMeanVarianceAxis0` """

func Mean

func Mean(X mat.Matrix) (mean *mat.Dense)

Mean for mat.Matrix

func MeanStdDev

func MeanStdDev(X mat.Matrix) (mean, std *mat.Dense)

MeanStdDev for mat.Matrix

func Scale

func Scale(X *mat.Dense) *mat.Dense

Scale provides a quick and easy way to perform this operation on a single array-like dataset

Example

Code:

// adapted from http://scikit-learn.org/stable/modules/preprocessing.html#standardization-or-mean-removal-and-variance-scaling
Xtrain := mat.NewDense(3, 3, []float64{1, -1, 2, 2, 0, 0, 0, 1, -1})
Xscaled := Scale(Xtrain)
fmt.Printf("Xscaled\n%.3f\n", mat.Formatted(Xscaled))
mean := Mean(Xscaled)
std := (NumpyLike{}).Std(Xscaled)
fmt.Printf("mean:%g\nstd:%.3f\n", mat.Formatted(mean), mat.Formatted(std))
Xscaled
⎡ 0.000  -1.225   1.336⎤
⎢ 1.225   0.000  -0.267⎥
⎣-1.225   1.225  -1.069⎦
mean:[0  0  0]
std:[1.000  1.000  1.000]

type Binarizer

type Binarizer struct{ Threshold float64 }

Binarizer Binarize data (set feature values to 0 or 1) according to a threshold

Example

Code:

// adapted from http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.Binarizer.html#sklearn.preprocessing.Binarizer
X := mat.NewDense(3, 3, []float64{1, -1, 2, 2, 0, 0, 0, 1, -1})
binarizer := NewBinarizer()
binarizer.Fit(X, nil) // fit does nothing
X1, _ := binarizer.Transform(X, nil)
fmt.Println(mat.Formatted(X1))

// It is possible to adjust the threshold of the binarizer:
binarizer.Threshold = 1.1
X1, _ = binarizer.Transform(X, nil)
fmt.Println(mat.Formatted(X1))
⎡1  0  1⎤
⎢1  0  0⎥
⎣0  1  0⎦
⎡0  0  1⎤
⎢1  0  0⎥
⎣0  0  0⎦

func NewBinarizer

func NewBinarizer() *Binarizer

NewBinarizer ...

func (*Binarizer) Fit

func (m *Binarizer) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for binarizer does nothing

func (*Binarizer) FitTransform

func (m *Binarizer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to data, then transform it

func (*Binarizer) Transform

func (m *Binarizer) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for Binarizer

func (*Binarizer) TransformerClone

func (m *Binarizer) TransformerClone() base.Transformer

TransformerClone ...

type FunctionTransformer

type FunctionTransformer struct {
	Func, InverseFunc func(X, Y *mat.Dense) (X1, Y1 *mat.Dense)
}

FunctionTransformer Constructs a transformer from an arbitrary callable.

Example

Code:

X, Y := mat.NewDense(2, 4, []float64{1, 2, 3, 4, 5, 6, 7, 8}), (*mat.Dense)(nil)

var firstColumn []float64
dropFirstColumn := func(X, Y *mat.Dense) (X1, Y1 *mat.Dense) {
	m, n := X.Dims()
	firstColumn = make([]float64, m)
	mat.Col(firstColumn, 0, X)
	X1 = mat.NewDense(m, n-1, nil)
	X1.Copy(X.Slice(0, m, 1, n))
	Y1 = Y
	return
}
undoDropFirstColumn := func(X, Y *mat.Dense) (X1, Y1 *mat.Dense) {
	m, n := X.Dims()
	n++
	X1 = mat.NewDense(m, n, nil)
	X1.SetCol(0, firstColumn)
	X1.Slice(0, m, 1, n).(*mat.Dense).Copy(X)
	Y1 = Y
	return
}
allButFirstColumn := NewFunctionTransformer(dropFirstColumn, undoDropFirstColumn)
X1, _ := allButFirstColumn.Transform(X, Y)
fmt.Println(mat.Formatted(X1))
X2, _ := allButFirstColumn.InverseTransform(X1, nil)
fmt.Println(mat.Formatted(X2))

// additional example from http://scikit-learn.org/stable/modules/preprocessing.html#custom-transformers
transformer := NewFunctionTransformer(
	func(X, Y *mat.Dense) (X1, Y1 *mat.Dense) {
		Xmat := X.RawMatrix()
		X1 = mat.NewDense(Xmat.Rows, Xmat.Cols, nil)
		X1.Apply(func(i, j int, v float64) float64 { return math.Log1p(v) }, X)
		Y1 = Y
		return

	}, func(X, Y *mat.Dense) (X1, Y1 *mat.Dense) {
		Xmat := X.RawMatrix()
		X1 = mat.NewDense(Xmat.Rows, Xmat.Cols, nil)
		X1.Apply(func(i, j int, v float64) float64 { return math.Exp(v) - 1 }, X)
		Y1 = Y
		return

	},
)
X = mat.NewDense(2, 2, []float64{0, 1, 2, 3})
X1, _ = transformer.Transform(X, nil)
fmt.Printf("log1p:\n%.8f\n", mat.Formatted(X1))
⎡2  3  4⎤
⎣6  7  8⎦
⎡1  2  3  4⎤
⎣5  6  7  8⎦
log1p:
⎡0.00000000  0.69314718⎤
⎣1.09861229  1.38629436⎦

func NewFunctionTransformer

func NewFunctionTransformer(f, invf func(X, Y *mat.Dense) (X1, Y1 *mat.Dense)) *FunctionTransformer

NewFunctionTransformer ...

func (*FunctionTransformer) Fit

func (m *FunctionTransformer) Fit(X, Y mat.Matrix) base.Fiter

Fit ...

func (*FunctionTransformer) FitTransform

func (m *FunctionTransformer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*FunctionTransformer) InverseTransform

func (m *FunctionTransformer) InverseTransform(X, Y *mat.Dense) (X1, Y1 *mat.Dense)

InverseTransform ...

func (*FunctionTransformer) Transform

func (m *FunctionTransformer) Transform(X, Y mat.Matrix) (X1, Y1 *mat.Dense)

Transform ...

func (*FunctionTransformer) TransformerClone

func (m *FunctionTransformer) TransformerClone() base.Transformer

TransformerClone ...

type Imputer

type Imputer struct {
	Strategy      string
	MissingValues []float64
}

Imputer ... Stragegy is mean|median|most_frequent. default to mean

Example

Code:

var nan = math.NaN()
X := mat.NewDense(5, 2, []float64{1, 2, 3, 4, nan, 6, 7, 8, 7, 10})
fmt.Println("replacing X.At(2,0) with...")
for _, s := range []string{"mean", "median", "most_frequent"} {

	X1, _ := (&Imputer{Strategy: s}).FitTransform(X, nil)
	fmt.Printf("%s\n%g\n", s, mat.Formatted(X1))

}
// additional example adapted from http://scikit-learn.org/stable/modules/preprocessing.html#imputation-of-missing-values
imp := NewImputer()
imp.Fit(mat.NewDense(3, 2, []float64{1, 2, nan, 3, 7, 6}), nil)
X = mat.NewDense(3, 2, []float64{nan, 2, 6, nan, 7, 6})
X1, _ := imp.Transform(X, nil)
fmt.Printf("imputation-of-missing-values:\n%g\n", mat.Formatted(X1))
replacing X.At(2,0) with...
mean
⎡  1    2⎤
⎢  3    4⎥
⎢4.5    6⎥
⎢  7    8⎥
⎣  7   10⎦
median
⎡ 1   2⎤
⎢ 3   4⎥
⎢ 3   6⎥
⎢ 7   8⎥
⎣ 7  10⎦
most_frequent
⎡ 1   2⎤
⎢ 3   4⎥
⎢ 7   6⎥
⎢ 7   8⎥
⎣ 7  10⎦
imputation-of-missing-values:
⎡                 4                   2⎤
⎢                 6  3.6666666666666665⎥
⎣                 7                   6⎦

func NewImputer

func NewImputer() *Imputer

NewImputer ...

func (*Imputer) Fit

func (m *Imputer) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for Imputer ...

func (*Imputer) FitTransform

func (m *Imputer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*Imputer) InverseTransform

func (m *Imputer) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform for Imputer ...

func (*Imputer) Transform

func (m *Imputer) Transform(Xmatrix, Ymatrix mat.Matrix) (Xout, Yout *mat.Dense)

Transform for Imputer ...

func (*Imputer) TransformerClone

func (m *Imputer) TransformerClone() base.Transformer

TransformerClone ...

type InverseTransformer

type InverseTransformer interface {
	Transformer
	InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)
}

InverseTransformer is a transformer able to inverse his tranformation

type KBinsDiscretizer

type KBinsDiscretizer struct {
	NBins    int
	Encode   string
	Strategy string
	BinEdges [][]float64
}

KBinsDiscretizer structure Encode = "onehot-dense","ordinal" Strategy = "quantile","uniform","kmeans"

Example

Code:

// example from https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.KBinsDiscretizer.html#sklearn.preprocessing.KBinsDiscretizer.fit
X := mat.NewDense(4, 4, []float64{
	-2, 1, -4, -1,
	-1, 2, -3, -0.5,
	0, 3, -2, 0.5,
	1, 4, -1, 2})
est := NewKBinsDiscretizer(3)
est.Encode = "ordinal"
est.Strategy = "uniform"
Xt, _ := est.FitTransform(X, nil)
fmt.Printf("Xt:\n%g\n", mat.Formatted(Xt))
fmt.Printf("est.BinEdges[0]:\n%g\n", est.BinEdges[0])
Xinv, _ := est.InverseTransform(Xt, nil)
fmt.Printf("est.InverseTransform(Xt):\n%g\n", mat.Formatted(Xinv))
Xt:
⎡0  0  0  0⎤
⎢1  1  1  0⎥
⎢2  2  2  1⎥
⎣2  2  2  2⎦
est.BinEdges[0]:
[-2 -1 0 1]
est.InverseTransform(Xt):
⎡-1.5   1.5  -3.5  -0.5⎤
⎢-0.5   2.5  -2.5  -0.5⎥
⎢ 0.5   3.5  -1.5   0.5⎥
⎣ 0.5   3.5  -1.5   1.5⎦

func NewKBinsDiscretizer

func NewKBinsDiscretizer(NBins int) *KBinsDiscretizer

NewKBinsDiscretizer returns a discretizer with Encode="onehot-dense" ans strategy="quantile"

func (*KBinsDiscretizer) Fit

func (m *KBinsDiscretizer) Fit(X, Y mat.Matrix) base.Fiter

Fit fits the transformer

func (*KBinsDiscretizer) FitTransform

func (m *KBinsDiscretizer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fitts the data then transforms it

func (*KBinsDiscretizer) InverseTransform

func (m *KBinsDiscretizer) InverseTransform(X mat.Matrix, Y mat.Mutable) (Xout, Yout *mat.Dense)

InverseTransform transforms discretized data back to original feature space.

func (*KBinsDiscretizer) Transform

func (m *KBinsDiscretizer) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform discretizes the Data

func (*KBinsDiscretizer) TransformerClone

func (m *KBinsDiscretizer) TransformerClone() Transformer

TransformerClone ...

type KernelCenterer

type KernelCenterer struct {
	KFitAll  float64
	KFitRows []float64
}

KernelCenterer Center a kernel matrix

Example

Code:

K := mat.NewDense(3, 3, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9})
kc := NewKernelCenterer()
kc.Fit(K, nil)
K1, _ := kc.Transform(K, nil)
fmt.Printf("KFitRows:%.3f\n", kc.KFitRows)
fmt.Printf("KFitAll:%.3f\n", kc.KFitAll)
fmt.Printf("Centered:\n%.3f\n", mat.Formatted(K1))
	KFitRows:[4.000 5.000 6.000]
KFitAll:5.000
Centered:
⎡0.000  0.000  0.000⎤
⎢0.000  0.000  0.000⎥
⎣0.000  0.000  0.000⎦

func NewKernelCenterer

func NewKernelCenterer() *KernelCenterer

NewKernelCenterer ...

func (*KernelCenterer) Fit

func (m *KernelCenterer) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for KernelCenterer ...

func (*KernelCenterer) FitTransform

func (m *KernelCenterer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*KernelCenterer) Transform

func (m *KernelCenterer) Transform(Xmatrix, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for KernelCenterer ...

func (*KernelCenterer) TransformerClone

func (m *KernelCenterer) TransformerClone() base.Transformer

TransformerClone ...

type LabelBinarizer

type LabelBinarizer struct {
	NegLabel, PosLabel float64
	Classes            [][]float64
}

LabelBinarizer Binarize labels in a one-vs-all fashion

Example

Code:

X, Y := (*mat.Dense)(nil), mat.NewDense(5, 1, []float64{1, 2, 6, 4, 2})
lb := &LabelBinarizer{}
lb.Fit(X, Y)
fmt.Println(lb.Classes)

_, Yout := lb.Transform(nil, mat.NewDense(2, 1, []float64{1, 6}))
fmt.Println(mat.Formatted(Yout))
_, Y2 := lb.InverseTransform(nil, Yout)
fmt.Println(mat.Formatted(Y2.T()))
[[1 2 4 6]]
⎡1  0  0  0⎤
⎣0  0  0  1⎦
[1  6]

func NewLabelBinarizer

func NewLabelBinarizer(NegLabel, PosLabel float64) *LabelBinarizer

NewLabelBinarizer ...

func (*LabelBinarizer) Fit

func (m *LabelBinarizer) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for binarizer register classes

func (*LabelBinarizer) FitTransform

func (m *LabelBinarizer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*LabelBinarizer) InverseTransform

func (m *LabelBinarizer) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform for LabelBinarizer

func (*LabelBinarizer) Transform

func (m *LabelBinarizer) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for LabelBinarizer

func (*LabelBinarizer) TransformerClone

func (m *LabelBinarizer) TransformerClone() base.Transformer

TransformerClone ...

type LabelEncoder

type LabelEncoder struct {
	Classes [][]float64
	Support [][]float64
}

LabelEncoder Encode labels with value between 0 and n_classes-1.

Example

Code:

// adapted from http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html#sklearn.preprocessing.LabelEncoder
le := NewLabelEncoder()
Y := mat.NewDense(4, 1, []float64{1, 2, 2, 6})
le.Fit(nil, Y)
fmt.Println(le.Classes)
_, Y1 := le.Transform(nil, mat.NewDense(4, 1, []float64{1, 1, 2, 6}))
fmt.Println(mat.Formatted(Y1.T()))
_, Y2 := le.InverseTransform(nil, mat.NewDense(4, 1, []float64{0, 0, 1, 2}))
fmt.Println(mat.Formatted(Y2.T()))
[[1 2 6]]
[0  0  1  2]
[1  1  2  6]

func NewLabelEncoder

func NewLabelEncoder() *LabelEncoder

NewLabelEncoder ...

func (*LabelEncoder) Fit

func (m *LabelEncoder) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for LabelEncoder ...

func (*LabelEncoder) FitTransform

func (m *LabelEncoder) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*LabelEncoder) InverseTransform

func (m *LabelEncoder) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform for LabelEncoder ...

func (*LabelEncoder) PartialFit

func (m *LabelEncoder) PartialFit(X, Y *mat.Dense) base.Transformer

PartialFit for LabelEncoder ...

func (*LabelEncoder) Transform

func (m *LabelEncoder) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for LabelEncoder ...

func (*LabelEncoder) TransformerClone

func (m *LabelEncoder) TransformerClone() base.Transformer

TransformerClone ...

type MaxAbsScaler

type MaxAbsScaler struct {
	Scale, MaxAbs []float64
	NSamplesSeen  int
}

MaxAbsScaler ...

Example

Code:

mas := NewMaxAbsScaler()
X0 := mat.NewDense(2, 3, []float64{1, 2, 0, 3, -4, 0})
X1, _ := mas.FitTransform(X0, nil)
X2, _ := mas.InverseTransform(X1, nil)
fmt.Println("MaxAbs", mas.MaxAbs)
fmt.Println("Scale ", mas.Scale)
fmt.Printf("Scaled:\n%g\n", mat.Formatted(X1))
fmt.Printf("Unscaled:\n%g\n", mat.Formatted(X2))
	MaxAbs [3 4 0]
Scale  [3 4 1]
Scaled:
⎡0.3333333333333333                 0.5                   0⎤
⎣                 1                  -1                   0⎦
Unscaled:
⎡ 1   2   0⎤
⎣ 3  -4   0⎦

func NewMaxAbsScaler

func NewMaxAbsScaler() *MaxAbsScaler

NewMaxAbsScaler ...

func (*MaxAbsScaler) Fit

func (m *MaxAbsScaler) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for MaxAbsScaler ...

func (*MaxAbsScaler) FitTransform

func (m *MaxAbsScaler) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*MaxAbsScaler) InverseTransform

func (m *MaxAbsScaler) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform for MaxAbsScaler ...

func (*MaxAbsScaler) PartialFit

func (m *MaxAbsScaler) PartialFit(X, Y *mat.Dense) base.Transformer

PartialFit for MaxAbsScaler ...

func (*MaxAbsScaler) Transform

func (m *MaxAbsScaler) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for MaxAbsScaler ...

func (*MaxAbsScaler) TransformerClone

func (m *MaxAbsScaler) TransformerClone() base.Transformer

TransformerClone ...

type MinMaxScaler

type MinMaxScaler struct {
	FeatureRange                            []float
	Scale, Min, DataMin, DataMax, DataRange *mat.Dense
	NSamplesSeen                            int
}

MinMaxScaler rescale data between FeatureRange

Example

Code:

// adapted from http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html#sklearn.preprocessing.MinMaxScaler
data := mat.NewDense(4, 2, []float64{-1., 2, -.5, 6, 0, 10, 1, 18})
scaler := NewMinMaxScaler([]float64{0, 1})
scaler.Fit(data, nil)
fmt.Println(mat.Formatted(scaler.DataMax))
X1, _ := scaler.Transform(data, nil)
fmt.Println(mat.Formatted(X1))
X2, _ := scaler.Transform(mat.NewDense(1, 2, []float64{2, 2}), nil)
fmt.Println(mat.Formatted(X2))
[ 1  18]
⎡   0     0⎤
⎢0.25  0.25⎥
⎢ 0.5   0.5⎥
⎣   1     1⎦
[1.5    0]

func NewMinMaxScaler

func NewMinMaxScaler(featureRange []float) *MinMaxScaler

NewMinMaxScaler creates an *MinMaxScaler with FeatureRange 0..1

func (*MinMaxScaler) Fit

func (scaler *MinMaxScaler) Fit(X, Y mat.Matrix) base.Fiter

Fit computes Sale and Min

func (*MinMaxScaler) FitTransform

func (scaler *MinMaxScaler) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*MinMaxScaler) InverseTransform

func (scaler *MinMaxScaler) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform rescale data into original bounds

func (*MinMaxScaler) PartialFit

func (scaler *MinMaxScaler) PartialFit(Xmatrix, Ymatrix mat.Matrix) Transformer

PartialFit updates Scale and Min with partial data

func (*MinMaxScaler) Reset

func (scaler *MinMaxScaler) Reset() *MinMaxScaler

Reset resets scaler to its initial state

func (*MinMaxScaler) Transform

func (scaler *MinMaxScaler) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform applies scaling to X

func (*MinMaxScaler) TransformerClone

func (scaler *MinMaxScaler) TransformerClone() base.Transformer

TransformerClone ...

type MultiLabelBinarizer

type MultiLabelBinarizer struct {
	Classes []interface{}

	Less func(i, j int) bool
}

MultiLabelBinarizer Transform between iterable of iterables and a multilabel format

Example

Code:

mlb := NewMultiLabelBinarizer()

fmt.Println("NewMultiLabelBinarizer matrix test")
Y0 := mat.NewDense(2, 2, []float64{1, 3, 2, 3})
_, Y1 := mlb.FitTransform(nil, Y0)
fmt.Println(mat.Formatted(Y1))
fmt.Println("Classes", mlb.Classes)
_, Y2 := mlb.InverseTransform(nil, Y1)
fmt.Println(mat.Formatted(Y2.(*mat.Dense)))

fmt.Println("NewMultiLabelBinarizer string test")
_, Y1 = mlb.FitTransform2(nil, [][]string{{"sci-fi", "thriller"}, {"comedy", "comedy"}})
fmt.Println(mat.Formatted(Y1))
fmt.Println("Classes", mlb.Classes)
_, Y2s := mlb.InverseTransform(nil, Y1)
fmt.Println(Y2s)
NewMultiLabelBinarizer matrix test
⎡1  0  0  0  0  1⎤
⎣0  1  0  0  0  1⎦
Classes [1 2 3]
⎡1  3⎤
⎣2  3⎦
NewMultiLabelBinarizer string test
⎡0  1  0  0  0  1⎤
⎣1  0  0  1  0  0⎦
Classes [comedy sci-fi thriller]
[[sci-fi thriller] [comedy comedy]]

func NewMultiLabelBinarizer

func NewMultiLabelBinarizer() *MultiLabelBinarizer

NewMultiLabelBinarizer ...

func (*MultiLabelBinarizer) Fit

func (m *MultiLabelBinarizer) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for MultiLabelBinarizer ... if Y is [][]string, use Fit2. this one is only to satisfy Transformer interface

func (*MultiLabelBinarizer) Fit2

func (m *MultiLabelBinarizer) Fit2(X mat.Matrix, Y interface{}) *MultiLabelBinarizer

Fit2 for MultiLabelBinarizer ... Y type can be *mat.Dense | [][]string

func (*MultiLabelBinarizer) FitTransform

func (m *MultiLabelBinarizer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*MultiLabelBinarizer) FitTransform2

func (m *MultiLabelBinarizer) FitTransform2(X mat.Matrix, Y interface{}) (Xout, Yout *mat.Dense)

FitTransform2 can take a [][]string in Y

func (*MultiLabelBinarizer) InverseTransform

func (m *MultiLabelBinarizer) InverseTransform(X, Y *mat.Dense) (Xout *mat.Dense, Yout interface{})

InverseTransform for MultiLabelBinarizer ... Yout type is same as the one passed int Fit

func (*MultiLabelBinarizer) Transform

func (m *MultiLabelBinarizer) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for MultiLabelBinarizer ... Y type must be the same passed int Fit

func (*MultiLabelBinarizer) Transform2

func (m *MultiLabelBinarizer) Transform2(X mat.Matrix, Y interface{}) (Xout, Yout *mat.Dense)

Transform2 handles Y types ùmat.dense and [][]string

func (*MultiLabelBinarizer) TransformerClone

func (m *MultiLabelBinarizer) TransformerClone() base.Transformer

TransformerClone ...

type Normalizer

type Normalizer struct {
	Norm string
	Axis int
	// contains filtered or unexported fields
}

Normalizer Normalize samples individually to unit norm. Norm is l1|l2|max. l2 by default

Example

Code:

// adapted from example in http://scikit-learn.org/stable/modules/preprocessing.html#normalization
X := mat.NewDense(3, 3, []float64{
	1, -1, 2,
	2, 0, 0,
	0, 1, -1})
Xnormalized, _ := NewNormalizer().FitTransform(X, nil)
fmt.Printf("%.3f\n", mat.Formatted(Xnormalized))
⎡ 0.408  -0.408   0.816⎤
⎢ 1.000   0.000   0.000⎥
⎣ 0.000   0.707  -0.707⎦

func NewNormalizer

func NewNormalizer() *Normalizer

NewNormalizer returns a normaliser with Norm l2 and axis 1

func (*Normalizer) Fit

func (m *Normalizer) Fit(X, Y mat.Matrix) base.Fiter

Fit for Normalizer ...

func (*Normalizer) FitTransform

func (m *Normalizer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*Normalizer) InverseTransform

func (m *Normalizer) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform for Normalizer ...

func (*Normalizer) Transform

func (m *Normalizer) Transform(Xmatrix, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for Normalizer ...

func (*Normalizer) TransformerClone

func (m *Normalizer) TransformerClone() base.Transformer

TransformerClone ...

type NumpyLike

type NumpyLike struct{}

NumpyLike is a namespace for numpy-like var and std

func (NumpyLike) Std

func (m NumpyLike) Std(X mat.Matrix) *mat.Dense

Std for NumpyLike

func (NumpyLike) Var

func (NumpyLike) Var(X mat.Matrix) *mat.Dense

Var for NumpyLike

type OneHotEncoder

type OneHotEncoder struct {
	NValues, FeatureIndices []int
	Values                  [][]float64
}

OneHotEncoder Encode categorical integer features using a one-hot aka one-of-K scheme.

Example

Code:

// adapted from example in http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html#sklearn.preprocessing.OneHotEncoder
enc := NewOneHotEncoder()
X, Y := mat.NewDense(4, 3, []float64{0, 0, 3, 1, 1, 0, 0, 2, 1, 1, 0, 2}), (*mat.Dense)(nil)
enc.Fit(X, Y)
fmt.Println(enc.NValues)
fmt.Println(enc.FeatureIndices)
X0 := mat.NewDense(1, 3, []float64{0, 1, 1})
X1, _ := enc.Transform(X0, nil)
fmt.Println(mat.Formatted(X1))
X2, _ := enc.InverseTransform(X1, nil)
fmt.Println(mat.Formatted(X2))
[2 3 4]
[0 2 5 9]
[1  0  0  1  0  0  1  0  0]
[0  1  1]

func NewOneHotEncoder

func NewOneHotEncoder() *OneHotEncoder

NewOneHotEncoder creates a *OneHotEncoder

func (*OneHotEncoder) Fit

func (m *OneHotEncoder) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit ...

func (*OneHotEncoder) FitTransform

func (m *OneHotEncoder) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*OneHotEncoder) InverseTransform

func (m *OneHotEncoder) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform compute Yout classes from one hot encoded format

func (*OneHotEncoder) Transform

func (m *OneHotEncoder) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform transform Y labels to one hot encoded format

func (*OneHotEncoder) TransformerClone

func (m *OneHotEncoder) TransformerClone() base.Transformer

TransformerClone ...

type PCA

type PCA struct {
	mat.SVD
	MinVarianceRatio                       float64
	NComponents                            int
	SingularValues, ExplainedVarianceRatio []float64
}

PCA is a thin single value decomposition transformer

Example

Code:

X := mat.NewDense(6, 2, []float64{-1., -1., -2., -1., -3., -2., 1., 1., 2., 1., 3., 2.})
pca := NewPCA()
pca.Fit(X, nil)
Xp, _ := pca.Transform(X, nil)
fmt.Printf("explained  : %.3f\n", pca.ExplainedVarianceRatio)
fmt.Printf("Svalues    : %.3f\n", pca.SingularValues)
fmt.Printf("transformed: %.3f\n", Xp.RawMatrix().Data)
X2, _ := pca.InverseTransform(Xp, nil)
fmt.Printf("inversed   : %.3f\n", X2.RawMatrix().Data)
//expected:=[-1.383405778728807 0.293578697080941
// -2.221898016633681 -0.2513348437429921
// -3.605303795362488 0.04224385333794878
// 1.383405778728807 -0.293578697080941
// 2.221898016633681 0.2513348437429921
// 3.605303795362488 -0.04224385333794878]
explained  : [0.992 0.008]
Svalues    : [6.301 0.550]
transformed: [-1.383 0.294 -2.222 -0.251 -3.605 0.042 1.383 -0.294 2.222 0.251 3.605 -0.042]
inversed   : [-1.000 -1.000 -2.000 -1.000 -3.000 -2.000 1.000 1.000 2.000 1.000 3.000 2.000]

func NewPCA

func NewPCA() *PCA

NewPCA returns a *PCA

func (*PCA) Fit

func (m *PCA) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit computes the svd of X

func (*PCA) FitTransform

func (m *PCA) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*PCA) InverseTransform

func (m *PCA) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform put X into original space

func (*PCA) Transform

func (m *PCA) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform Transforms X

func (*PCA) TransformerClone

func (m *PCA) TransformerClone() base.Transformer

TransformerClone ...

type PolynomialFeatures

type PolynomialFeatures struct {
	Degree                       int
	InteractionOnly, IncludeBias bool
	Powers                       [][]int
}

PolynomialFeatures struct

func NewPolynomialFeatures

func NewPolynomialFeatures(degree int) *PolynomialFeatures

NewPolynomialFeatures creates a *PolynomialFeatures

func (*PolynomialFeatures) Fit

func (poly *PolynomialFeatures) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit precompute Powers Powers[i, j] is the exponent of the jth input in the ith output.

func (*PolynomialFeatures) FitTransform

func (poly *PolynomialFeatures) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*PolynomialFeatures) InverseTransform

func (poly *PolynomialFeatures) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform inverse tranformation for PolynomialFeatures.

func (*PolynomialFeatures) Transform

func (poly *PolynomialFeatures) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform returns data with polynomial features added

func (*PolynomialFeatures) TransformerClone

func (poly *PolynomialFeatures) TransformerClone() base.Transformer

TransformerClone ...

type PowerTransformer

type PowerTransformer struct {
	Method      string
	Standardize bool

	Lambdas []float64
	Scaler  *StandardScaler
}

PowerTransformer apply a power transform featurewise to make data more Gaussian-like TODO support boxcox

Example

Code:

pt := NewPowerTransformer()
data := mat.NewDense(3, 2, []float64{
	1, 2,
	3, 2,
	4, 5,
})
Xout, _ := pt.FitTransform(data, nil)

fmt.Printf("lambdas: %.4f\n", pt.Lambdas)
fmt.Printf("transformed:\n%.4f\n", mat.Formatted(Xout))
Xinv, _ := pt.InverseTransform(Xout, nil)
fmt.Printf("inverse transformed:\n%.4f\n", mat.Formatted(Xinv))
lambdas: [1.3867 -3.1005]
transformed:
⎡-1.3162  -0.7071⎤
⎢ 0.2100  -0.7071⎥
⎣ 1.1062   1.4142⎦
inverse transformed:
⎡1.0000  2.0000⎤
⎢3.0000  2.0000⎥
⎣4.0000  5.0000⎦
Example (Boxcox)

Code:

pt := NewPowerTransformer()
pt.Method = "box-cox"
data := mat.NewDense(3, 2, []float64{
	1, 2,
	3, 2,
	4, 5,
})
Xout, _ := pt.FitTransform(data, nil)

fmt.Printf("lambdas: %.4f\n", pt.Lambdas)
fmt.Printf("transformed:\n%.4f\n", mat.Formatted(Xout))
Xinv, _ := pt.InverseTransform(Xout, nil)
fmt.Printf("inverse transformed:\n%.4f\n", mat.Formatted(Xinv))
lambdas: [1.0517 -2.3455]
transformed:
⎡-1.3327  -0.7071⎤
⎢ 0.2565  -0.7071⎥
⎣ 1.0762   1.4142⎦
inverse transformed:
⎡1.0000  2.0000⎤
⎢3.0000  2.0000⎥
⎣4.0000  5.0000⎦

func NewPowerTransformer

func NewPowerTransformer() *PowerTransformer

NewPowerTransformer returns a PowerTransformer with method yeo-johnson and standardize=true

func (*PowerTransformer) Fit

func (m *PowerTransformer) Fit(X, Y mat.Matrix) base.Fiter

Fit Estimate the optimal parameter lambda for each feature. The optimal lambda parameter for minimizing skewness is estimated on each feature independently using maximum likelihood.

func (*PowerTransformer) FitTransform

func (m *PowerTransformer) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fits the data then transforms it

func (*PowerTransformer) InverseTransform

func (m *PowerTransformer) InverseTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

InverseTransform apply the inverse power transformation using the fitted lambdas. The inverse of the Box-Cox transformation is given by::

if lambda == 0:
	X = exp(X_trans)
else:
	X = (X_trans * lambda + 1) ** (1 / lambda)

The inverse of the Yeo-Johnson transformation is given by::

if X >= 0 and lambda == 0:
	X = exp(X_trans) - 1
elif X >= 0 and lambda != 0:
	X = (X_trans * lambda + 1) ** (1 / lambda) - 1
elif X < 0 and lambda != 2:
	X = 1 - (-(2 - lambda) * X_trans + 1) ** (1 / (2 - lambda))
elif X < 0 and lambda == 2:
	X = 1 - exp(-X_trans)

func (*PowerTransformer) Transform

func (m *PowerTransformer) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform apply the power transform to each feature using the fitted lambdas

func (*PowerTransformer) TransformerClone

func (m *PowerTransformer) TransformerClone() base.Transformer

TransformerClone allow duplication

type QuantilePair

type QuantilePair struct {
	Left  float64
	Right float64
}

QuantilePair represents bounds of quantile

type QuantileTransformer

type QuantileTransformer struct {
	NQuantiles         int
	Subsample          int
	OutputDistribution string
	RandomState        rand.Source

	Quantiles mat.Matrix
	// contains filtered or unexported fields
}

QuantileTransformer Transform features using quantiles information.

Example

Code:

// works approximately. results are not exact. need a pass in the other way. Avoid use
type NormFloat64er interface{ NormFloat64() float64 }
var rng rand.Source = base.NewSource(0)
normal := func(loc, scale float64, n int) []float64 {
	data := make([]float64, n)
	for i := range data {
		data[i] = loc + scale*rng.(NormFloat64er).NormFloat64()
	}
	return data
}
X := mat.NewDense(25, 1, normal(.5, .25, 25))
sort.Float64s(X.RawMatrix().Data)

qt := NewQuantileTransformer(10, "uniform", rng)
qt.Fit(X, nil)
fmt.Printf("X=%.8f\n", mat.Formatted(X.T()))
fmt.Printf("references=%.8f\n", qt.references)
fmt.Printf("quantiles=%.8f\n", qt.Quantiles.T().(*mat.Dense).RawRowView(0))
Xout, _ := qt.Transform(X, nil)
fmt.Printf("transformed=%.8f\n", mat.Formatted(Xout.T()))

tol := 1e-8
expected := []float64{0.00000010, 0.09871873, 0.10643612, 0.11754671, 0.21017437,
	0.21945445, 0.23498666, 0.32443642, 0.33333333, 0.41360794,
	0.42339464, 0.46257841, 0.47112236, 0.49834237, 0.59986536,
	0.63390302, 0.66666667, 0.68873101, 0.69611125, 0.81280699,
	0.82160354, 0.88126439, 0.90516028, 0.99319435, 0.99999990}
for i := range expected {
	if math.Abs(Xout.At(i, 0)-expected[i]) > tol {
		fmt.Printf("at %d expected %.8f, got %.8f\n", i, expected[i], Xout.At(i, 0))
	}
}
X=[-0.13824745   0.25568053   0.28647607   0.31445874   0.44871043   0.46216070   0.47419529   0.53041875   0.53601089   0.57826693   0.58341858   0.60003930   0.60264963   0.61096581   0.66340465   0.69025943   0.71610905   0.73752210   0.74468450   0.86356838   0.87351977   0.94101309   0.96688950   1.06022330   1.06743866]
references=[0.00000000 0.11111111 0.22222222 0.33333333 0.44444444 0.55555556 0.66666667 0.77777778 0.88888889 1.00000000]
quantiles=[-0.13824745 0.30513118 0.46617223 0.53601089 0.59449906 0.62844542 0.71610905 0.82394042 0.94963856 1.06743866]
transformed=[0.00000010  0.09871873  0.10643612  0.11754671  0.21017437  0.21945445  0.23498666  0.32443642  0.33333333  0.41360794  0.42339464  0.46257841  0.47112236  0.49834237  0.59986536  0.63390302  0.66666667  0.68873101  0.69611125  0.81280699  0.82160354  0.88126439  0.90516028  0.99319435  0.99999990]

func NewQuantileTransformer

func NewQuantileTransformer(NQuantiles int, outputDistribution string, RandomState rand.Source) *QuantileTransformer

NewQuantileTransformer returns a new QuantileTransformer

func (*QuantileTransformer) Fit

func (m *QuantileTransformer) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for QuantileTransformer retain X or a part of it

func (*QuantileTransformer) FitTransform

func (m *QuantileTransformer) FitTransform(Xmatrix, Ymatrix mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to data, then transforms it

func (*QuantileTransformer) Transform

func (m *QuantileTransformer) Transform(Xmatrix, Ymatrix mat.Matrix) (Xout, Yout *mat.Dense)

Transform for QuantileTransformer returns Quantiles of X in Xout

func (*QuantileTransformer) TransformerClone

func (m *QuantileTransformer) TransformerClone() Transformer

TransformerClone ...

type RobustScaler

type RobustScaler struct {
	Center          bool
	Scale           bool
	Quantiles       *QuantilePair
	Median          *mat.Dense
	Tmp             *mat.Dense
	QuantileDivider *mat.Dense
}

RobustScaler scales data by removing centering around the Median and removing outliers by Quantile. See python sklearn's RobustScaler http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.RobustScaler.html.

Example

Code:

m := NewRobustScaler(true, false, nil)
X := mat.NewDense(3, 3, []float64{1, 4, 7, 3, 2, 8, 9, 1, 1})
//correctY := mat.NewDense(3, 3, []float64{-2, 2, 0, 0, 0, 1, 6, -1, -6})
X1, _ := m.FitTransform(X, nil)
fmt.Printf("centered:\n%g\n", mat.Formatted(X1))

m = NewRobustScaler(false, true, nil) // Use default (0.25, 0.75)
X = mat.NewDense(8, 1, []float64{9, 10, 12, 13, 19, 20, 21, 22})
X1, _ = m.FitTransform(X, nil)
fmt.Printf("quantiles:\n%g\n", mat.Formatted(X1))
centered:
⎡-2   2   0⎤
⎢ 0   0   1⎥
⎣ 6  -1  -6⎦
quantiles:
⎡0.9⎤
⎢  1⎥
⎢1.2⎥
⎢1.3⎥
⎢1.9⎥
⎢  2⎥
⎢2.1⎥
⎣2.2⎦

func NewDefaultRobustScaler

func NewDefaultRobustScaler() *RobustScaler

NewDefaultRobustScaler supplies typical arguments (via python sklearn)

func NewRobustScaler

func NewRobustScaler(center bool, scale bool, quantiles *QuantilePair) *RobustScaler

NewRobustScaler creates a *RobustScaler

func (*RobustScaler) Fit

func (scaler *RobustScaler) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit computes Median and Quantiles

func (*RobustScaler) FitTransform

func (scaler *RobustScaler) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*RobustScaler) InverseTransform

func (scaler *RobustScaler) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform unscales data

func (*RobustScaler) PartialFit

func (scaler *RobustScaler) PartialFit(Xmatrix, Ymatrix mat.Matrix) Transformer

PartialFit computes Median and Quantiles

func (*RobustScaler) Reset

func (scaler *RobustScaler) Reset() *RobustScaler

Reset ...

func (*RobustScaler) Transform

func (scaler *RobustScaler) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform scales data

func (*RobustScaler) TransformerClone

func (scaler *RobustScaler) TransformerClone() base.Transformer

TransformerClone ...

type Shuffler

type Shuffler struct {
	Perm        []int
	RandomState base.Source
}

Shuffler shuffles rows of X and Y

Example

Code:

X, Y := mat.NewDense(2, 3, []float64{1, 2, 3, 4, 5, 6}), mat.NewDense(2, 3, []float64{7, 8, 9, 10, 11, 12})
m := NewShuffler()
m.RandomState = base.NewSource(7)
X1, Y1 := m.FitTransform(X, Y)

fmt.Println("Transformed:")
fmt.Printf("%s", base.MatStr(X1, Y1))
X2, Y2 := m.InverseTransform(X1, Y1)
fmt.Println("InverseTransformed:")
fmt.Printf("%s", base.MatStr(X2, Y2))
Transformed:
4	5	6	10	11	12
1	2	3	7	8	9
InverseTransformed:
1	2	3	7	8	9
4	5	6	10	11	12

func NewShuffler

func NewShuffler() *Shuffler

NewShuffler returns a *Shuffler

func (*Shuffler) Fit

func (m *Shuffler) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for Shuffler

func (*Shuffler) FitTransform

func (m *Shuffler) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*Shuffler) InverseTransform

func (m *Shuffler) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform for Shuffler

func (*Shuffler) Transform

func (m *Shuffler) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for Shuffler

func (*Shuffler) TransformerClone

func (m *Shuffler) TransformerClone() base.Transformer

TransformerClone ...

type StandardScaler

type StandardScaler struct {
	WithMean, WithStd bool
	Scale, Mean, Var  *mat.Dense
	NSamplesSeen      int
}

StandardScaler scales data by removing Mean and dividing by stddev

Example

Code:

// adapted from example in http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html#sklearn.preprocessing.StandardScaler
data := mat.NewDense(4, 2, []float64{0, 0, 0, 0, 1, 1, 1, 1})
scaler := NewStandardScaler()
scaler.Fit(data, nil)
fmt.Println(mat.Formatted(scaler.Mean))
X1, _ := scaler.Transform(data, nil)
fmt.Println(mat.Formatted(X1))
X2, _ := scaler.Transform(mat.NewDense(1, 2, []float64{2, 2}), nil)
fmt.Println(mat.Formatted(X2))
X3, _ := scaler.InverseTransform(mat.NewDense(1, 2, []float64{3, 3}), nil)
fmt.Println(mat.Formatted(X3))
[0.5  0.5]
⎡-1  -1⎤
⎢-1  -1⎥
⎢ 1   1⎥
⎣ 1   1⎦
[3  3]
[2  2]

func NewStandardScaler

func NewStandardScaler() *StandardScaler

NewStandardScaler creates a *StandardScaler

func (*StandardScaler) Fit

func (scaler *StandardScaler) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit computes Mean snd Std

func (*StandardScaler) FitTransform

func (scaler *StandardScaler) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*StandardScaler) InverseTransform

func (scaler *StandardScaler) InverseTransform(X, Y *mat.Dense) (Xout, Yout *mat.Dense)

InverseTransform unscales data

func (*StandardScaler) PartialFit

func (scaler *StandardScaler) PartialFit(X, Y *mat.Dense) Transformer

PartialFit computes Mean and Std

func (*StandardScaler) Reset

func (scaler *StandardScaler) Reset() *StandardScaler

Reset ...

func (*StandardScaler) Transform

func (scaler *StandardScaler) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform scales data

func (*StandardScaler) TransformerClone

func (scaler *StandardScaler) TransformerClone() base.Transformer

TransformerClone ...

type Transformer

type Transformer = base.Transformer

Transformer is an interface for various preprocessors

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier