https://github.com/elahe-dastan/newborn
A library for ML algorithms
https://github.com/elahe-dastan/newborn
algorithms dataset go gola knn knn-classification linear-regression logistic-regression machine-learning math-calculation ml polynomial-regression regression
Last synced: about 2 months ago
JSON representation
A library for ML algorithms
- Host: GitHub
- URL: https://github.com/elahe-dastan/newborn
- Owner: elahe-dastan
- Created: 2020-08-26T08:26:47.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T20:07:23.000Z (almost 5 years ago)
- Last Synced: 2025-03-25T10:03:31.494Z (2 months ago)
- Topics: algorithms, dataset, go, gola, knn, knn-classification, linear-regression, logistic-regression, machine-learning, math-calculation, ml, polynomial-regression, regression
- Language: Go
- Homepage:
- Size: 387 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
[](https://cloud.drone.io/elahe-dastan/newborn)
# 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
```go
package mainimport (
"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](https://elahe-dastan.github.io/newborn/)
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.
```go
package mainimport (
"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
```