Hi all!

I just wrote a simple gradient regressor in Go. Gradient boosting is a 
statistical learning method. Given a number of samples it returns a 
function that fits the those data and can be used to predict previously 
unseen data. The usage is simple, here's an example:

    trainSamples := []sample.Sample{
    sample.DefaultSample{Xs: map[string]float64{"x": 0}, Y: 10},
    sample.DefaultSample{Xs: map[string]float64{"x": 1}, Y: 10},
    sample.DefaultSample{Xs: map[string]float64{"x": 2}, Y: 20},
    sample.DefaultSample{Xs: map[string]float64{"x": 3}, Y: 20},
    sample.DefaultSample{Xs: map[string]float64{"x": 4}, Y: 5},
    sample.DefaultSample{Xs: map[string]float64{"x": 5}, Y: 5},
    }
    predictFunc := gradboostreg.Learn(trainSamples, 0.5, 10)
    
    testSamples := []sample.Sample{
    sample.DefaultSample{Xs: map[string]float64{"x": 0.0}, Y: 10},
    sample.DefaultSample{Xs: map[string]float64{"x": 0.5}, Y: 10},
    sample.DefaultSample{Xs: map[string]float64{"x": 2.5}, Y: 20},
    sample.DefaultSample{Xs: map[string]float64{"x": 2.0}, Y: 20},
    sample.DefaultSample{Xs: map[string]float64{"x": 4.5}, Y: 5},
    }
    
    for i := range testSamples {
    predicted, actual := predictFunc(testSamples[i]), testSamples[i].GetY()
    fmt.Printf("predicted=%.1f actual=%.1f\n", predicted, actual)
    }
    
    // Output:
    // predicted=10.0 actual=10.0
    // predicted=10.0 actual=10.0
    // predicted=20.0 actual=20.0
    // predicted=20.0 actual=20.0
    // predicted=5.0 actual=5.0

Here's the source: https://github.com/siadat/gradboostreg

Let me know what you think! :)
Thanks,
Sina

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to