Spaces:
Build error
Build error
Commit
Β·
dfd3544
1
Parent(s):
b5b4a38
splitting up code into seperate modules
Browse files- alg/alg.go +5 -0
- {test β example}/iris.csv +0 -0
- {test β example}/main.go +0 -0
- nn/main.go +11 -0
- nn/split.go +5 -0
- nn/subset.go +6 -0
- request/request.go +31 -0
- server.go +10 -15
alg/alg.go
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package alg
|
| 2 |
+
|
| 3 |
+
type Alg interface {
|
| 4 |
+
Train()
|
| 5 |
+
}
|
{test β example}/iris.csv
RENAMED
|
File without changes
|
{test β example}/main.go
RENAMED
|
File without changes
|
nn/main.go
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package nn
|
| 2 |
+
|
| 3 |
+
import "github.com/Jensen-holm/ml-from-scratch/alg"
|
| 4 |
+
|
| 5 |
+
type NN struct {
|
| 6 |
+
alg.Alg
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
func New(rp *RequestPayload) {
|
| 10 |
+
|
| 11 |
+
}
|
nn/split.go
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package nn
|
| 2 |
+
|
| 3 |
+
// implement train test split function
|
| 4 |
+
|
| 5 |
+
func trainTestSplit() {}
|
nn/subset.go
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package nn
|
| 2 |
+
|
| 3 |
+
// subset the data frame into just the
|
| 4 |
+
// features and target that the user specify
|
| 5 |
+
|
| 6 |
+
func subset() {}
|
request/request.go
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package request
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
|
| 6 |
+
"github.com/go-gota/gota/dataframe"
|
| 7 |
+
"github.com/gofiber/fiber/v2"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
type Payload struct {
|
| 11 |
+
CSVData string `json:"csv_data"`
|
| 12 |
+
Features []string `json:"features"`
|
| 13 |
+
Target string `json:"target"`
|
| 14 |
+
Epochs int `json:"epochs"`
|
| 15 |
+
HiddenSize int `json:"hidden_size"`
|
| 16 |
+
LearningRate float64 `json:"learning_rate"`
|
| 17 |
+
ActivationFunc string `json:"activation_func"`
|
| 18 |
+
|
| 19 |
+
Df dataframe.DataFrame
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
func (p *Payload) SetDf(df dataframe.DataFrame) {
|
| 23 |
+
p.Df = df
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
func NewPayload(dest *Payload, c *fiber.Ctx) error {
|
| 27 |
+
if err := c.BodyParser(dest); err != nil {
|
| 28 |
+
return fmt.Errorf("invalid JSON data")
|
| 29 |
+
}
|
| 30 |
+
return nil
|
| 31 |
+
}
|
server.go
CHANGED
|
@@ -2,35 +2,30 @@ package main
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"fmt"
|
|
|
|
| 5 |
|
|
|
|
|
|
|
| 6 |
"github.com/gofiber/fiber/v2"
|
| 7 |
)
|
| 8 |
|
| 9 |
-
type RequestPayload struct {
|
| 10 |
-
CSVData string `json:"csv_data"`
|
| 11 |
-
Features []string `json:"features"`
|
| 12 |
-
Target string `json:"target"`
|
| 13 |
-
Epochs int `json:"epochs"`
|
| 14 |
-
HiddenSize int `json:"hidden_size"`
|
| 15 |
-
LearningRate float64 `json:"learning_rate"`
|
| 16 |
-
ActivationFunc string `json:"activation_func"`
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
func main() {
|
| 20 |
app := fiber.New()
|
| 21 |
|
| 22 |
app.Post("/", func(c *fiber.Ctx) error {
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
// parse json request data into requestData struct
|
| 27 |
-
if err := c.BodyParser(requestData); err != nil {
|
| 28 |
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
| 29 |
"error": "Invalid JSON data",
|
| 30 |
})
|
| 31 |
}
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
return c.SendString("No error")
|
| 36 |
})
|
|
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"fmt"
|
| 5 |
+
"strings"
|
| 6 |
|
| 7 |
+
"github.com/Jensen-holm/ml-from-scratch/request"
|
| 8 |
+
"github.com/go-gota/gota/dataframe"
|
| 9 |
"github.com/gofiber/fiber/v2"
|
| 10 |
)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
func main() {
|
| 13 |
app := fiber.New()
|
| 14 |
|
| 15 |
app.Post("/", func(c *fiber.Ctx) error {
|
| 16 |
+
r := new(request.Payload)
|
| 17 |
|
| 18 |
+
err := request.NewPayload(r, c)
|
| 19 |
+
if err != nil {
|
|
|
|
|
|
|
| 20 |
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
| 21 |
"error": "Invalid JSON data",
|
| 22 |
})
|
| 23 |
}
|
| 24 |
|
| 25 |
+
df := dataframe.ReadCSV(strings.NewReader(r.CSVData))
|
| 26 |
+
r.SetDf(df)
|
| 27 |
+
|
| 28 |
+
fmt.Println(r.Df)
|
| 29 |
|
| 30 |
return c.SendString("No error")
|
| 31 |
})
|