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 line2345678910111 unmodified linego 1.19require (github.com/andybalholm/brotli v1.0.5 // indirectgithub.com/go-gota/gota v0.12.0 // indirectgithub.com/gofiber/fiber/v2 v2.49.2 // indirectgithub.com/google/uuid v1.3.1 // indirectgithub.com/klauspost/compress v1.16.7 // indirectgithub.com/mattn/go-colorable v0.1.13 // indirect1 unmodified line2345678910111213141 unmodified linego 1.19require (github.com/go-gota/gota v0.12.0github.com/gofiber/fiber/v2 v2.49.2)require (github.com/andybalholm/brotli v1.0.5 // indirectgithub.com/google/uuid v1.3.1 // indirectgithub.com/klauspost/compress v1.16.7 // indirectgithub.com/mattn/go-colorable v0.1.13 // indirect
52 unmodified lines5354555657588 unmodified lines6768697071727321 unmodified lines959697989910052 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/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/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=52 unmodified lines535455565758598 unmodified lines68697071727321 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/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 lines161718192021222 unmodified lines25262728293015 unmodified linesHiddenSize int `json:"hidden_size"`LearningRate float64 `json:"learning_rate"`ActivationFunc string `json:"activation"`Df dataframe.DataFrame}func NewNN(c *fiber.Ctx) (*NN, error) {2 unmodified linesif err != nil {return nil, fmt.Errorf("invalid JSON data: %v", err)}newNN.Df = dataframe.ReadCSV(strings.NewReader(newNN.CSVData))return newNN, nil}15 unmodified lines161718192021222324252627282 unmodified lines3132333435363738394041424344454615 unmodified linesHiddenSize int `json:"hidden_size"`LearningRate float64 `json:"learning_rate"`ActivationFunc string `json:"activation"`TestSize float64 `json:"test_size"`Df *dataframe.DataFrameXTrain dataframe.DataFrameYTrain dataframe.DataFrameXTest dataframe.DataFrameYTest dataframe.DataFrame}func NewNN(c *fiber.Ctx) (*NN, error) {2 unmodified linesif err != nil {return nil, fmt.Errorf("invalid JSON data: %v", err)}df := dataframe.ReadCSV(strings.NewReader(newNN.CSVData))newNN.Df = &dfreturn 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}
12345package nn// implement train test split functionfunc trainTestSplit() {}1234567891011121314151617181920212223242526272829303132333435363738package nnimport ("math""math/rand")// implement train test split functionfunc (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 rowsrandStrt := rand.Intn(int(math.Floor(float64(nRows) * nn.TestSize)))test := nn.Df.Subset([]int{randStrt, randStrt + testRows})// use what is left for trainingallIndices := make([]int, nRows)for i := range allIndices {allIndices[i] = i}// Remove the test indices using slice append and variadic parametertrainIndices := append(allIndices[:randStrt], allIndices[randStrt+testRows:]...)// Create the train DataFrame using the trainIndicestrain := 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