{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Importing Models From Libraries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "PyXAI can [generate models]({{ site.baseurl }}/pyxai/documentation/learning/generating/) for you. Indeed, it provides dedicated functions that simplify this task. However, if your model has already been trained, you may want to import it into PyXAI in order to extract explanations. This page explains how to perform such a task." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Procedure " ] }, { "cell_type": "markdown", "metadata": {}, "source": "Consider the following source code to create a ```RandomForestClassifier``` using [Scikit-learn](https://scikit-learn.org/stable/): " }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from sklearn import datasets\n", "from sklearn.ensemble import RandomForestClassifier\n", "\n", "model_rf = RandomForestClassifier(random_state=0)\n", "data = datasets.load_breast_cancer(as_frame=True)\n", "X = data.data.to_numpy()\n", "Y = data.target.to_numpy()\n", "\n", "feature_names = data.feature_names\n", "model_rf.fit(X, Y);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can import this ML model using the ```import_models``` method of the ```ModelIO``` class:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a table summarizing the library compatibility of ```import_models```:\n\n
| Type | \nScikit-learn | \nXgboost | \nLightGBM | \n
|---|---|---|---|
| Decision Tree | \nDecisionTreeClassifier | \n\n | \n |
| Random Forest | \nRandomForestClassifier | \n\n | \n |
| Boosted Tree | \n\n | XGBClassifier XGBRegressor | \n LGBMRegressor | \n