![]() |
slope 6.6.0
|
First, we define our model. Let's use logistic regression, by setting the loss to "logistic".
Next, we set the data matrix x and the response vector y. Here we use some toy data.
Finally, we call the path() method to fit the full SLOPE path.
Now we can retrieve the coefficients by calling res.getCoefs().
By default, fit() and path() interpret supplied alpha values as absolute penalty scales. To choose them relative to the null-model threshold, set the alpha scale to "relative":
Each supplied value multiplies alpha_max, the smallest alpha that gives zero coefficients. The model computes this threshold using the current loss, intercept, normalization, observation weights, and lambda sequence. A value of 1.0 gives the null model, 0.1 uses 10% of that penalty scale, and 0.0 removes the penalty. Values above 1.0 are also allowed. Values must be finite and nonnegative, and path values must be in nonincreasing order. An all-zero lambda sequence leaves the model unpenalized regardless of alpha.
Calling path(x, y) still generates the usual automatic path. Noise-based alpha estimation and cross-validation retain their absolute penalty scales. SlopeFit::getAlpha() and SlopePath::getAlpha() always return the absolute values used by the solver. Set model.setAlphaScale("absolute") before passing those values back to fit() or path().
Pass one observation weight per row to fit a weighted model. Weights must be finite and nonnegative, and at least one weight must be positive. An empty weight vector gives every observation the same weight. The weighted objective is
\[ \frac{1}{\sum_i w_i}\sum_i w_i\ell_i(\beta_0,\beta) + \alpha\sum_j\lambda_j|\beta|_{(j)}. \]
Multiplying every weight by the same positive number leaves the fit unchanged. Zero-weight rows do not contribute to the objective or to computed feature centers and scales. Inputs must still satisfy the usual data validation rules. Standardization uses the weighted mean and population standard deviation. Manual centers and scales retain their supplied values. L1 and L2 feature scales use weighted norms with weights normalized to the number of positive-weight rows. Minima, ranges, and maximum absolute values use only positive-weight rows. Integer weights reproduce repeated observations with default standardization; L1 and L2 scales do not promise that equivalence. Multinomial classes are inferred from all supplied responses, including zero-weight rows.
Weights are the final optional argument to fit() and path(), after the interrupt callback:
Supply weights again when relaxing a fit. For a single fit, weights follow the optional intercept and coefficient warm starts. Pass the original predictors, before normalization; relaxation uses just-in-time normalization and does not modify them. For a path, weights follow gamma:
Cross-validation accepts weights after its configuration:
Automatically generated folds are identical across platforms for the same sample count, fold count, number of repetitions, and config.random_seed. Fold assignments differ from releases that used std::shuffle. Set config.predefined_folds to reuse saved fold assignments.
Each training and validation subset normalizes its own weights. Validation metrics use observation weights, and the reported mean and standard error continue to give each fold equal weight. Every training and validation subset must have positive total weight.
The same row weights apply to every response column, including multiresponse quadratic models and multinomial models. Automatic noise-based alpha estimation and automatic Gaussian lambda calibration do not support nonuniform weights. Use the default BH sequence, another supported sequence, or an explicit lambda vector instead.
The Julia bindings retain the original entry points and add fit_slope_dense_weighted, fit_slope_sparse_weighted, cv_slope_dense_weighted, and cv_slope_sparse_weighted. These functions take the same arguments as their original counterparts, followed by a Vector{Float64} of observation weights.