微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GoLearn Go 机器学习框架

程序名称:GoLearn

授权协议: MIT

操作系统: 跨平台

开发语言: Google Go

GoLearn 介绍

GoLearn 是一款 Go 语言机器学习框架,示例代码

package main

import (
    "fmt"

    "github.com/sjwhitworth/golearn/base"
    "github.com/sjwhitworth/golearn/evaluation"
    "github.com/sjwhitworth/golearn/knn"
)

func main() {
    // Load in a dataset, with headers. Header attributes will be stored.
    // Think of instances as a Data Frame structure in R or Pandas.
    // You can also create instances from scratch.
    rawData, err := base.ParseCSVToInstances("datasets/iris.csv", false)
    if err != nil {
        panic(err)
    }

    // Print a pleasant summary of your data.
    fmt.Println(rawData)

    //Initialises a new KNN classifier
    cls := knn.NewKnnClassifier("euclidean", 2)

    //Do a training-test split
    trainData, testData := base.InstancesTrainTestSplit(rawData, 0.50)
    cls.Fit(trainData)

    //Calculates the Euclidean distance and returns the most popular label
    predictions := cls.Predict(testData)
    fmt.Println(predictions)

    // Prints precision/recall metrics
    confusionMat, err := evaluation.GetConfusionMatrix(testData, predictions)
    if err != nil {
        panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error()))
    }
    fmt.Println(evaluation.GetSummary(confusionMat))
}

GoLearn 官网

https://github.com/sjwhitworth/golearn

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