load_csv_legacy

Function load_csv_legacy 

Source
pub fn load_csv_legacy<P: AsRef<Path>>(
    path: P,
    has_header: bool,
    target_column: Option<usize>,
) -> Result<Dataset>
Expand description

Load a dataset from a CSV file (legacy API)

Examples found in repository?
examples/csv_loading.rs (lines 6-10)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Load a CSV file with headers and target column
6    let dataset = load_csv_legacy(
7        "scirs2-datasets/data/example.csv",
8        true,    // has header
9        Some(3), // target column index (0-based)
10    )?;
11
12    println!("CSV dataset loaded successfully:");
13    println!("  Samples: {}", dataset.n_samples());
14    println!("  Features: {}", dataset.n_features());
15    println!("  Feature names: {:?}", dataset.featurenames);
16
17    // Access data and target
18    println!("\nFirst 3 samples:");
19    for i in 0..3 {
20        let features = dataset.data.row(i);
21        let target = dataset.target.as_ref().map(|t| t[i]);
22        println!("  Sample {i}: Features = {features:?}, Target = {target:?}");
23    }
24
25    Ok(())
26}