Documentation ¶
Index ¶
- Variables
- func ClassesFromProbs(p *mat.Dense) *mat.Dense
- func JSONMultiClass(m *MultiClass, activationfunctionname string, w writestringer) error
- func LogOddsFromProbs(m *mat.Dense) *mat.Dense
- func MarshalMCMetaData(m *MultiClass, probtransformname string) ([]byte, error)
- func SubSample(totdata int, subsample float64) []int
- type Feats
- type JSONMetaData
- type MultiClass
- func (M *MultiClass) Accuracy(D *utils.DataBunch, classes ...int) float64
- func (M *MultiClass) ClassLabels() []int
- func (M *MultiClass) Classes() int
- func (M *MultiClass) FeatureImportance() (*Feats, error)
- func (M *MultiClass) PredictSingle(instance []float64, predictions ...[]float64) []float64
- func (M *MultiClass) PredictSingleClass(instance []float64, predictions ...[]float64) int
- func (M *MultiClass) Rounds(class ...int) int
- type Options
- type Tree
- func (T *Tree) Branches() int
- func (T *Tree) FeatureImportance(xgboost bool, gains ...*Feats) (*Feats, error)
- func (t *Tree) JNode(id uint, addsamples ...bool) *utils.JSONNode
- func (T *Tree) Leaf() bool
- func (T *Tree) Leftf(l utils.JTree) utils.JTree
- func (T *Tree) Predict(data [][]float64, preds []float64) []float64
- func (T *Tree) PredictSingle(row []float64) float64
- func (T *Tree) Print(spacing string, featurenames ...[]string) string
- func (T *Tree) Rightf(r utils.JTree) utils.JTree
- type TreeOptions
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ClassesFromProbs ¶
given an nxm matrix p, where n is the number of samples and n is the number of classes, and each element i,j is the probability of sample i of being in class j, returns a nx1 column matrix where each element corresponds to the most likely class for sample i (i.e., for each row, the column in the original matrix with the largest value.
func JSONMultiClass ¶
func JSONMultiClass(m *MultiClass, activationfunctionname string, w writestringer) error
Marshals a multi-class classifier to JSON. probtransformname is the name of the activation function, normally, "softmax", w is any object with a WriteString(string)(int,error) method, normally, a *bufio.Writer.
func LogOddsFromProbs ¶
Obtains the Log of the odds for a nxm matrix where each element i,j is the probability of the samble i to belong to class j.
func MarshalMCMetaData ¶
func MarshalMCMetaData(m *MultiClass, probtransformname string) ([]byte, error)
Types ¶
type Feats ¶
type Feats struct {
// contains filtered or unexported fields
}
Feats represents a set of features and their associated gains in a tree Implements sort.Sort, so the features can be sorted by gain.
type JSONMetaData ¶
type MultiClass ¶
type MultiClass struct {
// contains filtered or unexported fields
}
MultiClass is a multi-class gradient-boosted (xgboost or "regular") classification ensemble.
func NewMultiClass ¶
func NewMultiClass(D *utils.DataBunch, opts ...*Options) *MultiClass
Produces (and fits) a new multi-class classification boosted tree ensamble It will be of xgboost type if xgboost is true, regular gradient boosting othewise.
func UnJSONMultiClass ¶
func UnJSONMultiClass(r *bufio.Reader) (*MultiClass, error)
func (*MultiClass) Accuracy ¶
func (M *MultiClass) Accuracy(D *utils.DataBunch, classes ...int) float64
Returns the percentage of accuracy of the model on the data (which needs to contain labels). You can give it the number of classes present, which helps with memory.
func (*MultiClass) ClassLabels ¶
func (M *MultiClass) ClassLabels() []int
func (*MultiClass) Classes ¶
func (M *MultiClass) Classes() int
Returns the number of classes, i.e. the number of categories to which each data vector could belong.
func (*MultiClass) FeatureImportance ¶
func (M *MultiClass) FeatureImportance() (*Feats, error)
Returns the features ranked by their "importance" to the classification.
func (*MultiClass) PredictSingle ¶
func (M *MultiClass) PredictSingle(instance []float64, predictions ...[]float64) []float64
Returns a slice with the probability of the sample belonging to each class. You can supply a slice to be filled with the predictions in order to avoid allocation.
func (*MultiClass) PredictSingleClass ¶
func (M *MultiClass) PredictSingleClass(instance []float64, predictions ...[]float64) int
Predicts the class to which a single sample belongs. You can give a slice of floats to use as temporal storage for the probabilities that are used to assign the class
func (*MultiClass) Rounds ¶
func (M *MultiClass) Rounds(class ...int) int
Returns the number of "rounds" per class, in the given class, or, if no argument is given, in the first one (the rounds might not be all the same in all classes) ir the class index given is out of range, Rounds returns -1.
type Options ¶
type Options struct { XGB bool Rounds int MaxDepth int EarlyStop int //roundw without increased fit before we stop trying. LearningRate float64 Lambda float64 MinChildWeight float64 Gamma float64 SubSample float64 ColSubSample float64 BaseScore float64 MinSample int //the minimum samples in each tree TreeMethod string // EarlyStopRounds int //stop after n consecutive rounds of no improvement. Not implemented yet. Verbose bool Loss utils.LossFunc }
Contain options to create a multi-class classification ensamble.
func DefaultGOptions ¶
func DefaultGOptions() *Options
Returns a pointer to an Options structure with the default options a for regular gradient boosting multi-class classification ensamble.
func DefaultOptions ¶
func DefaultOptions() *Options
func DefaultXOptions ¶
func DefaultXOptions() *Options
Returns a pointer to an Options structure with the default values for an XGBoost multi-class classification ensamble.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
A tree, both for regular gradient boosting and for xgboost
func NewTree ¶
func NewTree(X [][]float64, o *TreeOptions) *Tree
Returns a new tree for the data X and options o
func (*Tree) FeatureImportance ¶
Returns a string with a list of the features, in descending order of importance, and their scores.
func (*Tree) Predict ¶
Predicts a value for each data vector. If preds is not nil, predicted values are stored there.
func (*Tree) PredictSingle ¶
Predicts a value for a single data vector.
func (*Tree) Print ¶
Returns a text representation of the tree (uses several lines) This function is heavily based on the equivalent from https://github.com/sjwhitworth/golearn
type TreeOptions ¶
type TreeOptions struct { Debug bool XGB bool MinChildWeight float64 AllowedColumns []int //for column sub-sampling, by tree Lambda float64 Gamma float64 ColSampleByNode float64 //not used Gradients []float64 Hessian []float64 Y []float64 MaxDepth int Indexes []int // contains filtered or unexported fields }
TreeOptions contains the options for a particular tree
func DefaultGTreeOptions ¶
func DefaultGTreeOptions() *TreeOptions
Returns the default options for a "regular" (not "extreme") boosting tree
func DefaultXTreeOptions ¶
func DefaultXTreeOptions() *TreeOptions
Returns the default options for an extreme boosting tree