Liking cljdoc? Tell your friends :D

svm-techml-smile.core

Public API — re-exports all sub-namespaces for single-ns consumers.

Aliases here carry the defining var's :doc, :arglists, :file and :line, so (doc svm-techml-smile.core/foo) shows the real documentation and REPL-driven editor hover (Calva, CIDER) works. Static-only analysis (clj-kondo, Cursive's offline index) does not expand this macro and will show less — require the defining namespace directly if that is how your editor resolves symbols.

Public API — re-exports all sub-namespaces for single-ns consumers.

Aliases here carry the defining var's :doc, :arglists, :file and :line, so
(doc svm-techml-smile.core/foo) shows the real documentation and REPL-driven
editor hover (Calva, CIDER) works. Static-only analysis (clj-kondo, Cursive's
offline index) does not expand this macro and will show less — require the
defining namespace directly if that is how your editor resolves symbols.
raw docstring

build-columnclj

(build-column dataset spec)

Add a single column to dataset according to feature-spec.

Add a single column to dataset according to feature-spec.
sourceraw docstring

build-many-columnsclj

(build-many-columns dataset specs)

Reduce over a sequence of feature specs, adding each column in order.

Reduce over a sequence of feature specs, adding each column in order.
sourceraw docstring

cast-to-floatclj

(cast-to-float ds)

Cast every column in ds to :float32. Useful before feeding into Smile SVM/SVR.

Cast every column in ds to :float32. Useful before feeding into Smile SVM/SVR.
sourceraw docstring

dataset->arrayclj

(dataset->array ds)

Convert a tech.ml.dataset to a row-major double[][]: one row per observation, one column per feature, in (ds/column-names ds) order — the layout Smile's fit/predict expect. Same result as (.toArray (dataset->dataframe ds)) but without building the intermediate DataFrame.

Throws if any column has missing values (see assert-no-missing).

Convert a tech.ml.dataset to a row-major double[][]: one row per observation,
one column per feature, in (ds/column-names ds) order — the layout Smile's
fit/predict expect. Same result as (.toArray (dataset->dataframe ds)) but
without building the intermediate DataFrame.

Throws if any column has missing values (see assert-no-missing).
sourceraw docstring

dataset->dataframeclj

(dataset->dataframe ds)

Convert a tech.ml.dataset to a Smile DataFrame (one DoubleVector per column).

Convert a tech.ml.dataset to a Smile DataFrame (one DoubleVector per column).
sourceraw docstring

dscol->smilecolclj

(dscol->smilecol col)

Convert a tech.ml.dataset column to a Smile DoubleVector, preserving the column name.

Convert a tech.ml.dataset column to a Smile DoubleVector, preserving the column name.
sourceraw docstring

estimate-sigmaclj

(estimate-sigma scaled-ds)

Estimate the RBF Gaussian kernel bandwidth from a scaled feature matrix.

Follows the sklearn 'scale' convention: sigma = sqrt(0.5 * n_features * variance(flatten(X))) i.e. gamma = 1 / (n_features * X.var()). Note variance here is the sample variance (n-1 denominator); sklearn's X.var() uses n, so sigma runs a factor sqrt(n/(n-1)) high — under 0.01% for any matrix over 5k values.

Missing values are skipped, not propagated — bridge/dataset->array is what rejects them. Throws if sigma is not positive, since a zero-variance feature matrix would otherwise build a degenerate GaussianKernel.

Estimate the RBF Gaussian kernel bandwidth from a scaled feature matrix.

Follows the sklearn 'scale' convention:
  sigma = sqrt(0.5 * n_features * variance(flatten(X)))
i.e. gamma = 1 / (n_features * X.var()). Note `variance` here is the sample
variance (n-1 denominator); sklearn's X.var() uses n, so sigma runs a factor
sqrt(n/(n-1)) high — under 0.01% for any matrix over 5k values.

Missing values are skipped, not propagated — bridge/dataset->array is what
rejects them. Throws if sigma is not positive, since a zero-variance feature
matrix would otherwise build a degenerate GaussianKernel.
sourceraw docstring

evaluate-classifierclj

(evaluate-classifier kernel-machine features-array y-array)

Run a trained Smile SVM on features-array and return predictions + metrics.

kernel-machine — smile.classification.SVM (or compatible .predict implementor) features-array — double[][] y-array — int[] of true labels in {-1, +1}

Returns a map with :predictions (seq), :y-array, :accuracy, :precision, :sensitivity, :fallout, :confusion-matrix.

Run a trained Smile SVM on features-array and return predictions + metrics.

kernel-machine — smile.classification.SVM (or compatible .predict implementor)
features-array — double[][]
y-array        — int[] of true labels in {-1, +1}

