项目作者: siadat

项目描述 :
Gradient Boosting Regressor in Go
高级语言: Go
项目地址: git://github.com/siadat/gradboostreg.git
创建时间: 2018-01-29T20:49:15Z
项目社区:https://github.com/siadat/gradboostreg

开源协议:

下载


GradBoostReg

GoDoc
Build Status

Gradient Boosting Regressor in Go

Install

  1. go get -u github.com/siadat/gradboostreg

Example

Problem

Let’s say we have one predictor (also known as a feature) named X and we want to find the function
that predicts the value Y. Given the following 6 training samples:

  1. X: 0 1 2 3 4 5
  2. Y: 10 10 20 20 5 5

Predict Y for the following X values:

  1. X: 0 0.5 2.5 2 4.5

Solution

  1. trainSamples := []sample.Sample{
  2. sample.DefaultSample{Xs: map[string]float64{"X": 0}, Y: 10},
  3. sample.DefaultSample{Xs: map[string]float64{"X": 1}, Y: 10},
  4. sample.DefaultSample{Xs: map[string]float64{"X": 2}, Y: 20},
  5. sample.DefaultSample{Xs: map[string]float64{"X": 3}, Y: 20},
  6. sample.DefaultSample{Xs: map[string]float64{"X": 4}, Y: 5},
  7. sample.DefaultSample{Xs: map[string]float64{"X": 5}, Y: 5},
  8. }
  9. predictFunc := gradboostreg.Learn(trainSamples, 0.5, 10)
  10. testSamples := []sample.Sample{
  11. sample.DefaultSample{Xs: map[string]float64{"X": 0.0}},
  12. sample.DefaultSample{Xs: map[string]float64{"X": 0.5}},
  13. sample.DefaultSample{Xs: map[string]float64{"X": 2.5}},
  14. sample.DefaultSample{Xs: map[string]float64{"X": 2.0}},
  15. sample.DefaultSample{Xs: map[string]float64{"X": 4.5}},
  16. }
  17. for i := range testSamples {
  18. predictedY := predictFunc(testSamples[i])
  19. fmt.Printf("X=%.1f predictedY=%.1f\n", testSamples[i].GetX("X"), predictedY)
  20. }
  21. // Output:
  22. // X=0.0 predictedY=10.0
  23. // X=0.5 predictedY=10.0
  24. // X=2.5 predictedY=20.0
  25. // X=2.0 predictedY=20.0
  26. // X=4.5 predictedY=5.0