pub struct Background { /* private fields */ }Expand description
A reference dataset used by a SHAP explainer.
Background owns its data so that explainers can safely retain it for
their entire lifetime.
The data has shape:
(n_background_samples, n_features)Implementations§
Source§impl Background
impl Background
Sourcepub fn new(data: Array2<f64>) -> Result<Self>
pub fn new(data: Array2<f64>) -> Result<Self>
Creates a background dataset from an owned array.
§Errors
Returns ShapError::EmptyBackground when the supplied array has
zero rows.
Sourcepub fn from_view(data: ArrayView2<'_, f64>) -> Result<Self>
pub fn from_view(data: ArrayView2<'_, f64>) -> Result<Self>
Creates a background dataset by copying an array view.
Sourcepub fn data(&self) -> ArrayView2<'_, f64>
pub fn data(&self) -> ArrayView2<'_, f64>
Returns the underlying background data.
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Returns the number of features.
Sourcepub fn row(&self, index: usize) -> Result<ArrayView1<'_, f64>>
pub fn row(&self, index: usize) -> Result<ArrayView1<'_, f64>>
Returns one background observation.
§Errors
Returns ShapError::InvalidConfiguration if index is outside
the background dataset.
Sourcepub fn sample<R: Rng + ?Sized>(
&self,
n_samples: usize,
rng: &mut R,
) -> Result<Self>
pub fn sample<R: Rng + ?Sized>( &self, n_samples: usize, rng: &mut R, ) -> Result<Self>
Creates a new background dataset containing a random sample of the existing observations.
Sampling is performed without replacement.
If n_samples is greater than or equal to the current number of
observations, a clone of the complete background dataset is returned.
Trait Implementations§
Source§impl Clone for Background
impl Clone for Background
Source§fn clone(&self) -> Background
fn clone(&self) -> Background
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more