Spaces:
Build error
Build error
Commit ·
6b47160
1
Parent(s): c4864dc
working through Train() function
Browse filesFiles changed (2)
- nn/main.go+38
- nn/split.go+9-7
1 unmodified line23456789101126 unmodified lines3839404142434445461 unmodified lineimport ("fmt""strings""github.com/go-gota/gota/dataframe""github.com/gofiber/fiber/v2")type NN struct {26 unmodified linesfunc (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}1 unmodified line234567891011121326 unmodified lines4041424344454647484950515253545556575859606162636465666768697071727374757677787980818283841 unmodified lineimport ("fmt""math/rand""strings""github.com/go-gota/gota/dataframe""github.com/gofiber/fiber/v2""gonum.org/v1/gonum/mat")type NN struct {26 unmodified linesfunc (nn *NN) Train() {// train test split the dataXTrain, XTest, YTrain, YTest := nn.trainTestSplit()weights, biases := nn.InitWnB()// iterate n times where n = nn.Epochs// use backprop algorithm on each iteration// to fit the model to the data}func (nn *NN) InitWnB() {// randomly initialize weights and biases to startinputSize := len(nn.Features)hiddenSize := nn.HiddenSizeoutputSize := 1 // only predicting one thing for now// Initialize weights and biases for the input layer to hidden layerweightsInputHidden := mat.NewDense(inputSize, hiddenSize, nil)weightsInputHidden.Apply(func(_, _ int, v float64) float64 {// Randomly initialize weights with values between -1 and 1return rand.Float64()*2 - 1}, weightsInputHidden)biasesHidden := mat.NewVecDense(hiddenSize, nil)biasesHidden.Apply(func(_, _ int, v float64) float64 {// Randomly initialize biasesreturn rand.Float64()}, biasesHidden)// Initialize weights and biases for the hidden layer to output layerweightsHiddenOutput := mat.NewDense(hiddenSize, outputSize, nil)weightsHiddenOutput.Apply(func(_, _ int, v float64) float64 {// Randomly initialize weights with values between -1 and 1return rand.Float64()*2 - 1}, weightsHiddenOutput)biasesOutput := mat.NewVecDense(outputSize, nil)biasesOutput.Apply(func(_, _ int, v float64) float64 {// Randomly initialize biasesreturn rand.Float64()}, biasesOutput)}
2 unmodified lines34567891011121317 unmodified lines31323334353637382 unmodified linesimport ("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.17 unmodified lines// 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)}2 unmodified lines34567891011121317 unmodified lines313233343536373839402 unmodified linesimport ("math""math/rand""github.com/go-gota/gota/dataframe")func (nn *NN) trainTestSplit() (dataframe.DataFrame, dataframe.DataFrame, dataframe.DataFrame, dataframe.DataFrame) {// now we split the data into training// and testing based on user specified// nn.TestSize.17 unmodified lines// Create the train DataFrame using the trainIndicestrain := nn.Df.Subset(trainIndices)XTrain = train.Select(nn.Features)YTrain = train.Select(nn.Target)XTest = test.Select(nn.Features)YTest = test.Select(nn.Target)return XTrain, XTest, YTrain, YTest}
nn/main.go+38
nn/split.go+9-7