Struct gbdt::decision_tree::TrainingCache
source · [−]pub struct TrainingCache { /* private fields */ }
Expand description
Cache the sort results and some calculation results
Implementations
sourceimpl TrainingCache
impl TrainingCache
sourcepub fn get_cache(feature_size: usize, data: &DataVec, cache_level: u8) -> Self
pub fn get_cache(feature_size: usize, data: &DataVec, cache_level: u8) -> Self
Allocate the training cache. Feature size, training set and cache level should be provided.
use gbdt::config::Loss;
use gbdt::decision_tree::{Data, DecisionTree, TrainingCache};
// set up training data
let data1 = Data::new_training_data(
vec![1.0, 2.0, 3.0],
1.0,
2.0,
None
);
let data2 = Data::new_training_data(
vec![1.1, 2.1, 3.1],
1.0,
1.0,
None
);
let data3 = Data::new_training_data(
vec![2.0, 2.0, 1.0],
1.0,
0.5,
None
);
let mut dv = Vec::new();
dv.push(data1);
dv.push(data2);
dv.push(data3);
let mut cache = TrainingCache::get_cache(3, &dv, 2);
sourcepub fn get_preds(&self) -> Vec<ValueType>
pub fn get_preds(&self) -> Vec<ValueType>
Return the training data’s predictions using this decision tree. These results are computed during training and then cached.
Example
use gbdt::config::Loss;
use gbdt::decision_tree::{Data, DecisionTree, TrainingCache};
// set up training data
let data1 = Data::new_training_data(
vec![1.0, 2.0, 3.0],
1.0,
2.0,
None
);
let data2 = Data::new_training_data(
vec![1.1, 2.1, 3.1],
1.0,
1.0,
None
);
let data3 = Data::new_training_data(
vec![2.0, 2.0, 1.0],
1.0,
0.5,
None
);
let data4 = Data::new_training_data(
vec![2.0, 2.3, 1.2],
1.0,
3.0,
None
);
let mut dv = Vec::new();
dv.push(data1);
dv.push(data2);
dv.push(data3);
dv.push(data4);
// train a decision tree
let mut tree = DecisionTree::new();
tree.set_feature_size(3);
tree.set_max_depth(2);
tree.set_min_leaf_size(1);
tree.set_loss(Loss::SquaredError);
let mut cache = TrainingCache::get_cache(3, &dv, 2);
tree.fit(&dv, &mut cache);
// get predictions for the training data
println!("{:?}", cache.get_preds());
// output:
// [2.0, 0.75, 0.75, 3.0]
Auto Trait Implementations
impl RefUnwindSafe for TrainingCache
impl Send for TrainingCache
impl Sync for TrainingCache
impl Unpin for TrainingCache
impl UnwindSafe for TrainingCache
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more