model

package
v0.0.0-...-4560c35 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const AccuracyCol = "Accuracy"

AccuracyCol is the Error column name

View Source
const CorrectCol = "Correct"

CorrectCol i th Correct column name

View Source
const DefaultScoreHistory = 3
View Source
const ErrorCol = "Error"

ErrorCol is the Error column name

View Source
const F1ScoreCol = "F1score"

F1ScoreCol is the F1score column name

View Source
const IterationCol = "Iteration"

IterationCol is the Iteration column name

View Source
const LabelCol = "Label"

LabelCol is the default name of column containing a training label

View Source
const LossCol = "Loss"

LossCol is the Loss column name

View Source
const MaeCol = "Mae"

MaeCol is the Mean of Absolute Error column name

View Source
const PrecisionCol = "Precision"

PrecisionCol is the Precision column name

View Source
const PredictedCol = "Predicted"

PredictedCol is the default name of column containing a result of prediction

View Source
const RmseCol = "Rmse"

RmseCol is the Root Mean fo Squared Error column name

View Source
const SensitivityCol = "Sensitivity"

SensitivityCol is the Sensitivity column name

View Source
const SubsetCol = "Subset"

SubsetCol is the Subset column naime

View Source
const TestCol = "Test"

TestCol is the default name of Test column containing a boolean flag

View Source
const TestSubset = "test"

TestSubset is the Subset column item value for test rows

View Source
const TotalCol = "Total"

TotalCol is the Total column name

View Source
const TrainSubset = "train"

TrainSubset is the Subset column item value for train rows

Variables

This section is empty.

Functions

func Accuracy

func Accuracy(lr fu.Struct) float64

Accuracy of an ML algorithm, has a value in the interval [0,1]

func AccuracyScore

func AccuracyScore(train, test fu.Struct) float64

AccuracyScore scores accuracy in interval [0,1], Greater is better

func BatchUpdateMetrics

func BatchUpdateMetrics(result, label *tables.Column, mu MetricsUpdater)

BatchUpdateMetrics updates metrics for a batch of training results

func Error

func Error(lr fu.Struct) float64

Error of an ML algorithm, can have any value

func ErrorScore

func ErrorScore(train, test fu.Struct) float64

ErrorScore scores error in interval [0,1], Greater is better

func Evaluate

func Evaluate(source tables.AnyData, label string, m PredictionModel, batchsize int, metricsf Metrics) (lr fu.Struct, err error)

Evaluate metrics of the given source with the prediction model

func Loss

func Loss(lr fu.Struct) float64

Loss is the maen of the ML algorithm loss function. It can have any float value

func LossScore

func LossScore(train, test fu.Struct) float64

LossScore scores loss in interval [0,1], Greater is better

func LuckyEvaluate

func LuckyEvaluate(source tables.AnyData, label string, m PredictionModel, batchsize int, metricsf Metrics) fu.Struct

LuckyEvaluate is the same as Evaluate function with handling error as a panic

func Memorize

func Memorize(output iokit.Output, m MemorizeMap) error

Memorize writes models directory to single output

func Objectify

func Objectify(input iokit.Input, m ObjectifyMap) (pm map[string]PredictionModel, err error)

Objectify reads and reconstructs prediction models from a directory

Types

type Classification

type Classification struct {
	Accuracy   float64 // accuracy goal
	Error      float64 // error goal
	Confidence float32 // threshold for binary classification
}

Classification metrics factory

func (Classification) Names

func (m Classification) Names() []string

Names is the list of calculating metrics

func (Classification) New

func (m Classification) New(iteration int, subset string) MetricsUpdater

New metrics updater for the given iteration and subset

type CollectionWriter

type CollectionWriter struct {
	// contains filtered or unexported fields
}

CollectionWriter is an abstraction of a collection creator

func (*CollectionWriter) Add

func (c *CollectionWriter) Add(name string, write func(io.Writer) error) error

Add an element to collection

func (*CollectionWriter) AddLzma2

func (c *CollectionWriter) AddLzma2(name string, write func(io.Writer) error) error

Add an Lzma2 compressed element to collection

type Dataset

type Dataset struct {
	Source   tables.AnyData // It can be tables.Table or lazy stream of mlutil.Struct objects
	Label    string         // name of float32/Tensor field containing label to train
	Test     string         // name of boolean field to select test data
	Features []string       // patterns of feature names to train model or predict
}

Dataset is an abstraction of some source of a data to feed hungry models

type FatModel

type FatModel func(workout Workout) (*Report, error)

FatModel is fattened model (a training function of model instance bounded to a dataset)

func (FatModel) LuckyTrain

func (f FatModel) LuckyTrain(training UnifiedTraining) *Report

