pipeline

package
Version: v0.0.0-...-beb861e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NamedStep

type NamedStep struct {
	Name string
	base.Fiter
}

NamedStep represents a pipeline named Step Step must be Predicter (last step) or Transformer

type Pipeline

type Pipeline struct {
	NamedSteps []NamedStep

	NOutputs int
}

Pipeline is a sequance of transformers and an estimator

Example
randomState := rand.New(base.NewLockedSource(7))

ds := datasets.LoadBreastCancer()

scaler := preprocessing.NewStandardScaler()

pca := preprocessing.NewPCA()
pca.MinVarianceRatio = 0.995

poly := preprocessing.NewPolynomialFeatures(2)
poly.IncludeBias = false

m := nn.NewMLPClassifier([]int{}, "relu", "adam", 0)
m.RandomState = randomState
m.MaxIter = 300
m.LearningRateInit = .02
m.WeightDecay = .001

pl := MakePipeline(scaler, pca, poly, m)
// or equivalent:
pl = NewPipeline(NamedStep{"scaler", scaler}, NamedStep{"pca", pca}, NamedStep{"poly", poly}, NamedStep{"mlp", m})
// pipeline is clonable
pl = pl.PredicterClone().(*Pipeline)
// pipeline is classifier if last step is a classifier
if !pl.IsClassifier() {
	fmt.Println("shouldn't happen")
}

pl.Fit(ds.X, ds.Y)
nSamples, _ := ds.X.Dims()
_, nOutputs := ds.Y.Dims()
Ypred := mat.NewDense(nSamples, nOutputs, nil)

pl.Predict(ds.X, Ypred)
accuracy := pl.Score(ds.X, ds.Y)
fmt.Println("accuracy>0.999 ?", accuracy > 0.999)
if accuracy <= .999 {
	fmt.Println("accuracy:", accuracy)
}
// pipeline is a Transformer too
_, _ = pl.FitTransform(ds.X, ds.Y)
Output:

accuracy>0.999 ? true

func MakePipeline

func MakePipeline(steps ...base.Fiter) *Pipeline

MakePipeline returns a Pipeline from unnamed steps

func NewPipeline

func NewPipeline(steps ...NamedStep) *Pipeline

NewPipeline returns a *Pipeline

func (*Pipeline) Fit

func (p *Pipeline) Fit(Xmatrix, Ymatrix mat.Matrix) base.Fiter

Fit for Pipeline

func (*Pipeline) FitTransform

func (p *Pipeline) FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

FitTransform fit to dat, then transform it

func (*Pipeline) GetNOutputs

func (p *Pipeline) GetNOutputs() int

GetNOutputs returns output columns number for Y

func (*Pipeline) IsClassifier

func (p *Pipeline) IsClassifier() bool

IsClassifier for pipeline returns last step IsClassifier if any

func (*Pipeline) Predict

func (p *Pipeline) Predict(X mat.Matrix, Y mat.Mutable) *mat.Dense

Predict for pipeline calls steps Transform then InverseTransform for InverseTransformer steps

func (*Pipeline) PredicterClone

func (p *Pipeline) PredicterClone() base.Predicter

PredicterClone for pipeline relies on children clone method is child is Transformer

func (*Pipeline) Score

func (p *Pipeline) Score(X, Y mat.Matrix) float64

Score for pipeline

func (*Pipeline) Transform

func (p *Pipeline) Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)

Transform for pipeline

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL