SGDRegressor
#include <Skigen/LinearModel>
template <typename Scalar = double>
class Skigen::SGDRegressor(alpha=1e-4, max_iter=1000, tol=1e-3, eta0=0.01, random_state=42)
Linear regressor fitted by minimizing a regularized empirical loss with SGD.
SGDRegressor implements regularized linear regression with stochastic gradient descent (squared error loss, L2 penalty).
Mirrors sklearn.linear_model.SGDRegressor.
Parameters:
-
alpha : Scalar, default=1e-4 Regularization constant (
Scalar, default1e-4). -
max_iter : int, default=1000 Maximum number of epochs (
int, default1000). -
tol : Scalar, default=1e-3 Stopping tolerance (
Scalar, default1e-3). -
eta0 : Scalar, default=0.01 Initial learning rate (
Scalar, default0.01). -
random_state : unsigned int, default=42 RNG seed (
unsigned int, default42).
Attributes:
-
coef : RowVectorType Parameter vector (1 × n_features).
-
intercept_value : Scalar Independent term in the decision function.
Methods
SKIGEN_PARAMS()
Fit the linear model with SGD.
Parameters:
-
X Training matrix of shape (n_samples, n_features).
-
y Target vector of shape (n_samples,).
Returns:
- result
Reference to the fitted estimator (
*this).
Throws:
std::invalid_argument— if X and y have inconsistent lengths.
partial_fit(X, y)
Online SGD update — runs one epoch on (X, y) starting from the current coef_ / intercept_, matching sklearn's SGDRegressor.partial_fit contract. The first call initialises the state to zero (no classes argument is needed for regression). Throws on feature-count mismatch with the first batch.
predict(X)
Predict using the linear model.
score(X, y)
Return the coefficient of determination on test data.
Example
Skigen::SGDRegressor<double> regressor;
regressor.fit(split_reg.X_train, split_reg.y_train);
std::cout << "=== SGD Regressor ===\n";
std::cout << "R²: " << regressor.score(split_reg.X_test, split_reg.y_test) << "\n";
std::cout << "Coef: " << regressor.coef() << "\n";