Returns a map with :predictions (seq), :y-array, :accuracy, :precision,
:sensitivity, :fallout, :confusion-matrix.
sourceraw docstring

fit-RBF-SVMclj

(fit-RBF-SVM x y sigma tol C)

Train a Gaussian-kernel SVM classifier via Smile 5's SVM/fit. x — double[][], y — int[], sigma — RBF bandwidth, tol — tolerance, C — regularisation. SVM$Options(C tol epochs=2) preserves 2-epoch convergence of the old LASVM-based API.

Train a Gaussian-kernel SVM classifier via Smile 5's SVM/fit.
x — double[][], y — int[], sigma — RBF bandwidth, tol — tolerance, C — regularisation.
SVM$Options(C tol epochs=2) preserves 2-epoch convergence of the old LASVM-based API.
sourceraw docstring

fit-RBF-SVRclj

(fit-RBF-SVR x y sigma eps C)

Train a Gaussian-kernel SVR via Smile 5's SVR.fit. x — double[][], y — double[], sigma — RBF bandwidth, eps — epsilon tube, C — regularisation. tol=0.01 is the Smile SVR default; irrelevant for the RBF kernel but required by the API.

Train a Gaussian-kernel SVR via Smile 5's SVR.fit.
x — double[][], y — double[], sigma — RBF bandwidth, eps — epsilon tube, C — regularisation.
tol=0.01 is the Smile SVR default; irrelevant for the RBF kernel but required by the API.
sourceraw docstring

fit-scaleclj

(fit-scale ds)

Fit a standard scaler on ds. Returns an opaque scaler map (tech.ml.dataset.math format).

Fit a standard scaler on ds. Returns an opaque scaler map (tech.ml.dataset.math format).
sourceraw docstring

labels->01clj

(labels->01 coll)

Convert SVM {-1, +1} integer labels to {0, 1} for Smile classification metrics. Smile's Accuracy/Precision/Sensitivity/Fallout/ConfusionMatrix expect 0-based class indices — passing -1 causes ArrayIndexOutOfBoundsException.

Convert SVM {-1, +1} integer labels to {0, 1} for Smile classification metrics.
Smile's Accuracy/Precision/Sensitivity/Fallout/ConfusionMatrix expect 0-based class
indices — passing -1 causes ArrayIndexOutOfBoundsException.
sourceraw docstring

one-hot-reducerclj

(one-hot-reducer dataset cols removals)

One-hot encode each column in cols, then drop any columns listed in removals. removals is only needed for OLS models (to avoid perfect collinearity); SVR models should pass [] for removals.

One-hot encode each column in cols, then drop any columns listed in removals.
removals is only needed for OLS models (to avoid perfect collinearity);
SVR models should pass [] for removals.
sourceraw docstring

predictclj

(predict model features)

Predict one observation. features is a double[] in training column order. Reflection-free replacement for (.predict ^KernelMachine km ^doubles row).

Predict one observation. features is a double[] in training column order.
Reflection-free replacement for (.predict ^KernelMachine km ^doubles row).
sourceraw docstring

predict-allclj

(predict-all model features)

Predict a whole feature matrix. features is a double[][] (see bridge/dataset->array); returns a double[] of predictions.

Predict a whole feature matrix. features is a double[][] (see
bridge/dataset->array); returns a double[] of predictions.
sourceraw docstring

prepare-featuresclj

(prepare-features x-ds)

Fit a standard scaler on x-ds, scale it, and return a map with: :scaler — fitted scaler (pass to transform-scale for new data) :sigma — estimated RBF bandwidth :features-array — double[][] ready for Smile fit/predict

Fit a standard scaler on x-ds, scale it, and return a map with:
:scaler         — fitted scaler (pass to transform-scale for new data)
:sigma          — estimated RBF bandwidth
:features-array — double[][] ready for Smile fit/predict
sourceraw docstring

prepare-svr-dataclj

(prepare-svr-data spec)

Apply the model spec pipeline and return the spec augmented with Smile-ready arrays.

Steps:

  1. apply :transformations (build-many-columns DSL)
  2. fit std-scaler on :std-scale columns
  3. drop :removals columns
  4. one-hot encode :one-hot columns (dropping :one-hot :removals)
  5. apply the std-scaler
  6. split into feature matrix (everything except :id-name and :y column)
  7. compute sigma, features-array (double[][]), y-array (double[])

The returned spec has :std-scale :scaler filled in — pass it to svm-techml-smile.kernel/transform-scale to normalise new observations.

Apply the model spec pipeline and return the spec augmented with Smile-ready arrays.

Steps:
  1. apply :transformations (build-many-columns DSL)
  2. fit std-scaler on :std-scale columns
  3. drop :removals columns
  4. one-hot encode :one-hot columns (dropping :one-hot :removals)
  5. apply the std-scaler
  6. split into feature matrix (everything except :id-name and :y column)
  7. compute sigma, features-array (double[][]), y-array (double[])

