Giter Site home page Giter Site logo

elahe-dastan / newborn Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 396 KB

A library for ML algorithms

Go 100.00%
regression algorithms knn knn-classification linear-regression polynomial-regression logistic-regression ml machine-learning dataset math-calculation go gola

newborn's Introduction

Build Status

Introduction

This repository is really simple and small I tried to put only basic and most frequently ML algorithms in it, I'm going to explain all the algorithms implemented in this repository, how you can use them and even the math calculation behind them for those who are interesting.

Reading Data And Picturing It

One of the most basic capabilities you'll need for sure is to read data from a dataset and plot it if possible, most of the times the dataset is a CSVDataset here is a sample of how to use this library

package main

import (
	"fmt"
	"strconv"

	"github.com/elahe-dastan/newborn/data"
)

func main() {
	headers, content := data.ReadCSVData("./data/dataset_test.csv")
	fmt.Println(headers)

	x := make([]float64, len(content[headers[0]]))
	y := make([]float64, len(content[headers[1]]))

	for i := 0; i < len(content[headers[0]]); i++ {
		x[i], _ = strconv.ParseFloat(content[headers[0]][i], 64)
		y[i], _ = strconv.ParseFloat(content[headers[1]][i], 64)
	}

	data.ScatterPlot(x, y, headers[0], headers[1], "example")
}
[x y]

Regression

One of the basic things everybody has to learn to study ML is linear regression, logistic regression and nonlinear regression, regression is used in both predicting a value and classification.
Let's talk a little deeper about regression, we want to fit a line or curve to a set of data.I'm going to show the math calculations of what is happening.

check here if you are interested in the math calculations

In this repository I haven't implemented linear regression separately because linear regression is polynomial regression with degree equal to 1 and lambda equal to 0

K Nearest Neighbour

This algorithm is used for classification, to choose a label for a new data the algorithm finds the k nearest data to it and finds the most repeated label among them, different methods can be used to calculate the distance between the new data and the old ones in this repository I use one of the easiest approaches called Euclidean Distance.

package main

import (
	"fmt"
	"github.com/elahe-dastan/newborn/data"
	"github.com/elahe-dastan/newborn/knn"
	"strconv"
)

func main() {
	headers, content := data.ReadCSVData("./knn/dataset_test.csv")
	currentData := make([][]float64, len(content[headers[0]]))
	for i := range currentData {
		f := make([]float64, len(headers)-1)
		for j := range f {
			f[j], _ = strconv.ParseFloat(content[headers[j]][i], 64)
		}
		currentData[i] = f
	}

	labels := make([]int, len(content[headers[0]]))
	for i := range labels {
		labels[i], _ = strconv.Atoi(content[headers[len(headers)-1]][i])
	}

	newData := []float64{57.0,1.0,4.0,140.0,192.0,0.0,0.0,148.0,0.0,0.4,2.0,0.0,6.0}
    
        // k = 3
	label := knn.KNN(currentData, labels, newData, 3)
	fmt.Println(label)
}
0

newborn's People

Contributors

elahe-dastan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

stevegt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.