Documentation ¶
Overview ¶
Package linear_models implements linear and logistic regression models.
Index ¶
- Constants
- Variables
- func Export(model *Model, filePath string) error
- func Load(model *Model, filePath string) error
- func Predict(model *Model, x []float64) float64
- type LinearRegression
- type LinearSVC
- func (lr *LinearSVC) Fit(X base.FixedDataGrid) error
- func (lr *LinearSVC) GetMetadata() base.ClassifierMetadataV1
- func (lr *LinearSVC) Load(filePath string) error
- func (lr *LinearSVC) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
- func (lr *LinearSVC) Predict(X base.FixedDataGrid) (base.FixedDataGrid, error)
- func (lr *LinearSVC) Save(filePath string) error
- func (lr *LinearSVC) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
- func (lr *LinearSVC) String() string
- type LinearSVCParams
- type LogisticRegression
- type Model
- type Parameter
- type Problem
Constants ¶
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 ¶
var ( NotEnoughDataError = errors.New("not enough rows to support this many variables.") NoTrainingDataError = errors.New("you need to Fit() before you can Predict()") )
Functions ¶
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 ¶
func (lr *LinearRegression) Predict(X base.FixedDataGrid) (base.FixedDataGrid, error)
type LinearSVC ¶
type LinearSVC struct { Param *LinearSVCParams // contains filtered or unexported fields }
LinearSVC represents a linear support-vector classifier.
func NewLinearSVC ¶
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) 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) SaveWithPrefix ¶
func (lr *LinearSVC) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
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 (lr *LogisticRegression) Fit(X base.FixedDataGrid) error
func (*LogisticRegression) Predict ¶
func (lr *LogisticRegression) Predict(X base.FixedDataGrid) (base.FixedDataGrid, error)
func (*LogisticRegression) String ¶
func (lr *LogisticRegression) String() string