Skip to content

Instantly share code, notes, and snippets.

@zoq

zoq/cat-data.cpp Secret

Created June 8, 2021 15:14
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 zoq/8a0b2e755412a0ca4e3ce9529e001c7c to your computer and use it in GitHub Desktop.
Save zoq/8a0b2e755412a0ca4e3ce9529e001c7c to your computer and use it in GitHub Desktop.
cat-data.cpp
arma::mat dataset; // Load data into this matrix.
mlpack::data::DatasetInfo info; // This will store the mappings.
// Load the dataset.
mlpack::data::Load("test.csv", dataset, info);
size_t catDim;
// Loop over all features, and add 1 to all non-categorical features.
for (size_t i = 0; i < info.Dimensionality(); ++i)
{
// The Type() function returns whether or not the data is numeric or
// categorical.
if (info.Type(i) != mlpack::data::Datatype::categorical)
std::cout << dataset.row(i) << std::endl;
if (info.Type(i) == mlpack::data::Datatype::categorical)
catDim = i;
}
for (size_t i = 0; i < dataset.n_cols; ++i)
std::cout << info.UnmapString(dataset.at(catDim, i), catDim, 0) << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment