gini

package
v0.53.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package gini contain function to calculating Gini gain.

Gini gain, which is an impurity-based criterion that measures the divergences between the probability distribution of the target attributes' values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMaxGain

func FindMaxGain(gains *[]Gini) (maxGainIdx int)

FindMaxGain find the attribute and value that have the maximum gain. The returned value is index of attribute.

func FindMinGiniIndex

func FindMinGiniIndex(ginis *[]Gini) (minIndexIdx int)

FindMinGiniIndex return the index of attribute that have the minimum Gini index.

Types

type Gini

type Gini struct {
	// SortedIndex of attribute, sorted by values of attribute. This will
	// be used to reference the unsorted target attribute.
	SortedIndex []int

	// ContinuPart contain list of partition value for continuous attribute.
	ContinuPart []float64

	// DiscretePart contain the possible combination of discrete values.
	DiscretePart libstrings.Table

	// Index contain list of Gini Index for each partition.
	Index []float64

	// Gain contain information gain for each partition.
	Gain []float64

	// MaxGainValue contain maximum gain of index.
	MaxGainValue float64

	// MinIndexGini contain minimum Gini index value.
	MinIndexValue float64

	// Value of Gini index for all value in attribute.
	Value float64

	// MaxPartGain contain the index of partition which have the maximum
	// gain.
	MaxPartGain int

	// MinIndexPart contain the index of partition which have the minimum
	// Gini index.
	MinIndexPart int

	// Skip if its true, the gain value would not be searched on this
	// instance.
	Skip bool

	// IsContinue define whether the Gini index came from continuous
	// attribute or not.
	IsContinu bool
}

Gini contain slice of sorted index, slice of partition values, slice of Gini index, Gini value for all samples.

func (*Gini) ComputeContinu

func (gini *Gini) ComputeContinu(src *[]float64, target, classes *[]string)

ComputeContinu Given an attribute "src" and the target attribute "target" which contain n classes, compute the information gain of "src".

The result of Gini partitions value, Gini Index, and Gini Gain is saved in ContinuPart, Index, and Gain.

func (*Gini) ComputeContinuFloat

func (gini *Gini) ComputeContinuFloat(src, target, classes *[]float64)

ComputeContinuFloat Given an attribute A and the target attribute T which contain N classes in C, compute the information gain of A.

The result of Gini partitions value, Gini Index, and Gini Gain is saved in ContinuPart, Index, and Gain.

Algorithm, (0) Sort the attribute. (1) Sort the target attribute using sorted index. (2) Create continu partition. (3) Create temporary space for gini index and gini gain. (4) Compute gini index for all target.

func (*Gini) ComputeDiscrete

func (gini *Gini) ComputeDiscrete(src, discval, target, classes *[]string)

ComputeDiscrete Given an attribute "src" with discrete value 'discval', and the target attribute "target" which contain n classes, compute the information gain of "src".

The result is saved as gain value in MaxGainValue for each partition.

func (*Gini) GetMaxGainValue

func (gini *Gini) GetMaxGainValue() float64

GetMaxGainValue return the value of partition which contain the maximum Gini gain.

func (*Gini) GetMaxPartGainValue

func (gini *Gini) GetMaxPartGainValue() interface{}

GetMaxPartGainValue return the partition that have the maximum Gini gain.

func (*Gini) GetMinIndexPartValue

func (gini *Gini) GetMinIndexPartValue() interface{}

GetMinIndexPartValue return the partition that have the minimum Gini index.

func (*Gini) GetMinIndexValue

func (gini *Gini) GetMinIndexValue() float64

GetMinIndexValue return the minimum Gini index value.

func (Gini) String

func (gini Gini) String() (s string)

String yes, it will print it JSON like format.

Jump to

Keyboard shortcuts

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