SimpleLinearRegression<T>
Models & Types · AiDotNet.Prototypes
Simple linear regression model for prototype validation. Demonstrates GPU acceleration for traditional machine learning algorithms.
How It Works
Linear regression model: y = X @ weights + bias
This implementation uses vectorized operations throughout, enabling GPU acceleration when using float type with GPU engine enabled.
Constructors
| Constructor | Summary |
|---|---|
SimpleLinearRegression(int numFeatures) |
Initializes a new instance of the SimpleLinearRegression. |
Properties
| Property | Summary |
|---|---|
bool IsTrained { get; } |
Gets whether the model has been trained. |
int NumFeatures { get; } |
Gets the number of features. |
Methods
| Method | Summary |
|---|---|
PrototypeVector<T> GetWeights() |
Gets the learned weights. |
PrototypeVector<T> PredictBatch(PrototypeVector<T> X, int numSamples) |
Makes predictions for a batch of samples. |
T ComputeMSE(PrototypeVector<T> predictions, PrototypeVector<T> targets) |
Computes Mean Squared Error. |
T ComputeR2Score(PrototypeVector<T> predictions, PrototypeVector<T> targets) |
Computes R² score (coefficient of determination). |
T GetBias() |
Gets the learned bias. |
T Predict(PrototypeVector<T> features) |
Makes a prediction for a single sample. |
string ToString() |
Returns a string representation of the model. |
void Train(PrototypeVector<T> X, PrototypeVector<T> y, int numSamples, double learningRate, int numEpochs, bool verbose) |
Trains the model using gradient descent. |