ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::io::csv Namespace Reference

Functions

stats::DataPacket read (std::string const &filename)
 Read a CSV file into a DataPacket.
 
stats::DataPacket read_sorted (std::string const &filename)
 Read a CSV file and sort rows so that response groups are contiguous.
 
void write (stats::DataPacket const &data, std::string const &filename)
 Write a DataPacket to a CSV file (features followed by label, no header).
 

Function Documentation

◆ read()

stats::DataPacket ppforest2::io::csv::read ( std::string const & filename)

Read a CSV file into a DataPacket.

Assumes the last column is the response variable (group label as string) and all preceding columns are features. Categorical feature columns are automatically detected and integer-encoded. String labels are mapped to contiguous integer codes starting at 0.

Parameters
filenamePath to the CSV file.
Returns
A DataPacket containing the feature matrix and response vector.
Exceptions
std::runtime_errorIf the file is empty or has inconsistent columns.

◆ read_sorted()

stats::DataPacket ppforest2::io::csv::read_sorted ( std::string const & filename)

Read a CSV file and sort rows so that response groups are contiguous.

Calls read() and then sorts the data if the response vector is not already contiguous, as required by the training routines.

Parameters
filenamePath to the CSV file.
Returns
A DataPacket with contiguous group ordering.

◆ write()

void ppforest2::io::csv::write ( stats::DataPacket const & data,
std::string const & filename )

Write a DataPacket to a CSV file (features followed by label, no header).

Parameters
dataThe DataPacket to write.
filenameOutput file path.