pub fn electrocardiogram() -> Result<Dataset>
Expand description
Load an electrocardiogram as an example for a 1-D signal.
The returned signal is a 5 minute long electrocardiogram (ECG), a medical recording of the heart’s electrical activity, sampled at 360 Hz.
§Returns
A Dataset containing:
data
: The electrocardiogram in millivolt (mV) sampled at 360 Hz (as a column vector)- No target values
- Metadata including sampling rate
§Examples
use scirs2_datasets::time_series::electrocardiogram;
let ecg = electrocardiogram().unwrap();
println!("ECG data shape: ({}, {})", ecg.n_samples(), ecg.n_features());
Examples found in repository?
examples/time_series_datasets.rs (line 8)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 println!("Loading time series datasets...\n");
6
7 // Load the electrocardiogram dataset
8 let ecg = electrocardiogram()?;
9
10 println!("Electrocardiogram dataset:");
11 println!(" Time steps: {}", ecg.n_samples());
12 println!(" Features: {}", ecg.n_features());
13 println!(
14 " Sampling rate: {} Hz",
15 ecg.metadata
16 .get("sampling_rate")
17 .unwrap_or(&"unknown".to_string())
18 );
19 println!(
20 " Duration: {}",
21 ecg.metadata
22 .get("duration")
23 .unwrap_or(&"unknown".to_string())
24 );
25
26 // Get a slice of the data and display basic statistics
27 let ecg_slice = ecg.data.slice(s![0..10, 0]);
28 println!(" First 10 data points: {:?}", ecg_slice);
29
30 // Calculate some basic statistics
31 let ecg_data = ecg.data.column(0);
32 let min = ecg_data.fold(f64::INFINITY, |a, &b| a.min(b));
33 let max = ecg_data.fold(f64::NEG_INFINITY, |a, &b| a.max(b));
34 let mean = ecg_data.sum() / ecg_data.len() as f64;
35
36 println!(" Min: {:.3} mV", min);
37 println!(" Max: {:.3} mV", max);
38 println!(" Mean: {:.3} mV", mean);
39
40 // Note: Stock market and weather datasets are commented out because their source data
41 // is not yet available.
42
43 /*
44 // Load the stock market dataset
45 println!("\nStock market dataset:");
46
47 // Get price changes (returns)
48 let stock_returns = stock_market(true)?;
49 println!(" Time steps: {}", stock_returns.n_samples());
50 println!(" Companies: {}", stock_returns.n_features());
51
52 // Print companies
53 if let Some(feature_names) = &stock_returns.feature_names {
54 println!(" Companies: {}", feature_names.join(", "));
55 }
56
57 // Load the weather dataset
58 println!("\nWeather dataset:");
59 let temp_data = weather(Some("temperature"))?;
60
61 println!(" Time steps: {}", temp_data.n_samples());
62 println!(" Locations: {}", temp_data.n_features());
63 */
64
65 println!("\nTime series dataset loaded successfully!");
66
67 Ok(())
68}