{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8226e658", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 12, "id": "7e95cb09", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "X1", "rawType": "float64", "type": "float" }, { "name": "X2", "rawType": "float64", "type": "float" }, { "name": "Y", "rawType": "float64", "type": "float" } ], "ref": "018727a2-2342-424f-8395-021f40817c5a", "rows": [ [ "0", "-0.8363543", "4.520502", "-19.868094121443526" ], [ "1", "0.4020083", "3.252834", "-10.46598545005849" ], [ "2", "-0.2492138", "3.610425", "-12.91499193423918" ], [ "3", "-0.6257167", "4.58877", "-20.67839639765537" ], [ "4", "-0.9899948", "4.893924", "-22.99404413854238" ] ], "shape": { "columns": 3, "rows": 5 } }, "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
X1X2Y
0-0.8363544.520502-19.868094
10.4020083.252834-10.465985
2-0.2492143.610425-12.914992
3-0.6257174.588770-20.678396
4-0.9899954.893924-22.994044
\n", "
" ], "text/plain": [ " X1 X2 Y\n", "0 -0.836354 4.520502 -19.868094\n", "1 0.402008 3.252834 -10.465985\n", "2 -0.249214 3.610425 -12.914992\n", "3 -0.625717 4.588770 -20.678396\n", "4 -0.989995 4.893924 -22.994044" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = pd.read_excel(\"./data/data_pdp.xlsx\")\n", "data.head()" ] }, { "cell_type": "code", "execution_count": 11, "id": "4e9a9a97", "metadata": {}, "outputs": [], "source": [ "def partial_dependant_function(data: pd.DataFrame, model: object, feature: str, grid_points: list) -> list:\n", " \"\"\"Compute the Partial Dependence Plot (PDP) for a given feature.\"\"\"\n", " pdp = []\n", " for val in grid_points:\n", " data_temp = data.copy()\n", " data_temp[feature] = val\n", " preds = model.predict(data_temp)\n", " pdp.append(preds.mean())\n", " return pdp" ] }, { "cell_type": "code", "execution_count": null, "id": "9553a1d8", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "studies", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.9" } }, "nbformat": 4, "nbformat_minor": 5 }