Skip to content

DecisionTreeClassifier

Defined in: ds/src/ml/estimators/DecisionTree.js:537

Extends

  • Classifier

Constructors

Constructor

new DecisionTreeClassifier(opts?): DecisionTreeClassifier

Defined in: ds/src/ml/estimators/DecisionTree.js:538

Parameters

opts?

Returns

DecisionTreeClassifier

Overrides

Classifier.constructor

Properties

_state

_state: object

Defined in: ds/src/core/estimators/estimator.js:27

Inherited from

Classifier._state


_warnings

_warnings: any[]

Defined in: ds/src/core/estimators/estimator.js:29

Inherited from

Classifier._warnings


classes_

classes_: any

Defined in: ds/src/core/estimators/estimator.js:515

Inherited from

GAMClassifier.classes_


fitted

fitted: boolean

Defined in: ds/src/core/estimators/estimator.js:25

Inherited from

Classifier.fitted


labelEncoder_

labelEncoder_: any

Defined in: ds/src/core/estimators/estimator.js:514

Inherited from

GAMClassifier.labelEncoder_


params

params: any

Defined in: ds/src/core/estimators/estimator.js:24

Inherited from

Classifier.params


tree

tree: DecisionTreeBase

Defined in: ds/src/ml/estimators/DecisionTree.js:540

Accessors

featureImportances

Get Signature

get featureImportances(): number[]

Defined in: ds/src/ml/estimators/DecisionTree.js:597

Get feature importances

Returns

number[]

Methods

_accuracy()

_accuracy(yTrue, yPred): number

Defined in: ds/src/core/estimators/estimator.js:644

Parameters

yTrue

any

yPred

any

Returns

number

Inherited from

Classifier._accuracy


_decodeLabels()

_decodeLabels(predictions): any[]

Defined in: ds/src/core/estimators/estimator.js:606

Decode numeric predictions to original labels

Parameters

predictions

any[]

Numeric predictions or label strings

Returns

any[]

Decoded labels (or original if no encoder)

Inherited from

Classifier._decodeLabels


_extractLabelEncoder()

_extractLabelEncoder(prepared): boolean

Defined in: ds/src/core/estimators/estimator.js:541

Extract and store label encoder from prepared data

Parameters

prepared

any

Result from prepareXY/prepareDataset

Returns

boolean

True if encoder was found and stored

Inherited from

Classifier._extractLabelEncoder


_getClasses()

_getClasses(preparedY, onlyPresentClasses?): any

Defined in: ds/src/core/estimators/estimator.js:563

Get unique classes from labels (encoded or raw) If labelEncoder exists, preparedY is assumed to be numeric indices [0, 1, 2, …] Otherwise, creates classes from unique values in preparedY

Parameters

preparedY

any[]

Label array (numeric if encoded, or raw labels)

onlyPresentClasses?

boolean = true

If true, only return classes present in preparedY

Returns

any

{ numericY, classes }

Inherited from

Classifier._getClasses


_prepareArgsForFit()

_prepareArgsForFit(args?): { columns?: undefined; columnsX: any[]; prepared: boolean; raw?: undefined; rows: any[]; X: any[][]; y: any[]; } | { columns: any[]; columnsX?: undefined; prepared: boolean; raw?: undefined; rows: any[]; X: any[][]; y?: undefined; } | { columns?: undefined; columnsX?: undefined; prepared?: undefined; raw: any[]; rows?: undefined; X?: undefined; y?: undefined; }

Defined in: ds/src/core/estimators/estimator.js:367

Convenience helper: parse arguments passed to fit/predict/transform.

Supports declarative table-style inputs:

  • fit({ X, y, data, omit_missing })
  • fit({ data, columns, … })

Returns an object { X, y, prepared, rows } where X/y are numeric arrays if preparation was required, otherwise returns the original values.

Note: this helper only prepares numeric matrices/vectors using core table utilities; it does not perform encoding of categorical predictors.

Parameters

args?

any[] = []

Returns

{ columns?: undefined; columnsX: any[]; prepared: boolean; raw?: undefined; rows: any[]; X: any[][]; y: any[]; } | { columns: any[]; columnsX?: undefined; prepared: boolean; raw?: undefined; rows: any[]; X: any[][]; y?: undefined; } | { columns?: undefined; columnsX?: undefined; prepared?: undefined; raw: any[]; rows?: undefined; X?: undefined; y?: undefined; }

Inherited from

Classifier._prepareArgsForFit


_repr_html_()

_repr_html_(): string

Defined in: ds/src/core/estimators/estimator.js:201

Observable/Jupyter HTML representation

Returns

string

HTML representation

Inherited from

Classifier._repr_html_


apply()

apply(X): number[]

Defined in: ds/src/ml/estimators/DecisionTree.js:602

Apply tree to X, return leaf indices

Parameters

X

any

Returns

number[]


clearWarnings()

clearWarnings(): void

Defined in: ds/src/core/estimators/estimator.js:139

Clear all warnings

Returns

void

Inherited from

Classifier.clearWarnings


decisionPath()

decisionPath(X): any[][]

Defined in: ds/src/ml/estimators/DecisionTree.js:607

Return decision path

Parameters

X

