ml module

btQuant.ml.anomalyScore(trees, X)[source]

Compute anomaly scores from isolation forest.

Parameters:
  • trees – list of isolation trees

  • X – features to score

Returns:

anomaly scores (higher = more anomalous)

btQuant.ml.decisionTree(X, y, maxDepth=5)[source]

Decision tree classifier using Gini impurity.

Parameters:
  • X – features (n_samples, n_features)

  • y – target labels

  • maxDepth – maximum tree depth

Returns:

tree structure

Return type:

dict

btQuant.ml.gradientBoosting(X, y, nEstimators=100, learningRate=0.1, maxDepth=3)[source]

Gradient boosting regressor.

Parameters:
  • X – features

  • y – target values

  • nEstimators – number of boosting rounds

  • learningRate – learning rate (shrinkage)

  • maxDepth – maximum tree depth

Returns:

predict function

btQuant.ml.isolationForest(X, nTrees=100, maxSamples=None, maxDepth=10)[source]

Isolation forest for anomaly detection.

Parameters:
  • X – features (n_samples, n_features)

  • nTrees – number of trees

  • maxSamples – samples per tree (default all)

  • maxDepth – maximum tree depth

Returns:

list of isolation trees

btQuant.ml.kmeans(X, k=3, maxIters=100, tol=0.0001)[source]

K-means clustering.

Parameters:
  • X – features (n_samples, n_features)

  • k – number of clusters

  • maxIters – maximum iterations

  • tol – convergence tolerance

Returns:

centroids, labels

btQuant.ml.knn(XTrain, yTrain, XTest, k=3)[source]

K-nearest neighbors classifier.

Parameters:
  • XTrain – training features

  • yTrain – training labels

  • XTest – test features

  • k – number of neighbors

Returns:

predicted labels

btQuant.ml.lda(X, y, nComponents=None)[source]

Linear discriminant analysis.

Parameters:
  • X – features

  • y – class labels

  • nComponents – number of components

Returns:

transformed data, eigenvalues, eigenvectors

btQuant.ml.logisticRegression(X, y, learningRate=0.01, nIters=1000)[source]

Logistic regression classifier.

Parameters:
  • X – features

  • y – binary labels (0/1)

  • learningRate – learning rate

  • nIters – number of iterations

Returns:

weights, bias, predict function

btQuant.ml.naiveBayes(XTrain, yTrain, XTest)[source]

Gaussian naive Bayes classifier.

Parameters:
  • XTrain – training features

  • yTrain – training labels

  • XTest – test features

Returns:

predicted labels

btQuant.ml.pca(X, nComponents=None)[source]

Principal component analysis.

Parameters:
  • X – features (n_samples, n_features)

  • nComponents – number of components to keep

Returns:

transformed data, eigenvalues, eigenvectors

btQuant.ml.predictTree(tree, X)[source]

Predict using a regression or decision tree.

Parameters:
  • tree – tree structure from regressionTree or decisionTree

  • X – features to predict (n_samples, n_features)

Returns:

predictions array

btQuant.ml.randomForest(X, y, nEstimators=10, maxDepth=5, sampleRatio=0.8)[source]

Random forest regressor.

Parameters:
  • X – features

  • y – target values

  • nEstimators – number of trees

  • maxDepth – maximum tree depth

  • sampleRatio – fraction of samples per tree

Returns:

predict function

btQuant.ml.regressionTree(X, y, maxDepth=5)[source]

Regression tree using MSE splits.

Parameters:
  • X – features (n_samples, n_features)

  • y – target values

  • maxDepth – maximum tree depth

Returns:

tree structure

Return type:

dict