本文整理汇总了C++中ME_Model::add_training_sample方法的典型用法代码示例。如果您正苦于以下问题:C++ ME_Model::add_training_sample方法的具体用法?C++ ME_Model::add_training_sample怎么用?C++ ME_Model::add_training_sample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ME_Model
的用法示例。
在下文中一共展示了ME_Model::add_training_sample方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
void train(ME_Model & model, const string & filename)
{
ifstream ifile(filename.c_str());
if (!ifile) {
cerr << "error: cannot open " << filename << endl;
exit(1);
}
string line;
int n = 0;
while (getline(ifile, line)) {
vector<Token> vs = read_line(line);
for (int j = 0; j < (int)vs.size(); j++) {
ME_Sample mes = sample(vs, j);
model.add_training_sample(mes);
}
if (n++ > 10000) break;
}
model.use_l1_regularizer(1.0);
// model.use_l2_regularizer(1.0);
// model.use_SGD();
model.set_heldout(100);
model.train();
model.save_to_file("model");
}
示例2: add_samples
void add_samples(int nrows, int ncols, vector<string> samples, vector<double> ia, vector<string> ja, vector<double> ra) {
new_model();
for (int i=0; i < nrows; i++) { // for each document
//Rprintf("Document %d\n",i); // debug output
ME_Sample newSample(samples[i]); // create new sample for code
for (int j=ia[i]-1; j < ia[i+1]-1; j++) { // for each feature
//Rprintf("Feature %s\n",features[j].c_str());
newSample.add_feature(ja[j],ra[j]);
}
model.add_training_sample(newSample);
}
}
示例3: train
void train(ME_Model & model, const string & input, const string & model_path)
{
ifstream ifile(input.c_str());
if (!ifile)
{
cerr << "error: cannot open " << input << endl;
exit(1);
}
string line;
while (getline(ifile, line))
{
vector<string> vs = split(line);
ME_Sample mes(vs, true);
model.add_training_sample(mes);
}
model.train();
model.save(model_path);
}