macro_rules! define_ml_algorithm {
(
name: $name:ident,
config: {
$(
$field:ident: $field_type:ty = $default:expr
$(=> validate($validator:expr))?
),* $(,)?
},
fit_fn: $fit_fn:ident,
predict_fn: $predict_fn:ident,
algorithm_type: $algorithm_type:ident
) => { ... };
}Expand description
Creates a complete ML algorithm with all necessary boilerplate
This macro generates:
- Configuration struct with validation
- State management (trained/untrained)
- Builder pattern implementation
- Core trait implementations
- Basic test suite
- Documentation templates
§Examples
ⓘ
use sklears_core::define_ml_algorithm;
define_ml_algorithm! {
name: LinearRegression,
config: {
fit_intercept: bool = true,
alpha: f64 = 1.0 => validate(|x| x >= 0.0),
max_iter: usize = 1000 => validate(|x| x > 0)
},
fit_fn: fit_linear_regression,
predict_fn: predict_linear_regression,
algorithm_type: supervised_regression
}