API Reference
Classes
-
Estimator Minimal base Estimator
-
Regressor Regressor base class
-
Classifier Classifier base class
-
Transformer Transformer base class
-
Optimizer Base Optimizer class
-
GradientDescent Gradient Descent Optimizer (Batch and Stochastic)
-
MomentumOptimizer Momentum Optimizer
-
RMSProp RMSProp Optimizer
-
AdamOptimizer Adam Optimizer (Adaptive Moment Estimation)
-
LabelEncoder Simple Label Encoder for categorical labels -> integers
-
OneHotEncoder Simple OneHotEncoder for a single categorical column Note: this encoder returns an array of arrays (one-hot vectors)
-
Pipeline Pipeline class for chaining transformers and estimators
-
GridSearchCV Simple GridSearchCV for hyperparameter tuning
-
StandardScaler Standardize features by removing mean and scaling to unit variance
-
MinMaxScaler Scale features to a given range [min, max]
-
Normalizer Normalize samples individually to unit norm
-
LabelEncoder Encode target labels with value between 0 and n_classes-1
-
OneHotEncoder Encode categorical features as one-hot numeric array
-
PolynomialFeatures Generate polynomial and interaction features
Members
- seed ML utilities including seeded random number generation
Constants
-
distributions Create parameter distribution objects
-
SUPPORTED_MARKS Attach lightweight rendering helpers to plot configuration objects. Allows calling config.show(Plot) in Observable without adding direct Plot dependency.
Functions
-
toMatrix(data) ⇒
MatrixConvert array-like structure to Matrix -
solveLeastSquares(A, b) ⇒
MatrixSolve least squares problem: minimize ||Ax - b||^2 -
covarianceMatrix(data, center) ⇒
MatrixCompute covariance matrix -
svd(data) ⇒
ObjectSingular Value Decomposition -
eig(data) ⇒
ObjectEigenvalue decomposition -
mmul(A, B) ⇒
MatrixMatrix multiplication -
transpose(data) ⇒
MatrixMatrix transpose -
inverse(data) ⇒
MatrixMatrix inverse -
approxEqual(a, b, tolerance) ⇒
booleanApproximate equality comparison for floating point numbers -
guardFinite(value, name) ⇒
numberGuard against non-finite values -
guardPositive(value, name) ⇒
numberGuard against negative values -
guardProbability(value, name) ⇒
numberGuard against values outside [0, 1] -
sum(arr) ⇒
numberSum of array -
mean(arr) ⇒
numberMean of array -
variance(arr, sample) ⇒
numberVariance of array -
stddev(arr, sample) ⇒
numberStandard deviation of array -
createOptimizer(name, options) ⇒
<a href="#Optimizer">Optimizer</a>Convenience function to create optimizer by name -
saveModel(model) ⇒
stringSave model to JSON -
loadModel(json) ⇒
ObjectLoad model from JSON -
addSerializationSupport(EstimatorClass, toJSONFn) Add toJSON method to an estimator class prototype This allows models to define their own serialization logic
-
serializeValue(value) ⇒
anySerialize model to file-safe object Handles special types like undefined, Infinity, NaN -
deserializeValue(value) ⇒
anyDeserialize value from file-safe object -
makeSaveable(model) ⇒
ObjectCreate a saveable model wrapper Adds save() method to any model object -
isArqueroLike(data) ⇒
booleanCheck if input has Arquero-like interface -
normalize(data) ⇒
Array.<Object>Normalize input to array of objects -
toMatrix(data, columns) ⇒
MatrixConvert table data to matrix -
toVector(data, column) ⇒
Array.<number>Convert table column to vector -
toColumns(data, columns) ⇒
ObjectExtract multiple columns as arrays -
getColumns(data) ⇒
Array.<string>Get column names from data -
filter(data, predicate) ⇒
Array.<Object>Filter rows based on predicate -
select(data, columns) ⇒
Array.<Object>Select specific columns -
isNumeric(v) ⇒
booleanHelper: check if a value is numeric (finite number) -
isMissing(v) ⇒
booleanHelper: check if a value is considered missing -
prepareX() Prepare feature matrix X from table-like data. Supports optional categorical encoding: prepareX({ columns, data, omit_missing = true, encode = null }) encode can be:
-
null/false: no encoding (default)
-
true: auto-label encode any non-numeric columns
-
{ colName: 'label' | 'onehot' } mapping per-column
Returns: { X, columns, n, rows, encoders } where encoders is a mapping of column->encoder used
-
prepareXY() Prepare feature matrix X and response vector y from table-like data. Supports categorical encoding for X and y via
encodeoption: prepareXY({ X, y, data, omit_missing = true, encode = null }) encode semantics same as prepareX. For y, only 'label' encoding is supported (maps categories to integer class labels). Returns: { X, y, columnsX, n, rows, encoders } where encoders may include encoders.y -
featureImportance(model, X, y, scoreFn, options) ⇒
Array.<Object>Compute feature importance via permutation -
coefficientImportance(model, featureNames) ⇒
Array.<Object>Compute coefficient-based feature importance (for linear models) -
partialDependence(model, X, feature, options) ⇒
ObjectCompute partial dependence for a feature -
residualPlotData(model, X, y) ⇒
ObjectCompute residual plot data -
correlationMatrix(X, featureNames) ⇒
ObjectCompute correlation matrix -
learningCurve(fitFn, scoreFn, X, y, options) ⇒
ObjectLearning curve data (performance vs training size) -
euclideanDistance(a, b) ⇒
numberEuclidean distance between two points -
createRandomGenerator(data, k) ⇒
Array.<Array.<number>>Initialize centroids using k-means++ algorithm -
initializeCentroidsKMeansPlusPlus(data, k, random) ⇒
Array.<Array.<number>>Initialize centroids using k-means++ algorithm -
assignClusters(data, centroids) ⇒
Array.<number>Assign each point to nearest centroid -
updateCentroids(data, labels, k) ⇒
Array.<Array.<number>>Update centroids based on cluster assignments -
computeInertia(data, labels, centroids) ⇒
numberCompute within-cluster sum of squares (inertia) -
fit(X, options) ⇒
ObjectFit k-means clustering model -
predict(model, X) ⇒
Array.<number>Predict cluster labels for new data -
silhouetteScore(X, labels) ⇒
numberCompute silhouette score for clustering quality -
mseLoss(yTrue, yPred) ⇒
ObjectMean Squared Error Loss -
maeLoss(yTrue, yPred) ⇒
ObjectMean Absolute Error Loss -
logLoss(yTrue, yPred, epsilon) ⇒
ObjectBinary Cross-Entropy Loss (Log Loss) -
crossEntropy(yTrue, yPred, epsilon) ⇒
ObjectCategorical Cross-Entropy Loss -
hingeLoss(yTrue, yPred) ⇒
ObjectHinge Loss (for SVM) -
huberLoss(yTrue, yPred, delta) ⇒
ObjectHuber Loss (robust to outliers) -
getLossFunction(name) ⇒
functionGet loss function by name -
mse(yTrue, yPred) ⇒
numberMean Squared Error -
rmse(yTrue, yPred) ⇒
numberRoot Mean Squared Error -
mae(yTrue, yPred) ⇒
numberMean Absolute Error -
r2(yTrue, yPred) ⇒
numberR² (coefficient of determination) -
accuracy(yTrue, yPred) ⇒
numberAccuracy score -
confusionMatrix(yTrue, yPred) ⇒
ObjectConfusion matrix -
precision(yTrue, yPred, positiveLabel) ⇒
numberPrecision score (for binary classification) -
recall(yTrue, yPred, positiveLabel) ⇒
numberRecall score (for binary classification) -
f1(yTrue, yPred, positiveLabel) ⇒
numberF1 score -
logLoss(yTrue, yPred, eps) ⇒
numberLog loss (cross-entropy loss) -
rocAuc(yTrue, yPred) ⇒
numberROC AUC score (simplified for binary classification) -
cohenKappa(yTrue, yPred) ⇒
numberCohen's Kappa coefficient -
adjustedRandIndex(yTrue, yPred) ⇒
numberAdjusted Rand Index -
initializeWeights(nIn, nOut) ⇒
Array.<Array.<number>>Initialize weights using Xavier/Glorot initialization -
forward(input, layers) ⇒
ObjectForward pass through network -
backward(target, forwardResult, layers) ⇒
Array.<Object>Backward pass (backpropagation) -
createNetwork(layerSizes, activation) ⇒
Array.<Object>Create MLP architecture -
fit(X, y, options) ⇒
ObjectTrain MLP using mini-batch gradient descent -
predict(model, X) ⇒
Array.<Array.<number>>Predict using trained MLP -
evaluate(model, X, y) ⇒
ObjectEvaluate model on test data -
polynomialFeatures(X, degree) ⇒
Array.<Array.<number>>Create polynomial features from input -
fit(X, y, options) ⇒
ObjectFit polynomial regression model -
predict(model, X, options) ⇒
Array.<number>Predict using polynomial regression model -
train(model, X, y, options) ⇒
ObjectTrain a model with gradient-based optimization -
trainFunction(lossFn, params0, options) ⇒
ObjectSimple training loop for functions (not models) -
earlyStopping(patience, minDelta) ⇒
ObjectEarly stopping callback -
learningRateScheduler(scheduleFn, optimizer) ⇒
ObjectLearning rate scheduler callback -
modelCheckpoint(metric) ⇒
ObjectModel checkpoint callback -
GridSearchCV(fitFn, scoreFn, X, y, paramGrid, options) ⇒
ObjectGrid Search Cross-Validation -
RandomSearchCV(fitFn, scoreFn, X, y, paramDistributions, options) ⇒
ObjectRandom Search Cross-Validation -
generateParamCombinations(paramGrid) ⇒
Array.<Object>Generate all combinations from parameter grid -
sampleParams(paramDistributions) ⇒
ObjectSample parameters from distributions -
sampleFromDistribution(distribution) ⇒
numberSample from a distribution object -
setSeed(value) Set random seed for reproducibility
-
random() ⇒
numberSeeded random number generator (LCG) -
randomInt(min, max) ⇒
numberRandom integer in range [min, max) -
shuffle(arr) ⇒
ArrayShuffle array in place using seeded random -
sample(arr, k) ⇒
ArraySample without replacement -
trainTestSplit(X, y, options) ⇒
ObjectSplit data into train and test sets -
kFold(X, y, k, shuffle) ⇒
Array.<Object>K-Fold cross-validation generator -
stratifiedKFold(X, y, k) ⇒
Array.<Object>Stratified K-Fold for classification with balanced class distribution -
groupKFold(X, y, groups, k) ⇒
Array.<Object>Group K-Fold keeping group membership intact -
leaveOneOut(X, y) ⇒
Array.<Object>Leave-One-Out cross-validation -
shuffleSplit(X, y, options) ⇒
Array.<Object>Shuffle Split - repeated random train-test splits -
crossValidate(fitFn, scoreFn, X, y, folds) ⇒
ObjectExecute cross-validation with a model -
fit() Fit CCA model. Accepts either numeric matrices (fit(XMatrix, YMatrix, options)) or a declarative object: fit({ X: ['col1', ...], Y: ['colA', ...], data, omit_missing, center, scale }).
-
euclideanDistance(a, b) ⇒
numberCompute Euclidean distance between two points -
computeDistanceMatrix(data) ⇒
Array.<Array.<number>>Compute pairwise distance matrix -
clusterDistance(cluster1, cluster2, distances, linkage) ⇒
numberFind minimum distance between two clusters -
fit(X, options) ⇒
ObjectFit hierarchical clustering -
cut(model, k) ⇒
Array.<number>Cut dendrogram to get k clusters -
cutHeight(model, height) ⇒
Array.<number>Cut dendrogram at specific height -
standardize(data, scale) ⇒
ObjectStandardize data (center and optionally scale) -
fit(X, options) ⇒
ObjectFit PCA model -
transform(model, X) ⇒
Array.<Object>Transform new data using fitted PCA model -
cumulativeVariance(model) ⇒
Array.<number>Get cumulative variance explained -
fit(Y, X, options) ⇒
ObjectFit RDA model -
transform(model, Y, X) ⇒
Array.<Object>Transform new data using fitted RDA model -
plotROC(yTrue, yProb, options) ⇒
ObjectGenerate ROC curve plot configuration -
plotPrecisionRecall(yTrue, yProb, options) ⇒
ObjectGenerate precision-recall curve plot configuration -
plotConfusionMatrix(yTrue, yPred, options) ⇒
ObjectGenerate confusion matrix plot configuration -
plotCalibration(yTrue, yProb, options) ⇒
ObjectGenerate calibration curve plot configuration Shows how well predicted probabilities match actual frequencies -
ordiplot(result, options) ⇒
ObjectGenerate unified ordination plot configuration Works with PCA, LDA, and RDA results -
plotHCA(result) ⇒
ObjectGenerate dendrogram data structure -
dendrogramLayout(dendrogramData, options) ⇒
ObjectConvert dendrogram to layout coordinates -
plotLDA(result, options) ⇒
ObjectGenerate LDA scatter plot configuration -
plotPCA(result, options) ⇒
ObjectGenerate PCA biplot configuration -
plotScree(result, options) ⇒
ObjectGenerate PCA scree plot configuration -
plotRDA(result, options) ⇒
ObjectGenerate RDA triplot configuration -
attachShow(config) ⇒
ObjectAttach a .show() helper to the configuration if marks are present. -
plotFeatureImportance(importances, options) ⇒
ObjectGenerate feature importance bar plot configuration -
plotPartialDependence(pdResult, options) ⇒
ObjectGenerate partial dependence plot configuration -
plotCorrelationMatrix(corrResult, options) ⇒
ObjectGenerate correlation matrix heatmap configuration -
plotResiduals(residualData, options) ⇒
ObjectGenerate residual plot configuration -
plotQQ(residualData, options) ⇒
ObjectGenerate Q-Q plot configuration for normality check -
erfInv(x) ⇒
numberApproximate error function inverse (for Q-Q plot) -
plotLearningCurve(lcResult, options) ⇒
ObjectGenerate learning curve plot configuration -
fit(X, y, options) ⇒
ObjectFit OLS linear regression Supports two calling styles: -
Array/matrix style (backward compatible): fit(X, y, { intercept })
-
Declarative table style: fit({ X: 'col' | ['col1','col2'], y: 'target', data, omit_missing, intercept })
-
predict(coefficients, X, options) ⇒
Array.<number>Predict using fitted model -
summary(model) ⇒
ObjectSummary statistics for regression -
fit(X, y, groups, options) ⇒
ObjectFit simple random-intercept linear mixed model -
predict(model, X, groups, options) ⇒
Array.<number>Predict using fitted LMM -
sigmoid(z) ⇒
numberLogistic (sigmoid) function -
fit(X, y, options) ⇒
ObjectFit logistic regression using IRLS -
predict(coefficients, X, options) ⇒
Array.<number>Predict probabilities using fitted model -
classify(probabilities, threshold) ⇒
Array.<number>Classify based on threshold
Optimizer
Base Optimizer class
Kind: global class
- Optimizer
- .minimize(lossFn, x0, options) ⇒
Object - .checkConvergence(gradient) ⇒
boolean
- .minimize(lossFn, x0, options) ⇒
optimizer.minimize(lossFn, x0, options) ⇒ Object
Minimize a loss function
Kind: instance method of Optimizer
Returns: Object - {x, history}
| Param | Type | Description |
|---|---|---|
| lossFn | function | Function that returns {loss, gradient} |
| x0 | Array.<number> | Initial parameters |
| options | Object | Additional options |
optimizer.checkConvergence(gradient) ⇒ boolean
Check convergence based on gradient norm
Kind: instance method of Optimizer
| Param | Type |
|---|---|
| gradient | Array.<number> |
seed
ML utilities including seeded random number generation
Kind: global variable
distributions
Create parameter distribution objects
Kind: global constant
- distributions
- .uniform(low, high) ⇒
Object - .loguniform(low, high) ⇒
Object - .randint(low, high) ⇒
Object - .choice(options) ⇒
Object
- .uniform(low, high) ⇒
distributions.uniform(low, high) ⇒ Object
Uniform distribution
Kind: static method of distributions
| Param | Type |
|---|---|
| low | number |
| high | number |
distributions.loguniform(low, high) ⇒ Object
Log-uniform distribution (for learning rates, etc.)
Kind: static method of distributions
| Param | Type |
|---|---|
| low | number |
| high | number |
distributions.randint(low, high) ⇒ Object
Random integer
Kind: static method of distributions
| Param | Type |
|---|---|
| low | number |
| high | number |
distributions.choice(options) ⇒ Object
Choice from options
Kind: static method of distributions
| Param | Type |
|---|---|
| options | Array |
SUPPORTED_MARKS
Attach lightweight rendering helpers to plot configuration objects. Allows calling config.show(Plot) in Observable without adding direct Plot dependency.
Kind: global constant
toMatrix(data) ⇒ Matrix
Convert array-like structure to Matrix
Kind: global function
Returns: Matrix - Matrix object
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Matrix | Input data |
solveLeastSquares(A, b) ⇒ Matrix
Solve least squares problem: minimize ||Ax - b||^2
Kind: global function
Returns: Matrix - Solution x
| Param | Type | Description |
|---|---|---|
| A | Array.<Array.<number>> | Matrix | Design matrix |
| b | Array.<number> | Array.<Array.<number>> | Matrix | Target vector/matrix |
covarianceMatrix(data, center) ⇒ Matrix
Compute covariance matrix
Kind: global function
Returns: Matrix - Covariance matrix
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Matrix | Data matrix (rows = observations) |
| center | boolean | If true, center the data |
svd(data) ⇒ Object
Singular Value Decomposition
Kind: global function
Returns: Object - {U, s, V} where data ≈ U * diag(s) * V'
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Matrix | Input matrix |
eig(data) ⇒ Object
Eigenvalue decomposition
Kind: global function
Returns: Object - {values, vectors}
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Matrix | Square matrix |
mmul(A, B) ⇒ Matrix
Matrix multiplication
Kind: global function
Returns: Matrix - A * B
| Param | Type | Description |
|---|---|---|
| A | Array.<Array.<number>> | Matrix | First matrix |
| B | Array.<Array.<number>> | Matrix | Second matrix |
transpose(data) ⇒ Matrix
Matrix transpose
Kind: global function
Returns: Matrix - Transposed matrix
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Matrix | Input matrix |
inverse(data) ⇒ Matrix
Matrix inverse
Kind: global function
Returns: Matrix - Inverse matrix
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Matrix | Square matrix |
approxEqual(a, b, tolerance) ⇒ boolean
Approximate equality comparison for floating point numbers
Kind: global function
Returns: boolean - True if approximately equal
| Param | Type | Description |
|---|---|---|
| a | number | First number |
| b | number | Second number |
| tolerance | number | Tolerance for comparison |
guardFinite(value, name) ⇒ number
Guard against non-finite values
Kind: global function
Returns: number - The value if valid
Throws:
ErrorIf value is not finite
| Param | Type | Description |
|---|---|---|
| value | number | Value to check |
| name | string | Name for error message |
guardPositive(value, name) ⇒ number
Guard against negative values
Kind: global function
Returns: number - The value if valid
Throws:
ErrorIf value is negative
| Param | Type | Description |
|---|---|---|
| value | number | Value to check |
| name | string | Name for error message |
guardProbability(value, name) ⇒ number
Guard against values outside [0, 1]
Kind: global function
Returns: number - The value if valid
Throws:
ErrorIf value is outside [0, 1]
| Param | Type | Description |
|---|---|---|
| value | number | Value to check |
| name | string | Name for error message |
sum(arr) ⇒ number
Sum of array
Kind: global function
Returns: number - Sum
| Param | Type | Description |
|---|---|---|
| arr | Array.<number> | Array of numbers |
mean(arr) ⇒ number
Mean of array
Kind: global function
Returns: number - Mean
| Param | Type | Description |
|---|---|---|
| arr | Array.<number> | Array of numbers |
variance(arr, sample) ⇒ number
Variance of array
Kind: global function
Returns: number - Variance
| Param | Type | Description |
|---|---|---|
| arr | Array.<number> | Array of numbers |
| sample | boolean | If true, use sample variance (n-1) |
stddev(arr, sample) ⇒ number
Standard deviation of array
Kind: global function
Returns: number - Standard deviation
| Param | Type | Description |
|---|---|---|
| arr | Array.<number> | Array of numbers |
| sample | boolean | If true, use sample variance (n-1) |
createOptimizer(name, options) ⇒ Optimizer
Convenience function to create optimizer by name
Kind: global function
Returns: Optimizer - Optimizer instance
| Param | Type | Description |
|---|---|---|
| name | string | Optimizer name |
| options | Object | Optimizer options |
saveModel(model) ⇒ string
Save model to JSON
Kind: global function
Returns: string - JSON string representation of the model
| Param | Type | Description |
|---|---|---|
| model | Object | Model object with toJSON method or estimator instance |
loadModel(json) ⇒ Object
Load model from JSON
Kind: global function
Returns: Object - Reconstructed model object
| Param | Type | Description |
|---|---|---|
| json | string | JSON string representation |
addSerializationSupport(EstimatorClass, toJSONFn)
Add toJSON method to an estimator class prototype This allows models to define their own serialization logic
Kind: global function
| Param | Type | Description |
|---|---|---|
| EstimatorClass | function | Estimator class |
| toJSONFn | function | Custom toJSON function |
serializeValue(value) ⇒ any
Serialize model to file-safe object Handles special types like undefined, Infinity, NaN
Kind: global function
Returns: any - Serializable value
| Param | Type | Description |
|---|---|---|
| value | any | Value to serialize |
deserializeValue(value) ⇒ any
Deserialize value from file-safe object
Kind: global function
Returns: any - Deserialized value
| Param | Type | Description |
|---|---|---|
| value | any | Value to deserialize |
makeSaveable(model) ⇒ Object
Create a saveable model wrapper Adds save() method to any model object
Kind: global function
Returns: Object - Model with save() method
| Param | Type | Description |
|---|---|---|
| model | Object | Model object |
isArqueroLike(data) ⇒ boolean
Check if input has Arquero-like interface
Kind: global function
Returns: boolean - True if has .objects() method
| Param | Type | Description |
|---|---|---|
| data | \* | Input data |
normalize(data) ⇒ Array.<Object>
Normalize input to array of objects
Kind: global function
Returns: Array.<Object> - Array of row objects
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
toMatrix(data, columns) ⇒ Matrix
Convert table data to matrix
Kind: global function
Returns: Matrix - Matrix with selected columns
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
| columns | Array.<string> | Column names to extract |
toVector(data, column) ⇒ Array.<number>
Convert table column to vector
Kind: global function
Returns: Array.<number> - 1D array
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
| column | string | Column name |
toColumns(data, columns) ⇒ Object
Extract multiple columns as arrays
Kind: global function
Returns: Object - Object with column names as keys and arrays as values
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
| columns | Array.<string> | Column names |
getColumns(data) ⇒ Array.<string>
Get column names from data
Kind: global function
Returns: Array.<string> - Column names
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
filter(data, predicate) ⇒ Array.<Object>
Filter rows based on predicate
Kind: global function
Returns: Array.<Object> - Filtered rows
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
| predicate | function | Filter function |
select(data, columns) ⇒ Array.<Object>
Select specific columns
Kind: global function
Returns: Array.<Object> - Rows with selected columns
| Param | Type | Description |
|---|---|---|
| data | Array.<Object> | Object | Input data |
| columns | Array.<string> | Columns to select |
isNumeric(v) ⇒ boolean
Helper: check if a value is numeric (finite number)
Kind: global function
| Param | Type |
|---|---|
| v | \* |
isMissing(v) ⇒ boolean
Helper: check if a value is considered missing
Kind: global function
| Param | Type |
|---|---|
| v | \* |
prepareX()
Prepare feature matrix X from table-like data. Supports optional categorical encoding: prepareX({ columns, data, omit_missing = true, encode = null })
encode can be:
- null/false: no encoding (default)
- true: auto-label encode any non-numeric columns
- { colName: 'label' | 'onehot' } mapping per-column
Returns: { X, columns, n, rows, encoders } where encoders is a mapping of column->encoder used
Kind: global function
prepareXY()
Prepare feature matrix X and response vector y from table-like data.
Supports categorical encoding for X and y via encode option:
prepareXY({ X, y, data, omit_missing = true, encode = null })
encode semantics same as prepareX. For y, only 'label' encoding is supported (maps categories to integer class labels).
Returns: { X, y, columnsX, n, rows, encoders } where encoders may include encoders.y
Kind: global function
featureImportance(model, X, y, scoreFn, options) ⇒ Array.<Object>
Compute feature importance via permutation
Kind: global function
Returns: Array.<Object> - Feature importance scores
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model with predict method |
| X | Array.<Array.<number>> | Feature matrix |
| y | Array.<number> | Target values |
| scoreFn | function | Scoring function (yTrue, yPred) => score |
| options | Object | {nRepeats, seed} |
coefficientImportance(model, featureNames) ⇒ Array.<Object>
Compute coefficient-based feature importance (for linear models)
Kind: global function
Returns: Array.<Object> - Feature importance based on coefficients
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted linear model with coefficients |
| featureNames | Array.<string> | Feature names (optional) |
partialDependence(model, X, feature, options) ⇒ Object
Compute partial dependence for a feature
Kind: global function
Returns: Object - {values, predictions}
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model with predict method |
| X | Array.<Array.<number>> | Feature matrix |
| feature | number | Feature index |
| options | Object | {gridSize, percentiles} |
residualPlotData(model, X, y) ⇒ Object
Compute residual plot data
Kind: global function
Returns: Object - {fitted, residuals, standardized}
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model with predict method |
| X | Array.<Array.<number>> | Feature matrix |
| y | Array.<number> | Target values |
correlationMatrix(X, featureNames) ⇒ Object
Compute correlation matrix
Kind: global function
Returns: Object - {matrix, features}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Feature matrix |
| featureNames | Array.<string> | Feature names (optional) |
learningCurve(fitFn, scoreFn, X, y, options) ⇒ Object
Learning curve data (performance vs training size)
Kind: global function
Returns: Object - {trainSizes, trainScores, testScores}
| Param | Type | Description |
|---|---|---|
| fitFn | function | Function to fit model: (X, y) => model |
| scoreFn | function | Scoring function: (yTrue, yPred) => score |
| X | Array.<Array.<number>> | Feature matrix |
| y | Array | Target values |
| options | Object | {trainSizes, cv} |
euclideanDistance(a, b) ⇒ number
Euclidean distance between two points
Kind: global function
Returns: number - Distance
| Param | Type | Description |
|---|---|---|
| a | Array.<number> | First point |
| b | Array.<number> | Second point |
createRandomGenerator(data, k) ⇒ Array.<Array.<number>>
Initialize centroids using k-means++ algorithm
Kind: global function
Returns: Array.<Array.<number>> - Initial centroids
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Data points |
| k | number | Number of clusters |
initializeCentroidsKMeansPlusPlus(data, k, random) ⇒ Array.<Array.<number>>
Initialize centroids using k-means++ algorithm
Kind: global function
Returns: Array.<Array.<number>> - Initial centroids
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Data points |
| k | number | Number of clusters |
| random | function | Random number generator returning [0,1) |
assignClusters(data, centroids) ⇒ Array.<number>
Assign each point to nearest centroid
Kind: global function
Returns: Array.<number> - Cluster assignments
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Data points |
| centroids | Array.<Array.<number>> | Current centroids |
updateCentroids(data, labels, k) ⇒ Array.<Array.<number>>
Update centroids based on cluster assignments
Kind: global function
Returns: Array.<Array.<number>> - New centroids
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Data points |
| labels | Array.<number> | Cluster assignments |
| k | number | Number of clusters |
computeInertia(data, labels, centroids) ⇒ number
Compute within-cluster sum of squares (inertia)
Kind: global function
Returns: number - Inertia
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Data points |
| labels | Array.<number> | Cluster assignments |
| centroids | Array.<Array.<number>> | Centroids |
fit(X, options) ⇒ Object
Fit k-means clustering model
Kind: global function
Returns: Object - {labels, centroids, inertia, iterations, converged}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Matrix | Data matrix (n samples × d features) |
| options | Object | {k: number of clusters, maxIter: max iterations, tol: tolerance} |
predict(model, X) ⇒ Array.<number>
Predict cluster labels for new data
Kind: global function
Returns: Array.<number> - Cluster labels
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model from fit() |
| X | Array.<Array.<number>> | New data points |
silhouetteScore(X, labels) ⇒ number
Compute silhouette score for clustering quality
Kind: global function
Returns: number - Silhouette score (range: -1 to 1, higher is better)
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Data points |
| labels | Array.<number> | Cluster assignments |
mseLoss(yTrue, yPred) ⇒ Object
Mean Squared Error Loss
Kind: global function
Returns: Object - {loss, gradient}
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
maeLoss(yTrue, yPred) ⇒ Object
Mean Absolute Error Loss
Kind: global function
Returns: Object - {loss, gradient}
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
logLoss(yTrue, yPred, epsilon) ⇒ Object
Binary Cross-Entropy Loss (Log Loss)
Kind: global function
Returns: Object - {loss, gradient}
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True labels (0 or 1) |
| yPred | Array.<number> | Predicted probabilities |
| epsilon | number | Small value to avoid log(0) |
crossEntropy(yTrue, yPred, epsilon) ⇒ Object
Categorical Cross-Entropy Loss
Kind: global function
Returns: Object - {loss, gradient}
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<Array.<number>> | One-hot encoded true labels |
| yPred | Array.<Array.<number>> | Predicted probabilities |
| epsilon | number | Small value to avoid log(0) |
hingeLoss(yTrue, yPred) ⇒ Object
Hinge Loss (for SVM)
Kind: global function
Returns: Object - {loss, gradient}
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True labels (-1 or 1) |
| yPred | Array.<number> | Predicted scores |
huberLoss(yTrue, yPred, delta) ⇒ Object
Huber Loss (robust to outliers)
Kind: global function
Returns: Object - {loss, gradient}
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
| delta | number | Threshold for switching from quadratic to linear |
getLossFunction(name) ⇒ function
Get loss function by name
Kind: global function
Returns: function - Loss function
| Param | Type | Description |
|---|---|---|
| name | string | Loss function name |
mse(yTrue, yPred) ⇒ number
Mean Squared Error
Kind: global function
Returns: number - MSE
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
rmse(yTrue, yPred) ⇒ number
Root Mean Squared Error
Kind: global function
Returns: number - RMSE
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
mae(yTrue, yPred) ⇒ number
Mean Absolute Error
Kind: global function
Returns: number - MAE
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
r2(yTrue, yPred) ⇒ number
R² (coefficient of determination)
Kind: global function
Returns: number - R²
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True values |
| yPred | Array.<number> | Predicted values |
accuracy(yTrue, yPred) ⇒ number
Accuracy score
Kind: global function
Returns: number - Accuracy
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
confusionMatrix(yTrue, yPred) ⇒ Object
Confusion matrix
Kind: global function
Returns: Object - {matrix, labels}
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
precision(yTrue, yPred, positiveLabel) ⇒ number
Precision score (for binary classification)
Kind: global function
Returns: number - Precision
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
| positiveLabel | \* | Label to consider as positive |
recall(yTrue, yPred, positiveLabel) ⇒ number
Recall score (for binary classification)
Kind: global function
Returns: number - Recall
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
| positiveLabel | \* | Label to consider as positive |
f1(yTrue, yPred, positiveLabel) ⇒ number
F1 score
Kind: global function
Returns: number - F1 score
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
| positiveLabel | \* | Label to consider as positive |
logLoss(yTrue, yPred, eps) ⇒ number
Log loss (cross-entropy loss)
Kind: global function
Returns: number - Log loss
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels (0 or 1) |
| yPred | Array.<number> | Predicted probabilities |
| eps | number | Small constant to avoid log(0) |
rocAuc(yTrue, yPred) ⇒ number
ROC AUC score (simplified for binary classification)
Kind: global function
Returns: number - AUC
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels (0 or 1) |
| yPred | Array.<number> | Predicted probabilities |
cohenKappa(yTrue, yPred) ⇒ number
Cohen's Kappa coefficient
Kind: global function
Returns: number - Kappa
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
adjustedRandIndex(yTrue, yPred) ⇒ number
Adjusted Rand Index
Kind: global function
Returns: number - Adjusted Rand Index
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
initializeWeights(nIn, nOut) ⇒ Array.<Array.<number>>
Initialize weights using Xavier/Glorot initialization
Kind: global function
Returns: Array.<Array.<number>> - Weight matrix
| Param | Type | Description |
|---|---|---|
| nIn | number | Input size |
| nOut | number | Output size |
forward(input, layers) ⇒ Object
Forward pass through network
Kind: global function
Returns: Object - {activations, outputs}
| Param | Type | Description |
|---|---|---|
| input | Array.<number> | Input vector |
| layers | Array.<Object> | Network layers |
backward(target, forwardResult, layers) ⇒ Array.<Object>
Backward pass (backpropagation)
Kind: global function
Returns: Array.<Object> - Gradients for each layer
| Param | Type | Description |
|---|---|---|
| target | Array.<number> | Target output |
| forwardResult | Object | Result from forward pass |
| layers | Array.<Object> | Network layers |
createNetwork(layerSizes, activation) ⇒ Array.<Object>
Create MLP architecture
Kind: global function
Returns: Array.<Object> - Initialized layers
| Param | Type | Description |
|---|---|---|
| layerSizes | Array.<number> | Size of each layer [input, hidden1, ..., output] |
| activation | string | Activation function ('sigmoid', 'relu', 'tanh') |
fit(X, y, options) ⇒ Object
Train MLP using mini-batch gradient descent
Kind: global function
Returns: Object - {layers, losses, epochs}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Training data |
| y | Array.<Array.<number>> | Array.<number> | Target values |
| options | Object | Training options |
predict(model, X) ⇒ Array.<Array.<number>>
Predict using trained MLP
Kind: global function
Returns: Array.<Array.<number>> - Predictions
| Param | Type | Description |
|---|---|---|
| model | Object | Trained model from fit() |
| X | Array.<Array.<number>> | Array.<number> | Input data |
evaluate(model, X, y) ⇒ Object
Evaluate model on test data
Kind: global function
Returns: Object - {mse, mae}
| Param | Type | Description |
|---|---|---|
| model | Object | Trained model |
| X | Array.<Array.<number>> | Test inputs |
| y | Array.<Array.<number>> | Array.<number> | Test targets |
polynomialFeatures(X, degree) ⇒ Array.<Array.<number>>
Create polynomial features from input
Kind: global function
Returns: Array.<Array.<number>> - Polynomial features
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Matrix | Input features (n × 1 for univariate) |
| degree | number | Polynomial degree |
fit(X, y, options) ⇒ Object
Fit polynomial regression model
Kind: global function
Returns: Object - {coefficients, degree, fitted, residuals, rSquared}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Array.<number> | Input data (can be 1D for univariate) |
| y | Array.<number> | Target values |
| options | Object | {degree: polynomial degree, intercept: include intercept} |
predict(model, X, options) ⇒ Array.<number>
Predict using polynomial regression model
Kind: global function
Returns: Array.<number> - Predictions
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model from fit() |
| X | Array.<Array.<number>> | Array.<number> | New data |
| options | Object | {intercept: boolean} |
train(model, X, y, options) ⇒ Object
Train a model with gradient-based optimization
Kind: global function
Returns: Object - Training history
| Param | Type | Description |
|---|---|---|
| model | Object | Model with forward and backward methods |
| X | Array.<Array.<number>> | Feature matrix |
| y | Array.<number> | Array.<Array.<number>> | Target values |
| options | Object | Training options |
trainFunction(lossFn, params0, options) ⇒ Object
Simple training loop for functions (not models)
Kind: global function
Returns: Object - {params, history}
| Param | Type | Description |
|---|---|---|
| lossFn | function | Loss function that returns {loss, gradient} |
| params0 | Array.<number> | Initial parameters |
| options | Object | Training options |
earlyStopping(patience, minDelta) ⇒ Object
Early stopping callback
Kind: global function
Returns: Object - Callback object with state
| Param | Type | Description |
|---|---|---|
| patience | number | Number of epochs to wait for improvement |
| minDelta | number | Minimum change to qualify as improvement |
learningRateScheduler(scheduleFn, optimizer) ⇒ Object
Learning rate scheduler callback
Kind: global function
Returns: Object - Callback object
| Param | Type | Description |
|---|---|---|
| scheduleFn | function | Function (epoch) => learningRate |
| optimizer | Optimizer | Optimizer to update |
modelCheckpoint(metric) ⇒ Object
Model checkpoint callback
Kind: global function
Returns: Object - Callback object with state
| Param | Type | Description |
|---|---|---|
| metric | string | Metric to monitor ('loss' or 'valLoss') |
GridSearchCV(fitFn, scoreFn, X, y, paramGrid, options) ⇒ Object
Grid Search Cross-Validation
Kind: global function
Returns: Object - {bestParams, bestScore, bestModel, results}
| Param | Type | Description |
|---|---|---|
| fitFn | function | Function (X, y, params) => model |
| scoreFn | function | Function (model, X, y) => score |
| X | Array | Feature matrix |
| y | Array | Target values |
| paramGrid | Object | Parameter grid {param1: [values], param2: [values]} |
| options | Object | {k, shuffle, metric} |
- GridSearchCV(fitFn, scoreFn, X, y, paramGrid, options) ⇒
Object- new exports.GridSearchCV(estimatorFn, paramGrid, scoreFn, cv)
- global
- instance
- .fit(X, y) ⇒
GridSearchCV - .predict(X) ⇒
Array - .getResults() ⇒
Array.<Object>
- .fit(X, y) ⇒
new exports.GridSearchCV(estimatorFn, paramGrid, scoreFn, cv)
Create grid search
| Param | Type | Default | Description |
|---|---|---|---|
| estimatorFn | function | Function that creates estimator: (params) => estimator | |
| paramGrid | Object | Grid of parameters: {param1: [val1, val2], ...} | |
| scoreFn | function | Scoring function: (yTrue, yPred) => score | |
| cv | number | 5 | Number of cross-validation folds |
GridSearchCVGridSearchCV
Simple GridSearchCV for hyperparameter tuning
Kind: global class of GridSearchCV
gridSearchCV.fit(X, y) ⇒ GridSearchCV
Perform grid search with cross-validation
Kind: instance method of GridSearchCV
Returns: GridSearchCV - this
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target values |
gridSearchCV.predict(X) ⇒ Array
Predict using best estimator
Kind: instance method of GridSearchCV
Returns: Array - Predictions
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
gridSearchCV.getResults() ⇒ Array.<Object>
Get results sorted by score
Kind: instance method of GridSearchCV
Returns: Array.<Object> - Results
RandomSearchCV(fitFn, scoreFn, X, y, paramDistributions, options) ⇒ Object
Random Search Cross-Validation
Kind: global function
Returns: Object - {bestParams, bestScore, bestModel, results}
| Param | Type | Description |
|---|---|---|
| fitFn | function | Function (X, y, params) => model |
| scoreFn | function | Function (model, X, y) => score |
| X | Array | Feature matrix |
| y | Array | Target values |
| paramDistributions | Object | Parameter distributions |
| options | Object | {nIter, k, shuffle, seed} |
generateParamCombinations(paramGrid) ⇒ Array.<Object>
Generate all combinations from parameter grid
Kind: global function
Returns: Array.<Object> - Array of parameter combinations
| Param | Type |
|---|---|
| paramGrid | Object |
sampleParams(paramDistributions) ⇒ Object
Sample parameters from distributions
Kind: global function
Returns: Object - Sampled parameters
| Param | Type |
|---|---|
| paramDistributions | Object |
sampleFromDistribution(distribution) ⇒ number
Sample from a distribution object
Kind: global function
Returns: number - Sampled value
| Param | Type | Description |
|---|---|---|
| distribution | Object | {type, ...params} |
setSeed(value)
Set random seed for reproducibility
Kind: global function
| Param | Type | Description |
|---|---|---|
| value | number | Seed value |
random() ⇒ number
Seeded random number generator (LCG)
Kind: global function
Returns: number - Random number between 0 and 1
randomInt(min, max) ⇒ number
Random integer in range [min, max)
Kind: global function
Returns: number - Random integer
| Param | Type | Description |
|---|---|---|
| min | number | Minimum value (inclusive) |
| max | number | Maximum value (exclusive) |
shuffle(arr) ⇒ Array
Shuffle array in place using seeded random
Kind: global function
Returns: Array - Shuffled array
| Param | Type | Description |
|---|---|---|
| arr | Array | Array to shuffle |
sample(arr, k) ⇒ Array
Sample without replacement
Kind: global function
Returns: Array - Sampled elements
| Param | Type | Description |
|---|---|---|
| arr | Array | Array to sample from |
| k | number | Number of samples |
trainTestSplit(X, y, options) ⇒ Object
Split data into train and test sets
Kind: global function
Returns: Object - {XTrain, XTest, yTrain, yTest, trainIndices, testIndices}
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target values (optional) |
| options | Object | {ratio, shuffle, seed} |
kFold(X, y, k, shuffle) ⇒ Array.<Object>
K-Fold cross-validation generator
Kind: global function
Returns: Array.<Object> - Array of fold objects
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target values |
| k | number | Number of folds |
| shuffle | boolean | Whether to shuffle data |
stratifiedKFold(X, y, k) ⇒ Array.<Object>
Stratified K-Fold for classification with balanced class distribution
Kind: global function
Returns: Array.<Object> - Array of fold objects
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target labels |
| k | number | Number of folds |
groupKFold(X, y, groups, k) ⇒ Array.<Object>
Group K-Fold keeping group membership intact
Kind: global function
Returns: Array.<Object> - Array of fold objects
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target values |
| groups | Array | Group labels |
| k | number | Number of folds |
leaveOneOut(X, y) ⇒ Array.<Object>
Leave-One-Out cross-validation
Kind: global function
Returns: Array.<Object> - Array of fold objects
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target values |
shuffleSplit(X, y, options) ⇒ Array.<Object>
Shuffle Split - repeated random train-test splits
Kind: global function
Returns: Array.<Object> - Array of split objects
| Param | Type | Description |
|---|---|---|
| X | Array | Feature matrix |
| y | Array | Target values |
| options | Object | {nSplits, testRatio, seed} |
crossValidate(fitFn, scoreFn, X, y, folds) ⇒ Object
Execute cross-validation with a model
Kind: global function
Returns: Object - {scores, meanScore, stdScore}
| Param | Type | Description |
|---|---|---|
| fitFn | function | Function that fits model: (XTrain, yTrain) => model |
| scoreFn | function | Function that scores model: (model, XTest, yTest) => score |
| X | Array | Feature matrix |
| y | Array | Target values |
| folds | Array.<Object> | Fold objects from kFold, etc. |
fit()
Fit CCA model.
Accepts either numeric matrices (fit(XMatrix, YMatrix, options)) or a declarative object: fit({ X: ['col1', ...], Y: ['colA', ...], data, omit_missing, center, scale }).
Kind: global function
euclideanDistance(a, b) ⇒ number
Compute Euclidean distance between two points
Kind: global function
Returns: number - Distance
| Param | Type | Description |
|---|---|---|
| a | Array.<number> | First point |
| b | Array.<number> | Second point |
computeDistanceMatrix(data) ⇒ Array.<Array.<number>>
Compute pairwise distance matrix
Kind: global function
Returns: Array.<Array.<number>> - Distance matrix
| Param | Type | Description |
|---|---|---|
| data | Array.<Array.<number>> | Data points |
clusterDistance(cluster1, cluster2, distances, linkage) ⇒ number
Find minimum distance between two clusters
Kind: global function
Returns: number - Distance between clusters
| Param | Type | Description |
|---|---|---|
| cluster1 | Array.<number> | Indices in cluster 1 |
| cluster2 | Array.<number> | Indices in cluster 2 |
| distances | Array.<Array.<number>> | Distance matrix |
| linkage | string | Linkage method |
fit(X, options) ⇒ Object
Fit hierarchical clustering
Kind: global function
Returns: Object - {dendrogram, distances}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Data matrix |
| options | Object | {linkage: 'single' |
cut(model, k) ⇒ Array.<number>
Cut dendrogram to get k clusters
Kind: global function
Returns: Array.<number> - Cluster assignments
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted HCA model |
| k | number | Number of clusters |
cutHeight(model, height) ⇒ Array.<number>
Cut dendrogram at specific height
Kind: global function
Returns: Array.<number> - Cluster assignments
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted HCA model |
| height | number | Height to cut at |
standardize(data, scale) ⇒ Object
Standardize data (center and optionally scale)
Kind: global function
Returns: Object - {standardized, means, sds}
| Param | Type | Default | Description |
|---|---|---|---|
| data | Array.<Array.<number>> | Data matrix | |
| scale | boolean | false | If true, scale to unit variance |
fit(X, options) ⇒ Object
Fit PCA model
Kind: global function
Returns: Object - PCA model
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Matrix | Data matrix (n x p) |
| options | Object | {scale: boolean, center: boolean} |
transform(model, X) ⇒ Array.<Object>
Transform new data using fitted PCA model
Kind: global function
Returns: Array.<Object> - Transformed scores
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted PCA model |
| X | Array.<Array.<number>> | New data |
cumulativeVariance(model) ⇒ Array.<number>
Get cumulative variance explained
Kind: global function
Returns: Array.<number> - Cumulative variance explained
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted PCA model |
fit(Y, X, options) ⇒ Object
Fit RDA model
Kind: global function
Returns: Object - RDA model
| Param | Type | Description |
|---|---|---|
| Y | Array.<Array.<number>> | Response matrix (n x q) |
| X | Array.<Array.<number>> | Explanatory matrix (n x p) |
| options | Object | {scale: boolean} |
transform(model, Y, X) ⇒ Array.<Object>
Transform new data using fitted RDA model
Kind: global function
Returns: Array.<Object> - Canonical scores
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted RDA model |
| Y | Array.<Array.<number>> | New response data |
| X | Array.<Array.<number>> | New explanatory data |
plotROC(yTrue, yProb, options) ⇒ Object
Generate ROC curve plot configuration
Kind: global function
Returns: Object - Plot configuration with ROC curve data and AUC
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True binary labels (0 or 1) |
| yProb | Array.<number> | Predicted probabilities for positive class |
| options | Object | {width, height, showDiagonal} |
plotPrecisionRecall(yTrue, yProb, options) ⇒ Object
Generate precision-recall curve plot configuration
Kind: global function
Returns: Object - Plot configuration with precision-recall curve and average precision
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True binary labels (0 or 1) |
| yProb | Array.<number> | Predicted probabilities for positive class |
| options | Object | {width, height, showBaseline} |
plotConfusionMatrix(yTrue, yPred, options) ⇒ Object
Generate confusion matrix plot configuration
Kind: global function
Returns: Object - Plot configuration with confusion matrix
| Param | Type | Description |
|---|---|---|
| yTrue | Array | True labels |
| yPred | Array | Predicted labels |
| options | Object | {width, height, normalize, labels} |
plotCalibration(yTrue, yProb, options) ⇒ Object
Generate calibration curve plot configuration Shows how well predicted probabilities match actual frequencies
Kind: global function
Returns: Object - Plot configuration with calibration curve
| Param | Type | Description |
|---|---|---|
| yTrue | Array.<number> | True binary labels (0 or 1) |
| yProb | Array.<number> | Predicted probabilities |
| options | Object | {width, height, nBins} |
ordiplot(result, options) ⇒ Object
Generate unified ordination plot configuration Works with PCA, LDA, and RDA results
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| result | Object | Ordination result (from PCA, LDA, or RDA) |
| options | Object | Configuration options |
| options.type | string | Type of ordination ('pca', 'lda', 'rda') - auto-detected if not specified |
| options.colorBy | string | null | Array of colors/groups for points (optional) |
| options.labels | Array.<string> | null | Labels for points (optional) |
| options.showLoadings | boolean | Show loading vectors (PCA/RDA only) |
| options.showCentroids | boolean | Show class centroids (LDA only) |
| options.showConvexHulls | boolean | Show convex hulls around groups (optional) |
| options.axis1 | number | First axis to plot (default: 1) |
| options.axis2 | number | Second axis to plot (default: 2) |
| options.width | number | Plot width (default: 640) |
| options.height | number | Plot height (default: 400) |
| options.loadingScale | number | Scale factor for loading vectors (default: 3) |
plotHCA(result) ⇒ Object
Generate dendrogram data structure
Kind: global function
Returns: Object - Dendrogram tree structure
| Param | Type | Description |
|---|---|---|
| result | Object | HCA result from mva.hca.fit() |
dendrogramLayout(dendrogramData, options) ⇒ Object
Convert dendrogram to layout coordinates
Kind: global function
Returns: Object - Layout with coordinates
| Param | Type | Description |
|---|---|---|
| dendrogramData | Object | Result from plotHCA |
| options | Object | {width, height, orientation} |
plotLDA(result, options) ⇒ Object
Generate LDA scatter plot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| result | Object | LDA result from mva.lda.fit() |
| options | Object | {width, height, ldX, ldY} |
plotPCA(result, options) ⇒ Object
Generate PCA biplot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| result | Object | PCA result from mva.pca.fit() |
| options | Object | {colorBy, showLoadings, width, height} |
plotScree(result, options) ⇒ Object
Generate PCA scree plot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| result | Object | PCA result |
| options | Object | {width, height} |
plotRDA(result, options) ⇒ Object
Generate RDA triplot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| result | Object | RDA result from mva.rda.fit() |
| options | Object | {width, height, axis1, axis2} |
attachShow(config) ⇒ Object
Attach a .show() helper to the configuration if marks are present.
Kind: global function
Returns: Object - The same config with a non-enumerable show() helper
| Param | Type | Description |
|---|---|---|
| config | Object | Plot configuration object |
plotFeatureImportance(importances, options) ⇒ Object
Generate feature importance bar plot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| importances | Array.<Object> | Feature importance array |
| options | Object | {width, height, topN} |
plotPartialDependence(pdResult, options) ⇒ Object
Generate partial dependence plot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| pdResult | Object | Result from partialDependence() |
| options | Object | {width, height, featureName} |
plotCorrelationMatrix(corrResult, options) ⇒ Object
Generate correlation matrix heatmap configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| corrResult | Object | Result from correlationMatrix() |
| options | Object | {width, height} |
plotResiduals(residualData, options) ⇒ Object
Generate residual plot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| residualData | Object | Result from residualPlotData() |
| options | Object | {width, height, standardized} |
plotQQ(residualData, options) ⇒ Object
Generate Q-Q plot configuration for normality check
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| residualData | Object | Result from residualPlotData() |
| options | Object | {width, height} |
erfInv(x) ⇒ number
Approximate error function inverse (for Q-Q plot)
Kind: global function
Returns: number - Inverse erf
| Param | Type | Description |
|---|---|---|
| x | number | Input value |
plotLearningCurve(lcResult, options) ⇒ Object
Generate learning curve plot configuration
Kind: global function
Returns: Object - Plot configuration
| Param | Type | Description |
|---|---|---|
| lcResult | Object | Result from learningCurve() |
| options | Object | {width, height} |
fit(X, y, options) ⇒ Object
Fit OLS linear regression Supports two calling styles:
- Array/matrix style (backward compatible): fit(X, y, { intercept })
- Declarative table style: fit({ X: 'col' | ['col1','col2'], y: 'target', data, omit_missing, intercept })
Kind: global function
Returns: Object - {coefficients, fitted, residuals, rSquared, adjRSquared, se, n, p}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Matrix | Object | Design matrix or options object when using table style |
| y | Array.<number> | string | Response vector or (when using array/matrix style) ignored if options object provided |
| options | Object | { intercept: boolean, omit_missing: boolean } (when using array/matrix style) |
predict(coefficients, X, options) ⇒ Array.<number>
Predict using fitted model
Kind: global function
Returns: Array.<number> - Predictions
| Param | Type | Description |
|---|---|---|
| coefficients | Array.<number> | Model coefficients |
| X | Array.<Array.<number>> | Matrix | New design matrix |
| options | Object | {intercept: boolean} |
summary(model) ⇒ Object
Summary statistics for regression
Kind: global function
Returns: Object - Summary information
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model from fit() |
fit(X, y, groups, options) ⇒ Object
Fit simple random-intercept linear mixed model
Kind: global function
Returns: Object - {fixedEffects, randomEffects, varFixed, varRandom, logLikelihood}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Matrix | Fixed effects design matrix |
| y | Array.<number> | Response vector |
| groups | Array.<(number|string)> | Group indicators |
| options | Object | {intercept: boolean, maxIter: number, tol: number} |
predict(model, X, groups, options) ⇒ Array.<number>
Predict using fitted LMM
Kind: global function
Returns: Array.<number> - Predictions
| Param | Type | Description |
|---|---|---|
| model | Object | Fitted model |
| X | Array.<Array.<number>> | Matrix | Design matrix |
| groups | Array.<(number|string)> | Group indicators |
| options | Object | {intercept: boolean} |
sigmoid(z) ⇒ number
Logistic (sigmoid) function
Kind: global function
Returns: number - Probability between 0 and 1
| Param | Type | Description |
|---|---|---|
| z | number | Input value |
fit(X, y, options) ⇒ Object
Fit logistic regression using IRLS
Kind: global function
Returns: Object - {coefficients, fitted, logLikelihood, iterations, converged}
| Param | Type | Description |
|---|---|---|
| X | Array.<Array.<number>> | Matrix | Design matrix |
| y | Array.<number> | Binary response (0 or 1) |
| options | Object | {intercept: boolean, maxIter: number, tol: number} |
predict(coefficients, X, options) ⇒ Array.<number>
Predict probabilities using fitted model
Kind: global function
Returns: Array.<number> - Predicted probabilities
| Param | Type | Description |
|---|---|---|
| coefficients | Array.<number> | Model coefficients |
| X | Array.<Array.<number>> | Matrix | New design matrix |
| options | Object | {intercept: boolean} |
classify(probabilities, threshold) ⇒ Array.<number>
Classify based on threshold
Kind: global function
Returns: Array.<number> - Binary predictions (0 or 1)
| Param | Type | Description |
|---|---|---|
| probabilities | Array.<number> | Predicted probabilities |
| threshold | number | Classification threshold |