Hello!
I am really new to this topic and golang in general, so sorry if this is too obvious
But i ran into the problem
I am trying to run the simple GP with the help of YouTube and ChatGPT, but my below code fails
package main
import (
"fmt"
"github.com/pa-m/sklearn/gaussian_process"
"github.com/pa-m/sklearn/gaussian_process/kernels"
"gonum.org/v1/gonum/mat"
"log"
"math/rand"
)
func main() {
// Generate some sample data
X := mat.NewDense(10, 1, nil)
y := make([]float64, 10)
for i := 0; i < 10; i++ {
X.Set(i, 0, float64(i))
y[i] = float64(i*i) + rand.NormFloat64() // Adding some noise
}
yMat := mat.NewDense(len(y), 1, y)
// Print the training data for debugging
fmt.Println("Training data X:")
matPrint(X)
fmt.Println("Training data y:")
fmt.Println(yMat)
// Define the kernel: ConstantKernel * RBF
constantKernel := &kernels.ConstantKernel{ConstantValue: 1.0, ConstantValueBounds: [2]float64{1e-5, 1e5}}
rbfKernel := &kernels.RBF{LengthScale: []float64{1.5}, LengthScaleBounds: [][2]float64{{1e-5, 1e5}}}
productKernel := &kernels.Product{
KernelOperator: kernels.KernelOperator{
K1: constantKernel,
K2: rbfKernel,
},
}
// Create the Gaussian Process Regressor
gp := gaussianprocess.NewRegressor(productKernel)
// Print Alpha for debugging
fmt.Println("Alpha:", gp.Alpha)
// Fit the model with X and yVec
err := gp.Fit(X, yMat)
if err != nil {
log.Fatalf("Error fitting model: %v", err)
}
// Print fitted model info
fmt.Println("Model fitted successfully.")
fmt.Println("Xtrain:", gp.Xtrain)
fmt.Println("Ytrain:", gp.Ytrain)
// Predict new values
X_test := mat.NewDense(5, 1, []float64{0, 2, 4, 6, 8})
y_pred := gp.Predict(X_test, nil)
// Print the test data and prediction results for debugging
fmt.Println("Test data X_test:")
matPrint(X_test)
fmt.Println("Predicted values:")
matPrint(y_pred)
}
// Helper function to print matrix
func matPrint(X mat.Matrix) {
fr, fc := X.Dims()
for r := 0; r < fr; r++ {
for c := 0; c < fc; c++ {
fmt.Printf("%f ", X.At(r, c))
}
fmt.Println()
}
}
Hello! I am really new to this topic and golang in general, so sorry if this is too obvious
But i ran into the problem
I am trying to run the simple GP with the help of YouTube and ChatGPT, but my below code fails
the output i am getting is below
I cannot understand what that error about fitting model means
I analyzed the fit method's code and cannot see where it can go wrong, or I am just blind
Would really appreciate the help! Thanks for the hard work