-
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit puts datasets into a separate crate called `linfa-datasets`
- Loading branch information
Showing
20 changed files
with
164 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ members = [ | |
"linfa-svm", | ||
"linfa-hierarchical", | ||
"linfa-ica", | ||
"datasets", | ||
] | ||
|
||
[profile.release] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "linfa-datasets" | ||
version = "0.2.1" | ||
authors = ["Lorenz Schmidt <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
linfa = { version = "0.2.1", path = ".." } | ||
ndarray = { version = "0.13", default-features = false } | ||
ndarray-csv = "0.4" | ||
csv = "1.1" | ||
flate2 = "1.0" | ||
|
||
[features] | ||
default = [] | ||
diabetes = [] | ||
iris = [] | ||
winequality = [] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use csv::ReaderBuilder; | ||
use flate2::read::GzDecoder; | ||
use linfa::Dataset; | ||
use ndarray::prelude::*; | ||
use ndarray_csv::Array2Reader; | ||
|
||
#[cfg(any(feature = "iris", feature = "diabetes", feature = "winequality"))] | ||
fn array_from_buf(buf: &[u8]) -> Array2<f64> { | ||
// unzip file | ||
let file = GzDecoder::new(buf); | ||
// create a CSV reader with headers and `;` as delimiter | ||
let mut reader = ReaderBuilder::new() | ||
.has_headers(true) | ||
.delimiter(b',') | ||
.from_reader(file); | ||
|
||
// extract ndarray | ||
reader.deserialize_array2_dynamic().unwrap() | ||
} | ||
|
||
#[cfg(feature = "iris")] | ||
/// Read in the iris-flower dataset from dataset path | ||
/// The `.csv` data is two dimensional: Axis(0) denotes y-axis (rows), Axis(1) denotes x-axis (columns) | ||
pub fn iris() -> Dataset<Array2<f64>, Vec<usize>> { | ||
let data = include_bytes!("../data/iris.csv.gz"); | ||
let array = array_from_buf(&data[..]); | ||
|
||
let (data, targets) = ( | ||
array.slice(s![.., 0..4]).to_owned(), | ||
array.column(4).to_owned(), | ||
); | ||
|
||
Dataset::new(data, targets).map_targets(|x| *x as usize) | ||
} | ||
|
||
#[cfg(feature = "diabetes")] | ||
pub fn diabetes() -> Dataset<Array2<f64>, Array1<f64>> { | ||
let data = include_bytes!("../data/diabetes_data.csv.gz"); | ||
let data = array_from_buf(&data[..]); | ||
|
||
let targets = include_bytes!("../data/diabetes_target.csv.gz"); | ||
let targets = array_from_buf(&targets[..]).column(0).to_owned(); | ||
|
||
Dataset::new(data, targets) | ||
} | ||
|
||
#[cfg(feature = "winequality")] | ||
pub fn winequality() -> Dataset<Array2<f64>, Vec<usize>> { | ||
let data = include_bytes!("../data/winequality-red.csv.gz"); | ||
let array = array_from_buf(&data[..]); | ||
|
||
let (data, targets) = ( | ||
array.slice(s![.., 0..11]).to_owned(), | ||
array.column(11).to_owned(), | ||
); | ||
|
||
Dataset::new(data, targets).map_targets(|x| *x as usize) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.