{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e9ca0612-adb5-4d11-89a1-b224de3bd3b5", "metadata": {}, "outputs": [], "source": [ "import sys\n", "sys.path.append('../') ##accrocchio\n", "from src.utils import retrive_data,split\n", "import pickle" ] }, { "cell_type": "code", "execution_count": 3, "id": "dcb4d7b5-fe20-43f1-b988-51c9d595e06d", "metadata": {}, "outputs": [], "source": [ "labeled,labeled_small,to_remove = retrive_data(False,threshold_under_represented=0.5,path='/home/agobbi/Projects/PID/datanalytics/PID/src')" ] }, { "cell_type": "code", "execution_count": 4, "id": "569dff52-2a78-43f4-ae40-07842d3669e3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " class p\n", "0 0 0.203424\n", "1 1 0.013596\n", "2 2 0.056109\n", "3 3 1.130661\n", "4 4 16.206137\n" ] } ], "source": [ "dataset,dataset_test = split(labeled_small,\n", " SKI_AREA_TEST= 'Klausberg',\n", " SEASON_TEST_SKIAREA = 'Kronplatz',\n", " SEASON_TEST_YEAR= 2023,\n", " use_smote = False,\n", " weight_type = 'sqrt' )" ] }, { "cell_type": "code", "execution_count": 5, "id": "65405081-748d-43ef-aed6-2a58e38673b4", "metadata": {}, "outputs": [], "source": [ "with open('../src/best_params_and_final_model.pkl','rb') as f:\n", " tot,bst_FS,FS = pickle.load(f) " ] }, { "cell_type": "code", "execution_count": 36, "id": "53434031-1a11-49f7-9481-de77f250d35b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n" ] } ], "source": [ "import shap\n", "import xgboost as xgb\n", "import numpy as np\n", "dtest_FS = xgb.DMatrix(dataset_test.X_test_area[bst_FS.feature_names],dataset_test.y_test_area,enable_categorical=True,)\n", "\n", "explainer = shap.TreeExplainer(bst_FS,feature_names=bst_FS.feature_names)\n", "shap_values = explainer.shap_values(dtest_FS)\n" ] }, { "cell_type": "code", "execution_count": 37, "id": "f3b72453-27be-4db5-b40d-883454c294f9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "