本文整理汇总了C++中LinearRegression::Lambda方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearRegression::Lambda方法的具体用法?C++ LinearRegression::Lambda怎么用?C++ LinearRegression::Lambda使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearRegression
的用法示例。
在下文中一共展示了LinearRegression::Lambda方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Handle parameters.
CLI::ParseCommandLine(argc, argv);
const string inputModelFile = CLI::GetParam<string>("input_model_file");
const string outputModelFile = CLI::GetParam<string>("output_model_file");
const string outputPredictionsFile =
CLI::GetParam<string>("output_predictions");
const string trainingResponsesFile =
CLI::GetParam<string>("training_responses");
const string testFile = CLI::GetParam<string>("test_file");
const string trainFile = CLI::GetParam<string>("training_file");
const double lambda = CLI::GetParam<double>("lambda");
mat regressors;
mat responses;
LinearRegression lr;
lr.Lambda() = lambda;
bool computeModel = false;
// We want to determine if an input file XOR model file were given.
if (!CLI::HasParam("training_file"))
{
if (!CLI::HasParam("input_model_file"))
Log::Fatal << "You must specify either --input_file or --model_file."
<< endl;
else // The model file was specified, no problems.
computeModel = false;
}
// The user specified an input file but no model file, no problems.
else if (!CLI::HasParam("input_model_file"))
computeModel = true;
// The user specified both an input file and model file.
// This is ambiguous -- which model should we use? A generated one or given
// one? Report error and exit.
else
{
Log::Fatal << "You must specify either --input_file or --model_file, not "
<< "both." << endl;
}
if (CLI::HasParam("test_file") && !CLI::HasParam("output_predictions"))
Log::Warn << "--test_file (-t) specified, but --output_predictions "
<< "(-o) is not; no results will be saved." << endl;
// If they specified a model file, we also need a test file or we
// have nothing to do.
if (!computeModel && !CLI::HasParam("test_file"))
{
Log::Fatal << "When specifying --model_file, you must also specify "
<< "--test_file." << endl;
}
if (!computeModel && CLI::HasParam("lambda"))
{
Log::Warn << "--lambda ignored because no model is being trained." << endl;
}
// An input file was given and we need to generate the model.
if (computeModel)
{
Timer::Start("load_regressors");
data::Load(trainFile, regressors, true);
Timer::Stop("load_regressors");
// Are the responses in a separate file?
if (CLI::HasParam("training_responses"))
{
// The initial predictors for y, Nx1.
responses = trans(regressors.row(regressors.n_rows - 1));
regressors.shed_row(regressors.n_rows - 1);
}
else
{
// The initial predictors for y, Nx1.
Timer::Start("load_responses");
data::Load(trainingResponsesFile, responses, true);
Timer::Stop("load_responses");
if (responses.n_rows == 1)
responses = trans(responses); // Probably loaded backwards.
if (responses.n_cols > 1)
Log::Fatal << "The responses must have one column.\n";
if (responses.n_rows != regressors.n_cols)
Log::Fatal << "The responses must have the same number of rows as the "
"training file.\n";
}
Timer::Start("regression");
lr = LinearRegression(regressors, responses.unsafe_col(0));
Timer::Stop("regression");
// Save the parameters.
if (CLI::HasParam("output_model_file"))
data::Save(outputModelFile, "linearRegressionModel", lr);
//.........这里部分代码省略.........