Science
vml
Classic machine learning algorithms, written in Venutian with no other packages.
Released v1.0.0 · 2026-09-28use "stdlib/ml.ven"
Classic machine learning written in Venutian with no other packages: linear and logistic regression, with fit and predict functions.
model = linear_regression_fit([1.0, 2.0, 3.0, 4.0], [3.0, 5.0, 7.0, 9.0])
print predict_linear(model, 5.0)
:: 11.0
Reference (15 functions)
API reference
Linear regression
Ordinary least squares, closed form.
linear_regression_fit(x, y)
Fits a straight line to (x, y) points using ordinary least squares.
m = linear_regression_fit([1.0, 2.0, 3.0, 4.0], [3.0, 5.0, 7.0, 9.0])
m.slope
:: 2.0
m.intercept
:: 1.0predict_linear(model, x)
Scores one x value against a fitted LinearModel.
m = linear_regression_fit([1.0, 2.0, 3.0, 4.0], [3.0, 5.0, 7.0, 9.0])
predict_linear(m, 5.0)
:: 11.0Logistic regression (gradient descent)
sigmoid(z)
sigmoid(0.0)
:: 0.5
sigmoid(2.0)
:: 0.8807970779778823logistic_regression_fit(x, y, learning_rate, iterations)
Fits a binary logistic regression model by batch gradient descent.
lm = logistic_regression_fit([[0.0], [1.0], [2.0], [3.0]], [0, 0, 1, 1], 0.5, 2000)
predict_logistic_label(lm, [3.0])
:: 1
predict_logistic_label(lm, [0.0])
:: 0predict_logistic(model, x)
Scores one feature vector against a fitted LogisticModel as a probability.
lm = logistic_regression_fit([[0.0], [1.0], [2.0], [3.0]], [0, 0, 1, 1], 0.5, 2000)
predict_logistic(lm, [3.0])
:: 0.999987151069753predict_logistic_label(model, x)
lm = logistic_regression_fit([[0.0], [1.0], [2.0], [3.0]], [0, 0, 1, 1], 0.5, 2000)
predict_logistic_label(lm, [3.0])
:: 1K-means clustering (Lloyd's algorithm)
euclidean_distance(a, b)
The straight line (Euclidean) distance between two of equal length points.
euclidean_distance([0.0, 0.0], [3.0, 4.0])
:: 5.0nearest_centroid_index(point, centroids)
Gives back the index of the centroid closest to point.
nearest_centroid_index([0.0, 0.0], [[0.0, 0.0], [10.0, 10.0]])
:: 0mean_point(points)
The per coordinate mean (centroid) of a non-empty List of points.
mean_point([[0.0, 0.0], [2.0, 2.0], [4.0, 4.0]])
:: [2.0, 2.0]k_means(points, k, iterations)
Partitions points into k clusters by Lloyd's algorithm (k-means).
result = k_means([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [10.0, 10.0], [10.0, 11.0], [11.0, 10.0]], 2, 10)
result[1]
:: either [0, 0, 0, 1, 1, 1] or [1, 1, 1, 0, 0, 0], the near-origin points are always grouped apart from the far ones, but which cluster index gets which label depends on the random initial centroidsK-nearest neighbors (majority vote)
k_nearest_neighbors(training_points, training_labels, query, k)
Classifies query by majority vote among its k nearest training points.
training_points = [[0.0, 0.0], [0.0, 1.0], [5.0, 5.0], [5.0, 6.0]]
training_labels = ["a", "a", "b", "b"]
k_nearest_neighbors(training_points, training_labels, [0.2, 0.2], 3)
:: "a"Train/test split
train_test_split(x, y, test_fraction)
Randomly splits (x, y) rows into training and test sets.
splitres = train_test_split([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 0.3)
length(splitres[2])
:: 3, as_integer(10 * 0.3) test rows; which 3 rows are chosen varies between callsEvaluation metrics
accuracy_score(predicted, actual)
The fraction of predictions that exactly match the actual labels.
accuracy_score([1, 0, 1, 1], [1, 0, 0, 1])
:: 0.75confusion_matrix(predicted, actual)
confusion_matrix([0, 1, 1, 0, 1], [0, 0, 1, 1, 1])
:: [[1, 1], [1, 2]]Feature scaling
normalize_features(x)
normalize_features([[0.0, 10.0], [5.0, 20.0], [10.0, 30.0]])
:: [[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]]