LuckyTrain trains fattened (Fat) model and trows any occurred errors as a panic

func (FatModel) Train

func (f FatModel) Train(training UnifiedTraining) (*Report, error)

Train a fattened (Fat) model

type GpuPredictionModel

type GpuPredictionModel interface {
	PredictionModel
	// Gpu changes context of prediction backend to gpu enabled
	// it's a recommendation only, if GPU is not available or it's impossible to use it
	// the cpu will be used instead
	Gpu(...int) PredictionModel
}

GpuPredictionModel is a prediction interface able to use GPU

type HungryModel

type HungryModel interface {
	Feed(Dataset) FatModel
}

HungryModel is an ML algorithm grows from a data to predict something Needs to be fattened by Feed method to fit.

type MemorizeMap

type MemorizeMap map[string]Mnemosyne

MemorizeMap maps names of models in directory to Mnemosyne abstraction

type Metrics

type Metrics interface {
	New(iteration int, subset string) MetricsUpdater
	Names() []string
}

Metrics interface

type MetricsUpdater

type MetricsUpdater interface {
	// updates metrics with prediction result and label
	// loss is an optional and can be used in LossScore on the training
	Update(result, label reflect.Value, loss float64)
	Complete() (fu.Struct, bool)
}

MetricsUpdater interface

type Mnemosyne

type Mnemosyne interface {
	Memorize(*CollectionWriter) error
}

Mnemosyne is a Serialization interface for an ML model parts

type ModelStash

type ModelStash struct {
	// contains filtered or unexported fields
}

func NewStash

func NewStash(histlen int, pattern string) *ModelStash

func (*ModelStash) Close

func (ms *ModelStash) Close() error

func (*ModelStash) Length

func (ms *ModelStash) Length() int

func (*ModelStash) Output

func (ms *ModelStash) Output(iteration int) (out iokit.Output, err error)

func (*ModelStash) Reader

func (ms *ModelStash) Reader(iteration int) (rd io.Reader, err error)

type ObjectifyMap

type ObjectifyMap map[string]func(map[string]iokit.Input) (PredictionModel, error)

ObjectifyMap mpas names of models in directory to objectification functions

type PredictionModel

type PredictionModel interface {
	// Features model uses when maps features
	// the same as Features in the training dataset
	Features() []string
	// Column name model adds to result table when maps features.
	// By default it's 'Predicted'
	Predicted() string
	// Returns new table with all original columns except features
	// adding one new column with prediction
	FeaturesMapper(batchSize int) (tables.FeaturesMapper, error)
}

PredictionModel is a predictor interface

type Regression

type Regression struct {
	Error float64 // error goal
}

Regression - the regression metrics factory

func (Regression) Names

func (m Regression) Names() []string

Names is the list of calculating metrics

func (Regression) New

func (m Regression) New(iteration int, subset string) MetricsUpdater

New iteration metrics

type Report

type Report struct {
	History     *tables.Table // all iterations history
	TheBest     int           // the best iteration
	Test, Train fu.Struct     // the best iteration metrics
	Score       float64       // the best score
}

Report is an ML training report

type Score

type Score func(train, test fu.Struct) float64

Score is the type of function calculating a metrics score

type Training

type Training struct {
	Iterations   int          // maximum iterations
	Metrics      Metrics      // evaluating metrics
	Score        Score        // score function
	ScoreHistory int          // possible count of forehead training with lower score
	ModelFile    iokit.Output // file to store final model
}

Training is the default implementation of unified training interface

func (Training) Workout

func (t Training) Workout() Workout

type UnifiedTraining

type UnifiedTraining interface {
	// Workout returns the first iteration workout
	Workout() Workout
}

UnifiedTraining is an interface allowing to write any logging/staging backend for ML training

type Workout

type Workout interface {
	Iteration() int
	TrainMetrics() MetricsUpdater
	TestMetrics() MetricsUpdater
	Complete(m MemorizeMap, train, test fu.Struct, metricsDone bool) (*Report, bool, error)
	Next() Workout
}

Workout is a training iteration abstraction

Directories

Path Synopsis
Package hyperopt implements SMBO/TPE hyper-parameter optimization for ML models Many thanks to Masashi SHIBATA for his excellent work on goptuna I used github.com/c-bata/goptuna as a reference implementation for the paper 'Algorithms for Hyper-Parameter Optimization' https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf TPE sampler mostly derived from goptuna.
Package hyperopt implements SMBO/TPE hyper-parameter optimization for ML models Many thanks to Masashi SHIBATA for his excellent work on goptuna I used github.com/c-bata/goptuna as a reference implementation for the paper 'Algorithms for Hyper-Parameter Optimization' https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf TPE sampler mostly derived from goptuna.

Jump to

Keyboard shortcuts

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