Exemple #1
0
// 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)
}
Exemple #2
0
// TestCSV
func TestCSV(test *testing.T) {
	reader := strings.NewReader(data)
	err := csv.Import(reader, &Handler{test, nil, 0})

	if err != nil {
		test.Error("Import returned error")
	}

	if !finalizeCalled {
		test.Error("Finalize was never called")
	}

	if abortCalled {
		test.Error("Abort should not have been called")
	}
}
func TestCSVHandler(t *testing.T) {
	reader := strings.NewReader(`apple,baker,Charlie
1,"x","foo"
4,"5","baz"`)
	handler := db.NewCSVHandler(featureFactory)

	if db.Import(reader, handler) != nil {
		t.Error("Import() returned an error")
	}

	df := handler.DataFrame()
	for i := 0; i < 2; i++ {
		for j := 0; j < 3; j++ {
			//			fmt.Printf("%v ", df.Get(i, j))
			df.Get(i, j)
		}
	}
}