{ "cells": [ { "cell_type": "markdown", "id": "6fcc6043", "metadata": {}, "source": [ "# Shapash with custom colors\n", "\n", "With this tutorial you will understand how to manipulate colors with Shapash plots\n", "\n", "Contents:\n", "- Build a Regressor\n", "- Compile Shapash SmartExplainer\n", "- Use `palette_name` parameter\n", "- Use `colors_dict` parameter\n", "- Change the colors after comiling the explainer\n", "\n", "Data from Kaggle [House Prices](https://www.kaggle.com/c/house-prices-advanced-regression-techniques/data)" ] }, { "cell_type": "code", "execution_count": 1, "id": "48c97ace", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from category_encoders import OrdinalEncoder\n", "from lightgbm import LGBMRegressor\n", "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "markdown", "id": "a2575fa2", "metadata": {}, "source": [ "## Building Supervized Model" ] }, { "cell_type": "code", "execution_count": 2, "id": "40c1779a", "metadata": {}, "outputs": [], "source": [ "from shapash.data.data_loader import data_loading\n", "house_df, house_dict = data_loading('house_prices')" ] }, { "cell_type": "code", "execution_count": 3, "id": "3329d91c", "metadata": {}, "outputs": [], "source": [ "y_df=house_df['SalePrice'].to_frame()\n", "X_df=house_df[house_df.columns.difference(['SalePrice'])]" ] }, { "cell_type": "code", "execution_count": 4, "id": "0e3d357e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | MSSubClass | \n", "MSZoning | \n", "LotArea | \n", "Street | \n", "LotShape | \n", "LandContour | \n", "Utilities | \n", "LotConfig | \n", "LandSlope | \n", "Neighborhood | \n", "... | \n", "EnclosedPorch | \n", "3SsnPorch | \n", "ScreenPorch | \n", "PoolArea | \n", "MiscVal | \n", "MoSold | \n", "YrSold | \n", "SaleType | \n", "SaleCondition | \n", "SalePrice | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Id | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
1 | \n", "2-Story 1946 & Newer | \n", "Residential Low Density | \n", "8450 | \n", "Paved | \n", "Regular | \n", "Near Flat/Level | \n", "All public Utilities (E,G,W,& S) | \n", "Inside lot | \n", "Gentle slope | \n", "College Creek | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "2 | \n", "2008 | \n", "Warranty Deed - Conventional | \n", "Normal Sale | \n", "208500 | \n", "
2 | \n", "1-Story 1946 & Newer All Styles | \n", "Residential Low Density | \n", "9600 | \n", "Paved | \n", "Regular | \n", "Near Flat/Level | \n", "All public Utilities (E,G,W,& S) | \n", "Frontage on 2 sides of property | \n", "Gentle slope | \n", "Veenker | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "5 | \n", "2007 | \n", "Warranty Deed - Conventional | \n", "Normal Sale | \n", "181500 | \n", "
3 | \n", "2-Story 1946 & Newer | \n", "Residential Low Density | \n", "11250 | \n", "Paved | \n", "Slightly irregular | \n", "Near Flat/Level | \n", "All public Utilities (E,G,W,& S) | \n", "Inside lot | \n", "Gentle slope | \n", "College Creek | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "9 | \n", "2008 | \n", "Warranty Deed - Conventional | \n", "Normal Sale | \n", "223500 | \n", "
4 | \n", "2-Story 1945 & Older | \n", "Residential Low Density | \n", "9550 | \n", "Paved | \n", "Slightly irregular | \n", "Near Flat/Level | \n", "All public Utilities (E,G,W,& S) | \n", "Corner lot | \n", "Gentle slope | \n", "Crawford | \n", "... | \n", "272 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "2 | \n", "2006 | \n", "Warranty Deed - Conventional | \n", "Abnormal Sale | \n", "140000 | \n", "
5 | \n", "2-Story 1946 & Newer | \n", "Residential Low Density | \n", "14260 | \n", "Paved | \n", "Slightly irregular | \n", "Near Flat/Level | \n", "All public Utilities (E,G,W,& S) | \n", "Frontage on 2 sides of property | \n", "Gentle slope | \n", "Northridge | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "12 | \n", "2008 | \n", "Warranty Deed - Conventional | \n", "Normal Sale | \n", "250000 | \n", "
5 rows × 73 columns
\n", "