import xplainable as xp
import pandas as pd
from sklearn.model_selection import train_test_split
from fastai.imports import *
from IPython.display import HTMLXclassifier
Xclassifier
iskaggle = os.environ.get('KAGGLE_KERNEL_RUN_TYPE', '')
folder = Path('titanic')
location = Path('Data')
path = Path(f'{location}/{folder}')
import zipfile,kaggle
kaggle.api.competition_download_cli(f'{folder}', path = str(location))
zipfile.ZipFile(f'{location}/{folder}.zip').extractall(f'{location}/{folder}')titanic.zip: Skipping, found more recently modified local copy (use --force to force download)
df = pd.read_csv(path/'train.csv')
df.head()| PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.2500 | NaN | S |
| 1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Thayer) | female | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | C |
| 2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.9250 | NaN | S |
| 3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.1000 | C123 | S |
| 4 | 5 | 0 | 3 | Allen, Mr. William Henry | male | 35.0 | 0 | 0 | 373450 | 8.0500 | NaN | S |
pp = xp.Preprocessor()
pp.preprocess(df)df = pd.read_csv('preprocessed_1695571534.csv')
df.head()| PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Thayer) | female | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | C |
| 1 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.1000 | C123 | S |
| 2 | 7 | 0 | 1 | McCarthy, Mr. Timothy J | male | 54.0 | 0 | 0 | 17463 | 51.8625 | E46 | S |
| 3 | 11 | 1 | 3 | Sandstrom, Miss. Marguerite Rut | female | 4.0 | 1 | 1 | PP 9549 | 16.7000 | G6 | S |
| 4 | 12 | 1 | 1 | Bonnell, Miss. Elizabeth | female | 58.0 | 0 | 0 | 113783 | 26.5500 | C103 | S |
# Train a model
model = xp.classifier(df)/home/ben/mambaforge/envs/cfast/lib/python3.11/site-packages/xplainable/_dependencies.py:39: UserWarning: Your version of Tornado is greater than 6.1, which is known to crash the Jupyter kernel when training models. Please consider downgrading to Tornado 6.1
warnings.warn("Your version of Tornado is greater than 6.1, which"