Skip to content

Instantly share code, notes, and snippets.

@keon
Last active May 26, 2016 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keon/0f7abbd191dbd819a1a5e65caa7954eb to your computer and use it in GitHub Desktop.
Save keon/0f7abbd191dbd819a1a5e65caa7954eb to your computer and use it in GitHub Desktop.
// Load Data and Labels in double types
data::Load(inputFile, data, true);
data::Load(inputLabel, labels, true);
arma::rowvec labels_row = labels.row(0); // extract first row
// Split Data
const auto value = data::TrainTestSplit(data, labels_row, testRatio);
Log::Info << "Train Data Count: " << get<0>(value).n_cols << endl;
Log::Info << "Test Data Count: " << get<1>(value).n_cols << endl;
Log::Info << "Train Label Count: " << get<2>(value).n_cols << endl;
Log::Info << "Test Label Count: " << get<3>(value).n_cols << endl;
// This is what I am trying to do: (of course the code doesn't work because armadillo does not support string type)
// Cast double matrix to string matrix, conv_to reference here -> (http://arma.sourceforge.net/docs.html#conv_to)
Mat<string> training = arma::conv_to<Mat<string>>::from(get<0>(value));
Mat<string> test = arma::conv_to<Mat<string>>::from(get<1>(value));
Mat<string> trainingLabels = arma::conv_to<Mat<string>>::from(get<2>(value));
Mat<string> testLabels = arma::conv_to<Mat<string>>::from(get<3>(value));
data::Save(trainingFile, training, false);
data::Save(testFile, test, false);
data::Save(trainingLabelsFile, trainingLabels, false);
data::Save(testLabelsFile, testLabels, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment