Spaces:
Build error
Build error
Commit ·
554811e
1
Parent(s): 27c0b63
added trainTestSplit() function
Browse filesFiles changed (8)
- go.mod+5-2
- go.sum+2-1
- nn/.main.go.swpAdded
- nn/.split.go.swpAdded
- nn/main.go+18-2
- nn/split.go+34-1
- wrangle/.trainTestSplit.go.swpAdded
- wrangle/trainTestSplit.goAdded+10
1 unmodified line234567891011781213141 unmodified line
go 1.19
require ( github.com/go-gota/gota v0.12.0 github.com/gofiber/fiber/v2 v2.49.2)
require ( github.com/andybalholm/brotli v1.0.5 // indirect github.com/go-gota/gota v0.12.0 // indirect github.com/gofiber/fiber/v2 v2.49.2 // indirect github.com/google/uuid v1.3.1 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect52 unmodified lines535455565758598 unmodified lines6869707071727321 unmodified lines959697989910010152 unmodified linesgolang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=8 unmodified linesgolang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 h1:0PC75Fz/kyMGhL0e1QnypqK2kQMqKt9csD1GnMJR+Zk=golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=21 unmodified linesgonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=gonum.org/v1/gonum v0.9.1 h1:HCWmqqNoELL0RAQeKBXWtkp04mGk8koafcB4He6+uhc=gonum.org/v1/gonum v0.9.1/go.mod h1:TZumC3NeyVQskjXqmyWt4S3bINhy7B4eYwW69EbyX+0=gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc=gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=gonum.org/v1/plot v0.9.0/go.mod h1:3Pcqqmp6RHvJI72kgb8fThyUnav364FOsdDo2aGW5lY=15 unmodified lines16171819201921222324252627282 unmodified lines313233283435363738394041424344454615 unmodified lines HiddenSize int `json:"hidden_size"` LearningRate float64 `json:"learning_rate"` ActivationFunc string `json:"activation"` TestSize float64 `json:"test_size"`
Df dataframe.DataFrame Df *dataframe.DataFrame XTrain dataframe.DataFrame YTrain dataframe.DataFrame XTest dataframe.DataFrame YTest dataframe.DataFrame}
func NewNN(c *fiber.Ctx) (*NN, error) {2 unmodified lines if err != nil { return nil, fmt.Errorf("invalid JSON data: %v", err) } newNN.Df = dataframe.ReadCSV(strings.NewReader(newNN.CSVData)) df := dataframe.ReadCSV(strings.NewReader(newNN.CSVData)) newNN.Df = &df return newNN, nil}
func (nn *NN) Train() { // train test split the data
// iterate n times where n = nn.Epochs // use backprop algorithm on each iteration // to fit the model to the data
}12345678951011121314151617181920212223242526272829303132333435363738package nn
import ( "math" "math/rand")
// implement train test split function
func trainTestSplit() {}func (nn *NN) trainTestSplit() { // now we split the data into training // and testing based on user specified // nn.TestSize. nRows := nn.Df.Nrow() testRows := int(math.Floor(float64(nRows) * nn.TestSize))
// subset the testing data // randomly select trainRows number of rows randStrt := rand.Intn(int(math.Floor(float64(nRows) * nn.TestSize))) test := nn.Df.Subset([]int{randStrt, randStrt + testRows})
// use what is left for training allIndices := make([]int, nRows) for i := range allIndices { allIndices[i] = i }
// Remove the test indices using slice append and variadic parameter trainIndices := append(allIndices[:randStrt], allIndices[randStrt+testRows:]...)
// Create the train DataFrame using the trainIndices train := nn.Df.Subset(trainIndices)
nn.XTrain = train.Select(nn.Features) nn.YTrain = train.Select(nn.Target) nn.XTest = test.Select(nn.Features) nn.YTest = test.Select(nn.Target)}12345678910package wrangle
import ( "github.com/go-gota/gota/dataframe")
func TrainTestSplit(df *dataframe.DataFrame, test float64) *dataframe.DataFrame {
return}go.mod+5-2
go.sum+2-1
nn/.main.go.swpAdded
nn/.split.go.swpAdded
nn/main.go+18-2
nn/split.go+34-1
wrangle/.trainTestSplit.go.swpAdded
wrangle/trainTestSplit.goAdded+10