The returned spec has :std-scale :scaler filled in — pass it to
svm-techml-smile.kernel/transform-scale to normalise new observations.
sourceraw docstring

rsqclj

(rsq y predictions)

In-sample R^2 against an origin baseline: 1 - sum((y - yhat)^2) / sum(y^2).

Note this is the UNCENTERED R^2 — the denominator is sum(y^2), not sum((y - ybar)^2), so it measures fit against zero rather than against the mean of y. That is what the jasmine quant-screen models have always reported; it reads higher than the textbook R^2 whenever y has a non-zero mean.

sum((y - yhat)^2) is exactly what smile.validation.metric.RSS/of computes, so this needs no Smile call at all.

In-sample R^2 against an origin baseline: 1 - sum((y - yhat)^2) / sum(y^2).

Note this is the UNCENTERED R^2 — the denominator is sum(y^2), not
sum((y - ybar)^2), so it measures fit against zero rather than against the
mean of y. That is what the jasmine quant-screen models have always reported;
it reads higher than the textbook R^2 whenever y has a non-zero mean.

sum((y - yhat)^2) is exactly what smile.validation.metric.RSS/of computes, so
this needs no Smile call at all.
sourceraw docstring

scale-new-featuresclj

(scale-new-features x-ds scaler)

Scale a new feature dataset with a previously fitted scaler and return double[][].

Scale a new feature dataset with a previously fitted scaler and return double[][].
sourceraw docstring

svr-model-specclj

(svr-model-spec dataset
                id-col
                y-col
                std-scale-cols
                &
                {:keys [type predict-fn removals transformations one-hot-cols
                        one-hot-removals]
                 :or {type :svr
                      predict-fn identity
                      removals []
                      transformations nil
                      one-hot-cols []
                      one-hot-removals []}})

Build a base cross-sectional SVR model spec.

Required args: dataset — tech.ml.dataset id-col — keyword identifying the row-ID column (e.g. :Bond, :ISIN) y-col — keyword naming the target column std-scale-cols — seq of columns to standardise

Optional kwargs: :type — :svr (default) or :ols :predict-fn — inverse-transform for y (default identity) :removals — extra columns to drop before the feature matrix (default []) :transformations — feature-spec DSL steps to apply first (default nil) :one-hot-cols — columns to one-hot encode (default []) :one-hot-removals— one-hot columns to drop after encoding (default [])

Build a base cross-sectional SVR model spec.

Required args:
  dataset          — tech.ml.dataset
  id-col           — keyword identifying the row-ID column (e.g. :Bond, :ISIN)
  y-col            — keyword naming the target column
  std-scale-cols   — seq of columns to standardise

Optional kwargs:
  :type            — :svr (default) or :ols
  :predict-fn      — inverse-transform for y (default identity)
  :removals        — extra columns to drop before the feature matrix (default [])
  :transformations — feature-spec DSL steps to apply first (default nil)
  :one-hot-cols    — columns to one-hot encode (default [])
  :one-hot-removals— one-hot columns to drop after encoding (default [])
sourceraw docstring

transform-scaleclj

(transform-scale ds scaler)

Apply a previously fitted scaler to ds.

Apply a previously fitted scaler to ds.
sourceraw docstring

ts-model-specclj

(ts-model-spec
  dataset
  &
  {:keys [seed start-idx last-idx training id-name]
   :or {seed 42 start-idx 100 last-idx 250 training 0.7 id-name :date}})

Build a base time-series SVM classification spec.

Required args: dataset — tech.ml.dataset (one row per time step)

Optional kwargs (all have defaults): :seed — random seed for deterministic shuffle (default 42) :start-idx — warm-up rows to skip at the start (default 100) :last-idx — rows reserved at the end for live prediction (default 250) :training — train fraction of middle rows (default 0.7) :id-name — row-ID column keyword (default :date)

Callers must assoc :signal, :transform, and :features before passing to the processing pipeline (process-model / split-data / svm-prepare-data in the host project).

Build a base time-series SVM classification spec.

Required args:
  dataset  — tech.ml.dataset (one row per time step)

Optional kwargs (all have defaults):
  :seed       — random seed for deterministic shuffle (default 42)
  :start-idx  — warm-up rows to skip at the start (default 100)
  :last-idx   — rows reserved at the end for live prediction (default 250)
  :training   — train fraction of middle rows (default 0.7)
  :id-name    — row-ID column keyword (default :date)

Callers must assoc :signal, :transform, and :features before passing to the
processing pipeline (process-model / split-data / svm-prepare-data in the
host project).
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close