Welcome to mlgo, a Golang machine learning library crafted from derived mathematical proofs obtained through DeepLearning.AI courses. This library serves as a proof-of-concept as a learning project for deeper understanding of the underlying concepts. Was greatly inspired by Keras, machine learning library for Python, while adapting to the idioms and conventions of Golang.
-
Mathematical Foundation: Handwritten from derived mathematical proofs obtained from DeepLearning.AI courses, ensuring a solid theoretical basis.
-
Open-Source Origins: Information was gathered from free resources on the internet, articles and posts.
-
Proof-of-Concept: Not designed for extensive optimization, the library serves as a proof-of-concept to demonstrate the feasibility of implementing machine learning concepts in Golang.
package main
import (
"fmt"
"log"
"github.com/Hukyl/mlgo/activation"
"github.com/Hukyl/mlgo/datasets"
"github.com/Hukyl/mlgo/loss"
"github.com/Hukyl/mlgo/metric"
"github.com/Hukyl/mlgo/nn"
"github.com/Hukyl/mlgo/nn/layers"
"github.com/Hukyl/mlgo/utils"
)
func main() {
parameters := utils.NeuralNetworkParameters{
EpochCount: 30,
InitialLearningRate: 0.01,
AccuracyMetric: metric.CategoricalAccuracy{},
}
// Preprocess data
X_train, Y_train := prepareData(datasets.MnistDataset("your/path/file.csv"))
// Define the structure of the layers
l := []layers.Layer{
layers.NewRandomDense(
[2]int{784, 20},
activation.Sigmoid{},
layers.XavierUniformInitialization{},
),
layers.NewRandomDense(
[2]int{20, 10},
activation.Sigmoid{},
layers.XavierUniformInitialization{},
),
}
model := nn.NewNeuralNetwork(
l,
loss.LogLoss[float64]{},
)
// Train your network
err := model.Train(X_train, Y_train, parameters)
if err != nil {
log.Fatal(err)
}
Y_pred := model.Predict(X_train[0])
fmt.Println(parameters.AccuracyMetric.Calculate(Y_train[0], Y_pred))
nn.DumpNeuralNetwork(model, "path/to/dump.json")
}
Andrii Shalaiev
Copyright © 2024 Andrii Shalaiev. All rights reserved.
This library is a proof-of-concept and may not be suitable for production use. Use at your own risk.