func RegAlgorithmRunOnDataSet(regressor algo.Regressor, train_dataset, test_dataset *core.RealDataSet, pred_path string, params map[string]string) (float64, []*eval.RealPrediction) { if train_dataset != nil { regressor.Train(train_dataset) } predictions := []*eval.RealPrediction{} var pred_file *os.File if pred_path != "" { pred_file, _ = os.Create(pred_path) } for _, sample := range test_dataset.Samples { prediction := regressor.Predict(sample) if pred_file != nil { pred_file.WriteString(strconv.FormatFloat(prediction, 'g', 5, 64) + "\n") } predictions = append(predictions, &eval.RealPrediction{Value: sample.Value, Prediction: prediction}) } if pred_path != "" { defer pred_file.Close() } rmse := eval.RegRMSE(predictions) return rmse, predictions }
func RegAlgorithmTrain(regressor algo.Regressor, train_path string, params map[string]string) error { global, _ := strconv.ParseInt(params["global"], 10, 64) train_dataset := core.NewRealDataSet() err := train_dataset.Load(train_path, global) if err != nil { return err } regressor.Init(params) regressor.Train(train_dataset) model_path, _ := params["model"] if model_path != "" { regressor.SaveModel(model_path) } return nil }