// TestCSV func main() { var reader io.Reader var err error if reader, err = os.Open("pima-indians-diabetes.csv"); err != nil { log.Fatalf("%v", err) } handler := &Handler{} err = db.Import(reader, handler) targetBool := make([]bool, handler.target.Len()) targetNumeric := make([]float64, handler.target.Len()) for i := 0; i < handler.target.Len(); i++ { targetBool[i] = handler.target.NumericValue(i) == 1.0 targetNumeric[i] = handler.target.NumericValue(i) } if err != nil { log.Fatal("Import returned error") } fmt.Printf("target: %v\n", handler.target) rf := db.NewRandomForestRegressor(100) oobScores := rf.Fit(handler.features, handler.target) auc := db.ROCArea(oobScores, targetBool) mse := db.MSE(oobScores, targetNumeric) variance := stats.Variance(targetNumeric) fmt.Printf("ROCArea: %v MSE: %v Var: %v\n", auc, mse, variance) }
func TestVariance(test *testing.T) { x := []float64{1.0, 2.0, 0.0, 5.0} variance := stats.Variance(x) expected := 3.5 if variance != expected { test.Errorf("Expected variance of %g; got %g\n", expected, variance) } }