Skip to content
/ mlgo Public

A machine learning library written for Golang, each part designed entirely from scratch

License

Notifications You must be signed in to change notification settings

Hukyl/mlgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mlgo - A Golang Machine Learning Library

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.

Key Features

  1. Mathematical Foundation: Handwritten from derived mathematical proofs obtained from DeepLearning.AI courses, ensuring a solid theoretical basis.

  2. Open-Source Origins: Information was gathered from free resources on the internet, articles and posts.

  3. 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.

Example Code

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")
}

Author and Copyright

Andrii Shalaiev
Copyright © 2024 Andrii Shalaiev. All rights reserved.

References

Disclaimer

This library is a proof-of-concept and may not be suitable for production use. Use at your own risk.

About

A machine learning library written for Golang, each part designed entirely from scratch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages