Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Post-hoc prototype-based explanations with rules for time-series classifiers

License

NotificationsYou must be signed in to change notification settings

sbobek/tsproto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPILicensePyPI - DownloadsDocumentation Status

TSProto

Post-host prototype-based explanations with rules for time-series classifiers.

Key features:

  • Extracts interpretable prototype for any black-box model and creates a decision tree, where each node is constructed from the visual prototype
  • Integrated with SHAP explainer, as a backbone for extraction of interpretable components (However, SHAP can be replaced with any other feature-importance method)

Install

TSProto can be installed from eitherPyPI or directly from source code from this repository.

To install form PyPI:

pip install tsproto

To install from source code:

git clone https://github.com/sbobek/tsprotocd tsprotopip install .

Usage

For full examples on two illustrative cases go to:

  • Example of extracting sine wave prototype and explaining class with existence ora absence of a prototype:Jupyter Notebook
  • Example of extracting sine wave as a prototype end explaining class by difference in frequency of a prototypeJupyter Notebook

The basic usage of the TSProto assuming you have your model trained is straightforward:

fromtsproto.modelsimport*fromtsproto.utilsimport*#assuming that trainX, trainy and model are givenpe=PrototypeEncoder(clf,n_clusters=2,min_size=50,method='dtw',descriptors=['existance'],jump=1,pen=1,multiplier=2,n_jobs=-1,verbose=1)trainX,shapclass=getshap(model=model,X=trainX,y=trainy,shap_version='deep',bg_size=1000,absshap=True)#The input needs to be a 3D vector: number of samples, lenght of time-series, number of dimensions (features)trainXproto=train.reshape((trainX.shape[0],trainX.shape[1],1))shapclassXproto=shapclass.reshape((shapclass.shape[0],shapclass.shape[1],1))ohe_train,features,target_ohe,weights=pe.fit_transform(trainXproto,shapclassXproto)im=InterpretableModel()acc,prec,rec,f1,interpretable_model=im.fit_or_predict(ohe_train,features,target_ohe,intclf=None,# if intclf is given, the funciton behaves as predict,verbose=0,max_depth=2,min_samples_leaf=0.05,weights=None)

After the Interpretable model has been created it now can be visualised.

# Visualize modelfromtsproto.plotsimport*ds_final=ohe_train.copy()dot=export_decision_tree_with_embedded_histograms(decision_tree=interpretable_model,dataset=ds_final,target_name='target',feature_names=features,filename='synthetic',proto_encoder=pe,figsize=(6,3))fromIPython.displayimportSVG,ImageImage('synthetic.png')

Prototype visualization

Cite this work

More details on how the TSProto works and evaluation benchmarks can eb found in the following paper:

Comming soon

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp