Bundle Machine learning library with linear regression, logistic regression, k-means clustering, and matrix operations. Designed for tabular data; supports training, prediction, and model evaluation. Compile with -lib ml.
LogisticRegression
Logistic regression using gradient descent with sigmoid activation. Binary classification only.
X := [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]];
y := [[0.0], [0.0], [0.0], [1.0]];
model := LogisticRegression->New(0.1, 1000);
model->Fit(X, y);
labels := model->PredictClass([[1.0, 1.0]]);
labels[0]->PrintLine();Operations
Fit #
Fits the model to training data using gradient descent.
method : public : Fit(X:Float[,], y:Float[,]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix (rows=samples, cols=features) |
| y | Float | target array (0.0 or 1.0 values, rows=samples, cols=1) |
Return
| Type | Description |
|---|---|
| Bool | true if fitting succeeded |
Example
X := [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
y := [[0.0], [0.0], [1.0]];
model := LogisticRegression->New(0.1, 200);
model->Fit(X, y);GetWeights #
Gets the learned weights.
method : public : GetWeights() ~ Float[]Return
| Type | Description |
|---|---|
| Float | weight array, or Nil if not fitted |
IsFitted #
Whether the model has been fitted.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if fitted |
LogSigmoid # function
Sigmoid activation function
function : LogSigmoid() ~ FloatParameters
| Name | Type | Description |
|---|---|---|
New # constructor
Constructor
New(learning_rate:Float, iterations:Int)Parameters
| Name | Type | Description |
|---|---|---|
| learning_rate | Float | step size for gradient descent |
| iterations | Int | number of training iterations |
Example
model := LogisticRegression->New(0.01, 500);Predict #
Predicts probabilities for input data.
method : public : Predict(X:Float[,]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix |
Return
| Type | Description |
|---|---|
| Float | probability array (values between 0 and 1) |
Example
probs := model->Predict([[2.0, 3.0]]);
"Probability: {$probs[0]}"->PrintLine();PredictClass #
Predicts class labels for input data (threshold 0.5).
method : public : PredictClass(X:Float[,]) ~ Bool[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix |
Return
| Type | Description |
|---|---|
| Bool | boolean class predictions |
Example
labels := model->PredictClass([[5.0, 6.0], [1.0, 0.5]]);
each(label in labels) {
label->PrintLine();
};