當前位置: 首頁>>代碼示例>>Golang>>正文


Golang algo.Regressor類代碼示例

本文整理匯總了Golang中github.com/xlvector/hector/algo.Regressor的典型用法代碼示例。如果您正苦於以下問題:Golang Regressor類的具體用法?Golang Regressor怎麽用?Golang Regressor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Regressor類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RegAlgorithmRunOnDataSet

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
}
開發者ID:irwenqiang,項目名稱:hector,代碼行數:25,代碼來源:algo_runner.go

示例2: RegAlgorithmRun

/* Regression */
func RegAlgorithmRun(regressor algo.Regressor, train_path string, test_path string, pred_path string, params map[string]string) (float64, []*eval.RealPrediction, error) {
	global, _ := strconv.ParseInt(params["global"], 10, 64)
	train_dataset := core.NewRealDataSet()

	err := train_dataset.Load(train_path, global)

	if err != nil {
		return 0.5, nil, err
	}

	test_dataset := core.NewRealDataSet()
	err = test_dataset.Load(test_path, global)
	if err != nil {
		return 0.5, nil, err
	}
	regressor.Init(params)
	rmse, predictions := RegAlgorithmRunOnDataSet(regressor, train_dataset, test_dataset, pred_path, params)

	return rmse, predictions, nil
}
開發者ID:irwenqiang,項目名稱:hector,代碼行數:21,代碼來源:algo_runner.go

示例3: RegAlgorithmTest

func RegAlgorithmTest(regressor algo.Regressor, test_path string, pred_path string, params map[string]string) (float64, []*eval.RealPrediction, error) {
	global, _ := strconv.ParseInt(params["global"], 10, 64)

	model_path, _ := params["model"]
	regressor.Init(params)
	if model_path != "" {
		regressor.LoadModel(model_path)
	} else {
		return 0.0, nil, nil
	}

	test_dataset := core.NewRealDataSet()
	err := test_dataset.Load(test_path, global)
	if err != nil {
		return 0.0, nil, err
	}

	rmse, predictions := RegAlgorithmRunOnDataSet(regressor, nil, test_dataset, pred_path, params)

	return rmse, predictions, nil
}
開發者ID:irwenqiang,項目名稱:hector,代碼行數:21,代碼來源:algo_runner.go

示例4: RegAlgorithmTrain

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
}
開發者ID:irwenqiang,項目名稱:hector,代碼行數:21,代碼來源:algo_runner.go


注:本文中的github.com/xlvector/hector/algo.Regressor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。