Skip to main content

Logistic Regression

UDTF: cuml_logistic_regression

Official cuML reference: Python API

Fit a query-local cuML logistic or softmax classifier and score independent rows.

Quickstart​

Register the relations referenced by the parenthesized SELECT clauses below. For metadata validation, the descriptor names training_vectors and predict_vectors.

SELECT id, prediction, probability
FROM cuml_logistic_regression(
training => (SELECT id, d0, label FROM train),
predict => (SELECT id, d0 FROM test)
)
ORDER BY row_ordinal;

Inputs​

Each relation argument is a parenthesized SELECT subquery. Metadata validation resolves a registered table or view for the same role without scanning its rows. See ML Inputs for the ID, feature element, Float64 narrowing, null, finite-value, and runtime-dimension contract.

RoleRequiredValidation referenceDescription
trainingyestableDense features and an Int32 label used to fit the query-local model.
predictyestableIndependent dense feature rows scored with the query-local model; must omit label.

Vector element types​

Feature values must be Float32 or Float64.

Arguments and options​

Scalar SQL arguments​

ArgumentTypeRequiredDefaultConstraintsDescription
change_tolnumberno0.00001minimum 0QN objective change tolerance.
fit_interceptbooleannotrueFit an intercept.
grad_tolnumberno0.0001minimum 0QN gradient tolerance.
lbfgs_memoryintegerno5minimum 1; maximum 2147483647L-BFGS history length.
linesearch_max_iterintegerno50minimum 1; maximum 2147483647Maximum line-search iterations.
max_iterintegerno1000minimum 1; maximum 2147483647Maximum QN iterations.
penalty_l1numberno0minimum 0L1 penalty.
penalty_l2numberno0minimum 0L2 penalty.
penalty_normalizedbooleannotrueNormalize the penalty by row count.

Vector binding shapes​

Each relation subquery projects an id and either feature columns in dimension order or one list column, with the element types listed under Vector element types. The training relation also projects an Int32 label; the predict relation omits it. Nullable field types are accepted. A null ID, feature value, list row, list element, or label fails the query.

The list-column shape excludes other feature columns. See ML Inputs for the allowed list containers and runtime checks.

Output​

ColumnTypeNullableDescription
row_ordinalUInt64noEvaluated input row position, including when IDs repeat. Follows the input's top-level ORDER BY on output columns; unspecified without one.
idsame_as_predict.idnoLogical ID from the predict relation.
predictionInt32noPredicted zero-based class index; a tie between classes takes the lowest index.
probabilityFloat32noProbability of the predicted class, as cuML's predict_proba defines it: the sigmoid of the decision score for two classes, the softmax over the decision scores for three or more.

The output schema depends on the call. Run gpu_validate_call against registered relations to inspect the schema that the validated ID types and literal options produce.

Examples​

How many mistakes does each classifier make in a later quarter?​

Logistic regression and random forest train on 1,560,000 Win32 files from weeks 0 to 51, using the same 512 normalized byte and byte-entropy histogram features. Evaluation uses 359,994 later Win32 files from weeks 52 to 63 and counts both benign files flagged and malicious files missed.

The query fits both models, predicts labels for the later files, then joins the known labels and aggregates the errors. Predictions are class IDs 0 and 1. Test labels are joined after prediction.

-- Unified temporal comparison training both logistic regression and random forest
-- on the full deduplicated Win32 training dataset (~1.56M files) and predicting on
-- the full held-out Win32 test dataset (359,994 files).
-- Evaluates both query-local classifiers side-by-side in one GPU statement.
WITH logistic AS (
SELECT p.id, p.prediction, m.label, m.week_id, m.sha256, m.family
FROM cuml_logistic_regression(
training => (
SELECT v.id, v.histogram AS vector, v.label
FROM ember_research_vectors_train v
JOIN ember_metadata_train m ON m.id = v.id
WHERE m.file_type = 'Win32'
ORDER BY v.id
),
predict => (
SELECT v.id, v.histogram AS vector
FROM ember_research_vectors_test v
JOIN ember_metadata_test m ON m.id = v.id
WHERE m.file_type = 'Win32'
ORDER BY v.id
),
max_iter => 1000,
penalty_l2 => 1.0
) p
JOIN ember_metadata_test m ON m.id = p.id
),
random_forest AS (
SELECT p.id, p.prediction, m.label, m.week_id, m.sha256, m.family
FROM cuml_random_forest_classifier(
training => (
SELECT v.id, v.histogram AS vector, v.label
FROM ember_research_vectors_train v
JOIN ember_metadata_train m ON m.id = v.id
WHERE m.file_type = 'Win32'
ORDER BY v.id
),
predict => (
SELECT v.id, v.histogram AS vector
FROM ember_research_vectors_test v
JOIN ember_metadata_test m ON m.id = v.id
WHERE m.file_type = 'Win32'
ORDER BY v.id
),
n_trees => 100,
max_depth => 12,
seed => 42
) p
JOIN ember_metadata_test m ON m.id = p.id
),
classified AS (
SELECT 'logistic' AS model, id, prediction, label FROM logistic
UNION ALL
SELECT 'random_forest' AS model, id, prediction, label FROM random_forest
)
SELECT model, COUNT(*) AS files,
SUM(CASE WHEN prediction = 1 AND label = 1 THEN 1 ELSE 0 END) AS true_positive,
SUM(CASE WHEN prediction = 1 AND label = 0 THEN 1 ELSE 0 END) AS false_positive,
SUM(CASE WHEN prediction = 0 AND label = 1 THEN 1 ELSE 0 END) AS false_negative,
SUM(CASE WHEN prediction = 0 AND label = 0 THEN 1 ELSE 0 END) AS true_negative
FROM classified
GROUP BY model
ORDER BY model;

The later test set contains 179,994 benign and 180,000 malicious files.

ModelBenign flaggedFalse-positive rateMalicious missedMiss rate
Logistic regression24,67913.7%30,58617.0%
Random forest9,2395.1%23,46813.0%

The query took 1256.11 s.

Random forest flags 15,440 fewer benign files and misses 7,118 fewer malicious files in this fit. It still misses 23,468 malicious files. These results describe one fit with the recorded options. Repeated training can change the logistic result.

The full-cohort capture records the query ID, cohort counts and observed repeat range.

Limits​

  • Training labels must be Int32 contiguous classes 0..C-1 and must not be null; predict must omit label and match the feature dimension.
  • Binary labels use logistic loss; three or more classes use softmax. Reaching max_iter is not an error.
  • probability covers only the predicted class; per-class probabilities are not returned. Class weights are not exposed, so threshold probability to trade precision for recall.
  • The model is query-local. An empty predict relation returns an empty result without a native call.
  • Coefficients and scores can differ slightly between runs, because the loss reduction accumulates with floating-point atomics; there is no seed option.
  • Float64 features, as wide columns or list elements, are narrowed to Float32 on the device before training or inference. Each value rounds to the nearest Float32, which keeps about seven significant digits; a value beyond the Float32 range becomes infinite and fails the query.