lineargo: github.com/lazywei/lineargo Index | Files

package lineargo

import "github.com/lazywei/lineargo"

Index

Package Files

constants.go libsvm_reader.go linear.go utils.go

Constants

const (
    // Solver Type
    L2R_LR              = int(C.L2R_LR)
    L2R_L2LOSS_SVC_DUAL = int(C.L2R_L2LOSS_SVC_DUAL)
    L2R_L2LOSS_SVC      = int(C.L2R_L2LOSS_SVC)
    L2R_L1LOSS_SVC_DUAL = int(C.L2R_L1LOSS_SVC_DUAL)
    MCSVM_CS            = int(C.MCSVM_CS)
    L1R_L2LOSS_SVC      = int(C.L1R_L2LOSS_SVC)
    L1R_LR              = int(C.L1R_LR)
    L2R_LR_DUAL         = int(C.L2R_LR_DUAL)
    L2R_L2LOSS_SVR      = int(C.L2R_L2LOSS_SVR)
    L2R_L2LOSS_SVR_DUAL = int(C.L2R_L2LOSS_SVR_DUAL)
    L2R_L1LOSS_SVR_DUAL = int(C.L2R_L1LOSS_SVR_DUAL)
)

func Accuracy Uses

func Accuracy(y_true, y_pred *mat64.Dense) float64

func Predict Uses

func Predict(model *Model, X *mat64.Dense) *mat64.Dense

double predict(const struct model *model_, const struct feature_node *x);

func PredictProba Uses

func PredictProba(model *Model, X *mat64.Dense) *mat64.Dense

double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates);

func ReadLibsvm Uses

func ReadLibsvm(filepath string, oneBased bool) (X, y *mat64.Dense)

ReadLibsvm reads libsvm format data from `filepath`. `oneBased` denotes the index of data stored in the file starts from 1 (`oneBased=true`) or 0 (`oneBased=false`). Returned X, y is of dimension (nSamples, nFeatures) and (nSamples, 1) respectively.

func SaveModel Uses

func SaveModel(model *Model, filename string)

type Model Uses

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

Model contains a pointer to C's struct model (i.e., `*C.struct_model`). It is returned after training and used for predicting.

func LoadModel Uses

func LoadModel(filename string) *Model

func Train Uses

func Train(X, y *mat64.Dense, bias float64, solverType int, c_, p, eps float64, classWeights map[int]float64) *Model

Wrapper for the `train` function in liblinear.

`model* train(const struct problem *prob, const struct parameter *param);`

The explanation of parameters are:

solverType:

for multi-class classification
       0 -- L2-regularized logistic regression (primal)
       1 -- L2-regularized L2-loss support vector classification (dual)
       2 -- L2-regularized L2-loss support vector classification (primal)
       3 -- L2-regularized L1-loss support vector classification (dual)
       4 -- support vector classification by Crammer and Singer
       5 -- L1-regularized L2-loss support vector classification
       6 -- L1-regularized logistic regression
       7 -- L2-regularized logistic regression (dual)
for regression
      11 -- L2-regularized L2-loss support vector regression (primal)
      12 -- L2-regularized L2-loss support vector regression (dual)
      13 -- L2-regularized L1-loss support vector regression (dual)

eps is the stopping criterion.

C_ is the cost of constraints violation.

p is the sensitiveness of loss of support vector regression.

classWeights is a map from int to float64, with the key be the class and the value be the weight. For example, {1: 10, -1: 0.5} means giving weight=10 for class=1 while weight=0.5 for class=-1

If you do not want to change penalty for any of the classes, just set classWeights to nil.

Package lineargo imports 9 packages (graph). Updated 2017-08-04. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).