any

Returns

any[][]


exportText()

exportText(featureNames?): string

Defined in: ds/src/ml/estimators/DecisionTree.js:627

Export tree as ASCII text

Parameters

featureNames?

any = null

Returns

string


exportTree()

exportTree(featureNames?, classNames?): string

Defined in: ds/src/ml/estimators/DecisionTree.js:622

Export tree to DOT format

Parameters

featureNames?

any = null

classNames?

any = null

Returns

string


fit()

fit(X, y?): DecisionTreeClassifier

Defined in: ds/src/ml/estimators/DecisionTree.js:549

Fit the classifier on training data.

Parameters

X

any

Feature matrix (n samples × p features), or a declarative options object ({ data, X/columns, y, … }).

y?

number[] | string[]

Class labels; omitted when using the declarative form.

Returns

DecisionTreeClassifier

The fitted estimator (for chaining).

Overrides

Classifier.fit


getDepth()

getDepth(): number

Defined in: ds/src/ml/estimators/DecisionTree.js:612

Get maximum depth of tree

Returns

number


getMemoryUsage()

getMemoryUsage(): string

Defined in: ds/src/core/estimators/estimator.js:97

Get memory usage in human-readable format

Returns

string

Memory usage string (e.g., “2.3 MB” or “145 KB”)

Inherited from

Classifier.getMemoryUsage


getNLeaves()

getNLeaves(): number

Defined in: ds/src/ml/estimators/DecisionTree.js:617

Get number of leaves

Returns

number


getParams()

getParams(): any

Defined in: ds/src/core/estimators/estimator.js:294

Get a shallow copy of parameters.

Returns

any

Inherited from

Classifier.getParams


getState()

getState(): any

Defined in: ds/src/core/estimators/estimator.js:65

Get comprehensive model state

Returns

any

State information including fitted status, memory estimate, warnings

Inherited from

Classifier.getState


getWarnings()

getWarnings(): any[]

Defined in: ds/src/core/estimators/estimator.js:124

Get all warnings

Returns

any[]

Array of warning objects

Inherited from

Classifier.getWarnings


getWarningsByType()

getWarningsByType(type): any[]

Defined in: ds/src/core/estimators/estimator.js:148

Get warnings of a specific type

Parameters

type

string

Warning type

Returns

any[]

Filtered warnings

Inherited from

Classifier.getWarningsByType


hasWarnings()

hasWarnings(): boolean

Defined in: ds/src/core/estimators/estimator.js:132

Check if model has warnings

Returns

boolean

Inherited from

Classifier.hasWarnings


isFitted()

isFitted(): boolean

Defined in: ds/src/core/estimators/estimator.js:36

Check if model is fitted

Returns

boolean

Inherited from

Classifier.isFitted


predict()

predict(X): number[] | string[]

Defined in: ds/src/ml/estimators/DecisionTree.js:574

Predict class labels for each sample.

Parameters

X

any

Feature matrix, or a declarative options object ({ data, X/columns, … }).

Returns

number[] | string[]

Predicted class labels (decoded to original label types).

Overrides

Classifier.predict


predictProba()

predictProba(X): any

Defined in: ds/src/ml/estimators/DecisionTree.js:580

Predict probabilities - subclasses should override Ensures model is fitted before prediction

Parameters

X

any

Returns

any

Overrides

Classifier.predictProba


save()

save(): string

Defined in: ds/src/core/estimators/estimator.js:329

Save model to JSON string

Returns

string

JSON representation of the model

Inherited from

Classifier.save


score()

score(yTrueOrOpts, yPred, _opts?, …args?): number

Defined in: ds/src/core/estimators/estimator.js:622

Default accuracy scoring:

  • score(yTrue, yPred)
  • or score({ X, y, data }) which predicts internally

Parameters

yTrueOrOpts

any

yPred

any

_opts?
args?

any[] = {}

Returns

number

Inherited from

Classifier.score


setParams()

setParams(params?): DecisionTreeClassifier

Defined in: ds/src/core/estimators/estimator.js:285

Set parameters (mutates instance).

Parameters

params?

any = {}

Returns

DecisionTreeClassifier

Inherited from

Classifier.setParams


toJSON()

toJSON(): object

Defined in: ds/src/core/estimators/estimator.js:302

Serialize minimal model metadata. Subclasses may override to include learned parameters.

Returns

object

fitted

fitted: boolean

params

params: any

state

state: object

warnings

warnings: any[]

Inherited from

Classifier.toJSON


transform()

transform(): void

Defined in: ds/src/core/estimators/estimator.js:431

Transform should be implemented by transformers.

Returns

void

Inherited from

Classifier.transform


fromJSON()

static fromJSON(obj?): Estimator

Defined in: ds/src/core/estimators/estimator.js:317

Basic deserialization. Subclasses should override if they need to restore learned arrays / matrices.

Parameters

obj?

any = {}

Returns

Estimator

Inherited from

Classifier.fromJSON


load()

static load(jsonString): Estimator

Defined in: ds/src/core/estimators/estimator.js:346

Load model from JSON string

Parameters

jsonString

string

JSON representation

Returns

Estimator

Reconstructed estimator instance

Inherited from

Classifier.load