RBF kernel estimation, fitting, and std-scaling helpers for Smile SVM/SVR.
RBF kernel estimation, fitting, and std-scaling helpers for Smile SVM/SVR.
(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.
(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.
(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.
(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).
(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).
(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.
(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
(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.
(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[][].
(transform-scale ds scaler)Apply a previously fitted scaler to ds.
Apply a previously fitted scaler to ds.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |