RegressionBase<T>
Base Classes · AiDotNet.Regression
Provides a base implementation for regression algorithms that model the relationship between a dependent variable and one or more independent variables.
Implements: IFeatureAware, IGradientComputable<T, Matrix<T>, Vector<T>>, IModelShape, IParameterManifestProvider, IRegression<T>
Known derived types: BayesianRegression<T>, ElasticNetRegression<T>, GammaRegression<T>, GeneralizedAdditiveModel<T>, GeneralizedLinearMixedModel<T>, GeneticAlgorithmRegression<T>, HarRvModel<T>, InverseGaussianRegression<T>, LassoRegression<T>, LinearMixedModel<T>, LogisticRegression<T>, MultinomialLogisticRegression<T>, MultipleRegression<T>, MultivariateRegression<T>, NegativeBinomialRegression<T>, OrthogonalRegression<T>, PartialLeastSquaresRegression<T>, PoissonRegression<T>, PolynomialRegression<T>, PrincipalComponentRegression<T>, QuantileRegression<T>, RidgeRegression<T>, RobustRegression<T>, SimpleRegression<T>, StepwiseRegression<T>, TimeSeriesRegression<T>, TweedieRegression<T>, WeightedRegression<T>
For Beginners
Regression is a statistical method for modeling the relationship between variables. This base class provides the foundation for different regression techniques, handling common operations like making predictions and saving/loading models. Think of it as a template that specific regression algorithms can customize while reusing the shared functionality.
How It Works
This abstract class implements common functionality for regression models, including prediction, serialization/deserialization, and solving linear systems. Specific regression algorithms should inherit from this class and implement the Train method.
The class supports various options like regularization to prevent overfitting and different decomposition methods for solving linear systems.
Properties
| Property | Summary |
|---|---|
ILossFunction<T> DefaultLossFunction { get; } |
|
ParameterLayoutSnapshot ParameterLayout { get; } |
|
T Intercept { get; set; } |
Gets or sets the intercept (bias) term of the regression model. |
Vector<T> Coefficients { get; set; } |
Gets or sets the coefficients (weights) of the regression model. |
bool HasIntercept { get; } |
Gets a value indicating whether the model includes an intercept term. |
bool SupportsParameterInitialization { get; } |
|
long ParameterCount { get; } |
|
string[] FeatureNames { get; set; } |
Gets or sets the feature names. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
Gets the feature importance scores as a dictionary. |
DynamicShapeInfo GetDynamicShapeInfo() |
|
IEnumerable<int> GetActiveFeatureIndices() |
Gets the indices of features that are actively used in the model. |
IFullModel<T, Matrix<T>, Vector<T>> Clone() |
Creates a clone of the regression model. |
IFullModel<T, Matrix<T>, Vector<T>> DeepCopy() |
Creates a deep copy of the regression model. |
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
Creates a new instance of the model with specified parameters. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the model. |
ModelOptions GetOptions() |
|
Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T> lossFunction) |
|
Vector<T> GetParameters() |
Returns the base coefficient surface followed by generated, stable-ID additional state. |
Vector<T> Predict(Matrix<T> input) |
Makes predictions for the given input data. |
Vector<T> SanitizeParameters(Vector<T> parameters) |
|
bool IsFeatureUsed(int featureIndex) |
Determines whether a specific feature is used in the model. |
byte[] Serialize() |
Serializes the model to a byte array. |
int[] GetInputShape() |
Saves the regression model to a file. |
int[] GetOutputShape() |
|
void ApplyGradients(Vector<T> gradients, T learningRate) |
|
void Deserialize(byte[] modelData) |
Deserializes the model from a byte array. |
void Dispose() |
|
void LoadModel(string filePath) |
Loads a regression model from a file. |
void LoadState(Stream stream) |
Loads the model’s state from a stream. |
void SaveModel(string filePath) |
|
void SaveState(Stream stream) |
Saves the model’s current state to a stream. |
void SetActiveFeatureIndices(IEnumerable<int> featureIndices) |
Sets the active feature indices for this model. |
void SetCoefficientsAndIntercept(Vector<T> coefficients, T intercept) |
Sets the coefficients and intercept directly for deserialization purposes. |
void SetParameters(Vector<T> parameters) |
Restores the base coefficient surface and generated additional state from one exact layout. |
void Train(Matrix<T> x, Vector<T> y) |
Trains the regression model on the provided data. |