linear_models

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package linear_models implements linear and logistic regression models.

Index

Constants

View Source
const (
	L2R_LR              = C.L2R_LR
	L2R_L2LOSS_SVC_DUAL = C.L2R_L2LOSS_SVC_DUAL
	L2R_L2LOSS_SVC      = C.L2R_L2LOSS_SVC
	L2R_L1LOSS_SVC_DUAL = C.L2R_L1LOSS_SVC_DUAL
	MCSVM_CS            = C.MCSVM_CS
	L1R_L2LOSS_SVC      = C.L1R_L2LOSS_SVC
	L1R_LR              = C.L1R_LR
	L2R_LR_DUAL         = C.L2R_LR_DUAL
)

Variables

View Source
var (
	NotEnoughDataError  = errors.New("not enough rows to support this many variables.")
	NoTrainingDataError = errors.New("you need to Fit() before you can Predict()")
)

Functions

func Export

func Export(model *Model, filePath string) error

func Load

func Load(model *Model, filePath string) error

func Predict

func Predict(model *Model, x []float64) float64

Types

type LinearRegression

type LinearRegression struct {
	Disturbance            float64
	RegressionCoefficients []float64
	Attrs                  []base.Attribute
	Cls                    base.Attribute
	// contains filtered or unexported fields
}

func NewLinearRegression

func NewLinearRegression() *LinearRegression

func (*LinearRegression) Fit

func (lr *LinearRegression) Fit(inst base.FixedDataGrid) error

func (*LinearRegression) Predict

type LinearSVC

type LinearSVC struct {
	Param *LinearSVCParams
	// contains filtered or unexported fields
}

LinearSVC represents a linear support-vector classifier.

func NewLinearSVC

func NewLinearSVC(loss, penalty string, dual bool, C float64, eps float64) (*LinearSVC, error)

NewLinearSVC creates a new support classifier.

loss and penalty: see LinearSVCParams#SetKindFromString

dual: see LinearSVCParams

eps: see LinearSVCParams

C: see LinearSVCParams

func NewLinearSVCFromParams

func NewLinearSVCFromParams(params *LinearSVCParams) (*LinearSVC, error)

NewLinearSVCFromParams constructs a LinearSVC from the given LinearSVCParams structure.

func (*LinearSVC) Fit

func (lr *LinearSVC) Fit(X base.FixedDataGrid) error

Fit automatically weights the class vector (if configured to do so) converts the FixedDataGrid into the right format and trains the model.

func (*LinearSVC) GetMetadata

func (lr *LinearSVC) GetMetadata() base.ClassifierMetadataV1

func (*LinearSVC) Load

func (lr *LinearSVC) Load(filePath string) error

func (*LinearSVC) LoadWithPrefix

func (lr *LinearSVC) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error

func (*LinearSVC) Predict

func (lr *LinearSVC) Predict(X base.FixedDataGrid) (base.FixedDataGrid, error)

Predict issues predictions from a trained LinearSVC.

func (*LinearSVC) Save

func (lr *LinearSVC) Save(filePath string) error

Save outputs this classifier

func (*LinearSVC) SaveWithPrefix

func (lr *LinearSVC) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error

func (*LinearSVC) String

func (lr *LinearSVC) String() string

String return a humaan-readable version.

type LinearSVCParams

type LinearSVCParams struct {
	SolverType                 int
	ClassWeights               []float64
	C                          float64
	Eps                        float64
	WeightClassesAutomatically bool
	Dual                       bool
}

LinearSVCParams represnts all available LinearSVC options.

SolverKind: can be linear_models.L2_L1LOSS_SVC_DUAL, L2R_L2LOSS_SVC_DUAL, L2R_L2LOSS_SVC, L1R_L2LOSS_SVC. It must be set via SetKindFromStrings.

ClassWeights describes how each class is weighted, and can be used in class-imabalanced scenarios. If this is nil, then all classes will be weighted the same unless WeightClassesAutomatically is True.

C is a float64 represnenting the misclassification penalty.

Eps is a float64 convergence threshold.

Dual indicates whether the solution is primary or dual.

func (*LinearSVCParams) Copy

func (p *LinearSVCParams) Copy() *LinearSVCParams

Copy return s a copy of these parameters

func (*LinearSVCParams) SetKindFromStrings

func (p *LinearSVCParams) SetKindFromStrings(loss, penalty string) error

SetKindFromStrings configures the solver kind from strings. Penalty and Loss parameters can either be l1 or l2.

type LogisticRegression

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

func NewLogisticRegression

func NewLogisticRegression(penalty string, C float64, eps float64) (*LogisticRegression, error)

func (*LogisticRegression) Fit

func (*LogisticRegression) Predict

func (*LogisticRegression) String

func (lr *LogisticRegression) String() string

type Model

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

func Train

func Train(prob *Problem, param *Parameter) *Model

type Parameter

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

func NewParameter

func NewParameter(solver_type int, C float64, eps float64) *Parameter

type Problem

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

func NewProblem

func NewProblem(X [][]float64, y []float64, bias float64) *Problem

Jump to

Keyboard shortcuts

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