Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
TreeExplainer Class Reference

A generic tree explainer: More...

#include <ExplainWrapper.h>

Inheritance diagram for TreeExplainer:
ModelExplainer PostProcessor SerializableObject

Public Member Functions

bool try_convert_trees ()
 
void init_post_processor (MedModel &model)
 Init ModelExplainer from MedModel - copies predictor pointer, might save normalizers pointers.
 
TreeExplainerMode get_mode () const
 
void _learn (const MedFeatures &train_mat)
 overload function for ModelExplainer - easier API
 
void explain (const MedFeatures &matrix, vector< map< string, float > > &sample_explain_reasons) const
 Virtual - return explain results in sample_feature_contrib.
 
void post_deserialization ()
 
- Public Member Functions inherited from ModelExplainer
virtual int init (map< string, string > &mapper)
 Global init for general args in all explainers. initialize directly all args in GlobalExplainerParams.
 
virtual int update (map< string, string > &mapper)
 Virtual to update object from parsed fields.
 
virtual void Learn (const MedFeatures &train_mat)
 Learns from predictor and train_matrix (PostProcessor API)
 
void Apply (MedFeatures &matrix)
 alias for explain
 
void get_input_fields (vector< Effected_Field > &fields) const
 List of fields that are used by this post_processor.
 
void get_output_fields (vector< Effected_Field > &fields) const
 List of fields that are being effected by this post_processor.
 
virtual void explain (MedFeatures &matrix) const
 Stores explain results in matrix.
 
void dprint (const string &pref) const
 
- Public Member Functions inherited from PostProcessor
void * new_polymorphic (string dname)
 for polymorphic classes that want to be able to serialize/deserialize a pointer * to the derived class given its type one needs to implement this function to return a new to the derived class given its type (as in my_type)
 
virtual float get_use_p ()
 
virtual int get_use_split ()
 
- Public Member Functions inherited from SerializableObject
virtual int version () const
 Relevant for serializations.
 
virtual string my_class_name () const
 For better handling of serializations it is highly recommended that each SerializableObject inheriting class will implement the next method.
 
virtual void serialized_fields_name (vector< string > &field_names) const
 The names of the serialized fields.
 
virtual void pre_serialization ()
 
virtual size_t get_size ()
 Gets bytes sizes for serializations.
 
virtual size_t serialize (unsigned char *blob)
 Serialiazing object to blob memory. return number ob bytes wrote to memory.
 
virtual size_t deserialize (unsigned char *blob)
 Deserialiazing blob to object. returns number of bytes read.
 
size_t serialize_vec (vector< unsigned char > &blob)
 
size_t deserialize_vec (vector< unsigned char > &blob)
 
virtual size_t serialize (vector< unsigned char > &blob)
 
virtual size_t deserialize (vector< unsigned char > &blob)
 
virtual int read_from_file (const string &fname)
 read and deserialize model
 
virtual int write_to_file (const string &fname)
 serialize model and write to file
 
virtual int read_from_file_unsafe (const string &fname)
 read and deserialize model without checking version number - unsafe read
 
int init_from_string (string init_string)
 Init from string.
 
int init_params_from_file (string init_file)
 
int init_param_from_file (string file_str, string &param)
 
int update_from_string (const string &init_string)
 
virtual string object_json () const
 

Data Fields

TreeEnsemble generic_tree_model
 
string proxy_model_type = ""
 proxy predictor type to relearn original predictor output with tree models
 
string proxy_model_init = ""
 proxy predictor arguments
 
bool interaction_shap = false
 If true will calc interaction_shap values (slower)
 
int approximate = false
 if true will run SAABAS alg - which is faster
 
float missing_value = MED_MAT_MISSING_VALUE
 missing value
 
bool verbose = false
 
- Data Fields inherited from ModelExplainer
MedPredictororiginal_predictor = NULL
 predictor we're trying to explain
 
ExplainFilters filters
 general filters of results
 
ExplainProcessings processing
 processing of results, like groupings, COV
 
GlobalExplainerParams global_explain_params
 
- Data Fields inherited from PostProcessor
PostProcessorTypes processor_type = PostProcessorTypes::FTR_POSTPROCESS_LAST
 
int use_split = -1
 
float use_p = 0.0
 

Additional Inherited Members

- Static Public Member Functions inherited from ModelExplainer
static void print_explain (MedSample &smp, int sort_mode=0)
 
- Static Public Member Functions inherited from PostProcessor
static PostProcessormake_processor (const string &processor_name, const string &params="")
 
static PostProcessormake_processor (PostProcessorTypes type, const string &params="")
 
static PostProcessorcreate_processor (string &params)
 

Detailed Description

A generic tree explainer:

  1. Reads tree model into structure to calc SHAP values - QRF, XGB, lightGBM (future - BART ?)
  2. for xgboost/lightGBM where conversion fails, use internal implementation of TreeShap
  3. train LightGBM/Xgboost proxy to explain non-tree Predictor

Member Function Documentation

◆ _learn()

void TreeExplainer::_learn ( const MedFeatures train_mat)
virtual

overload function for ModelExplainer - easier API

Implements ModelExplainer.

◆ explain()

void TreeExplainer::explain ( const MedFeatures matrix,
vector< map< string, float > > &  sample_explain_reasons 
) const
virtual

Virtual - return explain results in sample_feature_contrib.

of size: Sample_Count, Features_count + 1(for bias/prior score), outputs_count

Implements ModelExplainer.

◆ init_post_processor()

void TreeExplainer::init_post_processor ( MedModel model)
virtual

Init ModelExplainer from MedModel - copies predictor pointer, might save normalizers pointers.

Reimplemented from ModelExplainer.

◆ post_deserialization()

void TreeExplainer::post_deserialization ( )
virtual

Reimplemented from SerializableObject.


The documentation for this class was generated from the following files: