Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
Phpml\Classification\DecisionTree Class Reference
Inheritance diagram for Phpml\Classification\DecisionTree:
Phpml\Classification\Classifier Phpml\Estimator

Public Member Functions

 __construct (int $maxDepth=10)
 
 getFeatureImportances ()
 This will return an array including an importance value for each column in the given dataset.
 
 getGiniIndex ($baseValue, array $colValues, array $targets)
 
 getHtml ()
 
 predict (array $samples)
 
 setColumnNames (array $names)
 A string array to represent columns.
 
 setNumFeatures (int $numFeatures)
 This method is used to set number of columns to be used when deciding a split at an internal node of the tree.
 
 train (array $samples, array $targets)
 

Static Public Member Functions

static getColumnTypes (array $samples)
 

Public Attributes

int $actualDepth = 0
 
const CONTINUOUS = 1
 
const NOMINAL = 2
 

Protected Member Functions

 getBestSplit (array $records)
 
 getSelectedFeatures ()
 Returns available features/columns to the tree for the decision making process.
 
 getSplitLeaf (array $records, int $depth=0)
 
 getSplitNodesByColumn (int $column, DecisionTreeLeaf $node)
 Collects and returns an array of internal nodes that use the given column as a split criterion.
 
 predictSample (array $sample)
 
 preprocess (array $samples)
 
 setSelectedFeatures (array $selectedFeatures)
 Used to set predefined features to consider while deciding which column to use for a split.
 

Static Protected Member Functions

static isCategoricalColumn (array $columnValues)
 

Protected Attributes

array $columnTypes = []
 
int $maxDepth
 
DecisionTreeLeaf $tree
 

Member Function Documentation

◆ getFeatureImportances()

Phpml\Classification\DecisionTree::getFeatureImportances ( )

This will return an array including an importance value for each column in the given dataset.

The importance values are normalized and their total makes 1.

◆ getGiniIndex()

Phpml\Classification\DecisionTree::getGiniIndex ( $baseValue,
array $colValues,
array $targets )
Parameters
mixed$baseValue

◆ getSelectedFeatures()

Phpml\Classification\DecisionTree::getSelectedFeatures ( )
protected

Returns available features/columns to the tree for the decision making process.


If a number is given with setNumFeatures() method, then a random selection of features up to this number is returned.

If some features are manually selected by use of setSelectedFeatures(), then only these features are returned

If any of above methods were not called beforehand, then all features are returned by default.

◆ predict()

Phpml\Estimator::predict ( array $samples)
inherited

Implemented in Phpml\Pipeline.

◆ predictSample()

Phpml\Classification\DecisionTree::predictSample ( array $sample)
protected
Return values
mixed

◆ setColumnNames()

Phpml\Classification\DecisionTree::setColumnNames ( array $names)

A string array to represent columns.

Useful when HTML output or column importances are desired to be inspected.

Return values
$this
Exceptions
InvalidArgumentException

◆ setNumFeatures()

Phpml\Classification\DecisionTree::setNumFeatures ( int $numFeatures)

This method is used to set number of columns to be used when deciding a split at an internal node of the tree.


If the value is given 0, then all features are used (default behaviour), otherwise the given value will be used as a maximum for number of columns randomly selected for each split operation.

Return values
$this
Exceptions
InvalidArgumentException

◆ train()

Phpml\Classification\DecisionTree::train ( array $samples,
array $targets )

Implements Phpml\Estimator.


The documentation for this class was generated from the following file: