1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! # openml-rust
//!
//! The openml crate provides functions to fetch tasks and data sets from https://openml.org, and
//! run them with machine learning models.
//!
//! ## Example
//!
//! ```rust
//!extern crate openml;
//!
//!use openml::prelude::*;
//!use openml::{PredictiveAccuracy, SupervisedClassification};
//!use openml::baseline::NaiveBayesClassifier;
//!
//!fn main() {
//!    // Load "Supervised Classification on iris" task (https://www.openml.org/t/59)
//!    let task = SupervisedClassification::from_openml(59).unwrap();
//!
//!    println!("Task: {}", task.name());
//!
//!    // run the task
//!    let result: PredictiveAccuracy<_> = task.run(|train, test| {
//!        // train classifier
//!        let nbc: NaiveBayesClassifier<u8> = train
//!            .map(|(x, y)| (x, y))
//!            .collect();
//!
//!        // test classifier
//!        let y_out: Vec<_> = test
//!            .map(|x| nbc.predict(x))
//!            .collect();
//!
//!        Box::new(y_out.into_iter())
//!    });
//!
//!    println!("Classification Accuracy: {}", result.result());
//!}
//! ```

extern crate app_dirs;
extern crate arff;
extern crate fs2;
extern crate futures;
extern crate hyper;
extern crate hyper_tls;
#[macro_use]
extern crate log;
extern crate num_traits;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[cfg(test)]
extern crate simple_logger;
#[cfg(test)]
extern crate time;
extern crate tokio_core;

pub mod baseline;
mod dataset;
mod error;
mod measure_accumulator;
mod openml_api;
pub mod prelude;
mod procedures;
mod tasks;

pub use measure_accumulator::{
    MeasureAccumulator,
    PredictiveAccuracy,
    RootMeanSquaredError
};

pub use tasks::{
    SupervisedClassification,
    SupervisedRegression,
    Task
};

#[cfg(test)]
mod tests {
    use log::Level;
    use time::PreciseTime;

    use baseline::NaiveBayesClassifier;
    use measure_accumulator::PredictiveAccuracy;

    use super::*;

    #[test]
    fn apidev() {
        let task = SupervisedClassification::from_openml(59).unwrap();

        println!("{}", task.name());

        let result: PredictiveAccuracy<_> = task.run_static(|_train, test| {
            let y_out: Vec<_> = test.map(|_row: &[f64; 4]| 0).collect();
            Box::new(y_out.into_iter())
        });

        println!("{:#?}", result);

        #[allow(dead_code)]
        #[derive(Deserialize)]
        struct Row {
            sepallength: f32,
            sepalwidth: f32,
            petallength: f32,
            petalwidth: f32,
        }

        let result: PredictiveAccuracy<_> = task.run_static(|train, test| {
            let (_x_train, _y_train): (Vec<&Row>, Vec<i32>) = train.unzip();
            let y_out: Vec<_> = test.map(|_row: &Row| 0).collect();
            Box::new(y_out.into_iter())
        });

        println!("{:#?}", result);

        let result: PredictiveAccuracy<_> = task.run(|train, test| {
            // train classifier
            let nbc: NaiveBayesClassifier<u8> = train
                .map(|(x, y)| (x, y))
                .collect();

            // test classifier
            let y_out: Vec<_> = test
                .map(|x| nbc.predict(x))
                .collect();

            Box::new(y_out.into_iter())
        });

        println!("{:#?}", result);
    }

    #[test]
    fn apidev2() {
        use simple_logger;
        simple_logger::init_with_level(Level::Info).unwrap();

        let start = PreciseTime::now();

        let task = SupervisedClassification::from_openml(146825).unwrap();
        //let task = SupervisedClassification::from_openml(167147).unwrap();

        let end = PreciseTime::now();

        let result: PredictiveAccuracy<_> = task.run(|_train, test| {
            let y_out: Vec<_> = test.map(|_row: &[u8]| 0).collect();
            Box::new(y_out.into_iter())
        });

        println!("{:#?}", result);

        println!("loading took {} seconds.", start.to(end));
    }
}