pub struct BanknoteAuthentication { /* private fields */ }Expand description
A struct that represents the Banknote Authentication dataset with lazy loading.
The dataset loads only when you call a data accessor method. After the first load, the dataset caches the data for later accesses.
§About Dataset
Researchers extracted the data from images of genuine and forged banknote-like specimens. They digitized the images with an industrial camera normally used for print inspection. This camera produced 400×400 pixel grayscale images at a resolution of about 660 dpi. Researchers then used a Wavelet Transform tool to extract four continuous statistics from each image. These statistics are the variance, skewness, curtosis, and entropy of the transformed image. They cover 1372 specimens.
§Columns
| Name | Type | Description |
|---|---|---|
variance | Numeric | variance of the Wavelet-Transformed image |
skewness | Numeric | skewness of the Wavelet-Transformed image |
curtosis | Numeric | curtosis of the Wavelet-Transformed image |
entropy | Numeric | entropy of the image |
class | Integer | raw class code, 0 or 1 |
curtosis keeps the source’s spelling. UCI names the attribute that way.
The source designates the four statistics as the inputs
(BanknoteAuthentication::FEATURE_NAMES) and class as the label
(BanknoteAuthentication::TARGET).
UCI does not document which class code marks a genuine note and which one
marks a forged note. The loader keeps the code verbatim.
Missing values: none.
See more information at https://archive.ics.uci.edu/dataset/267/banknote+authentication.
§Citation
V. Lohweg. “Banknote Authentication,” UCI Machine Learning Repository, [Online]. Available: https://doi.org/10.24432/C55P57
§Thread Safety
This struct implements Send and Sync automatically, because all fields
implement them. This makes the struct safe to share across threads. The
internal Dataset makes lazy initialization thread-safe.
§Example
use dataset_ml::BanknoteAuthentication;
// the loader creates the directory if it does not exist
let download_dir = "./banknote_authentication";
let mut dataset = BanknoteAuthentication::new(download_dir);
let table = dataset.data().unwrap();
assert_eq!(table.n_samples(), 1372);
assert_eq!(table.n_columns(), 5);
// Ask for the feature matrix when you want it.
let features = table.numeric_matrix(&BanknoteAuthentication::FEATURE_NAMES).unwrap();
assert_eq!(features.shape(), &[1372, 4]);
// Reach one column by name.
let class = table.column(BanknoteAuthentication::TARGET).unwrap().as_integer().unwrap();
assert_eq!(class.len(), 1372);
// `get_data_mut()` edits the table in place. This needs no clone and no
// reload. The change stays cached.
if let Some(table) = dataset.get_data_mut() {
if let Some(column) = table.column_mut("variance") {
if let dataset_ml::ColumnData::Numeric(values) = column.data_mut() {
values[0] = 0.5;
}
}
}
assert!(dataset.get_data().is_some());
// `take_data()` moves the owned table out with no clone. This leaves the
// instance reusable.
let owned = dataset.take_data().unwrap();
assert_eq!(owned.n_samples(), 1372);
// `into_data()` also returns the owned table with no clone, but it consumes
// the instance.
let owned = dataset.into_data().unwrap();
assert_eq!(owned.n_samples(), 1372);Implementations§
Source§impl BanknoteAuthentication
impl BanknoteAuthentication
Sourcepub const FEATURE_NAMES: [&'static str; 4]
pub const FEATURE_NAMES: [&'static str; 4]
The columns the source designates as the model inputs, in source order.
Sourcepub fn new(storage_dir: &str) -> Self
pub fn new(storage_dir: &str) -> Self
Create a new BanknoteAuthentication instance without loading data.
The dataset loads lazily, on your first call to a data accessor method. This is a lightweight operation that only stores the storage directory.
§Parameters
storage_dir- The directory that stores the dataset.
§Returns
Self- aBanknoteAuthenticationinstance ready for lazy loading.
Sourcepub fn data(&self) -> Result<&Table, DatasetError>
pub fn data(&self) -> Result<&Table, DatasetError>
Get a reference to the parsed table.
This method triggers lazy loading on the first call. Later calls return the cached data.
§Returns
&Table- reference to the cached table of 1372 samples and 5 columns.
§Errors
Returns DatasetError if:
- Download fails due to network issues
- File extraction or I/O operations fail
- Data format is invalid (wrong number of columns, unparseable values, or invalid labels)
Sourcepub fn get_data(&self) -> Option<&Table>
pub fn get_data(&self) -> Option<&Table>
Get a reference to the parsed table without triggering loading.
Unlike BanknoteAuthentication::data, this method never runs the
loader. If the data has not loaded yet, it returns None instead of
downloading and parsing it.
§Returns
Some(&Table)- reference to the cached table, if loaded.None- if the dataset has not loaded yet.
Sourcepub fn get_data_mut(&mut self) -> Option<&mut Table>
pub fn get_data_mut(&mut self) -> Option<&mut Table>
Get a mutable reference to the parsed table for in-place editing.
This needs no clone, and it does not remove the data from the cache. The
changes stay in the cache. Later calls to
BanknoteAuthentication::data or BanknoteAuthentication::get_data
see them.
Like BanknoteAuthentication::get_data, this does not trigger
loading.
§Returns
Some(&mut Table)- mutable reference to the cached table, if loaded.None- if the dataset has not loaded yet.
Sourcepub fn into_data(self) -> Result<Table, DatasetError>
pub fn into_data(self) -> Result<Table, DatasetError>
Consume the dataset and return the owned table.
This consumes self. If you want owned data but need to keep using
the instance, use BanknoteAuthentication::take_data instead.
§Returns
Table- the owned table of 1372 samples and 5 columns.
§Errors
Returns DatasetError if loading fails (network, file I/O, or parsing).
Sourcepub fn take_data(&mut self) -> Result<Table, DatasetError>
pub fn take_data(&mut self) -> Result<Table, DatasetError>
Take the owned table out of the dataset. This leaves the instance reusable.
This resets the instance to its unloaded state. The next accessor call loads the dataset again.
§Returns
Table- the owned table of 1372 samples and 5 columns.
§Errors
Returns DatasetError if loading fails (network, file I/O, or parsing).
Trait Implementations§
Source§impl Debug for BanknoteAuthentication
impl Debug for BanknoteAuthentication
Source§impl MlDataset for BanknoteAuthentication
impl MlDataset for BanknoteAuthentication
Source§const NAME: &'static str = "banknote_authentication"
const NAME: &'static str = "banknote_authentication"
"iris", "sms_spam").