-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #3: added simple inspection method
- Loading branch information
Stefan Heid
committed
Aug 10, 2023
1 parent
0915684
commit e86a2bf
Showing
3 changed files
with
249 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "adc6c663-b073-4451-9821-216c578bbd69", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from skpsl import ProbabilisticScoringList\n", | ||
"from sklearn.datasets import make_classification\n", | ||
"from sklearn.model_selection import cross_val_score, ShuffleSplit\n", | ||
"from functools import reduce\n", | ||
"from operator import or_\n", | ||
"import numpy as np\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "764414e5-261c-4a77-b14b-2235472b9baf", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Brier score: 0.1924\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Generating synthetic data with continuous features and a binary target variable\n", | ||
"X, y = make_classification(random_state=42)\n", | ||
"X = (X > .5).astype(int)\n", | ||
"\n", | ||
"for train, test in ShuffleSplit(1, test_size=.2, random_state=42).split(X):\n", | ||
" psl = ProbabilisticScoringList([-1, 1, 2])\n", | ||
" psl.fit(X[train], y[train])\n", | ||
" print(f\"Brier score: {psl.score(X[test], y[test]):.4f}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"id": "26a044d2-d3a1-43eb-bbef-b8e7050ce568", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style scoped>\n", | ||
" .dataframe tbody tr th:only-of-type {\n", | ||
" vertical-align: middle;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>Stage</th>\n", | ||
" <th>Score</th>\n", | ||
" <th>T = -3</th>\n", | ||
" <th>T = -2</th>\n", | ||
" <th>T = -1</th>\n", | ||
" <th>T = 0</th>\n", | ||
" <th>T = 1</th>\n", | ||
" <th>T = 2</th>\n", | ||
" <th>T = 3</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>0</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>0.5375</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>1</td>\n", | ||
" <td>2.0</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>0.1818</td>\n", | ||
" <td>-</td>\n", | ||
" <td>0.9722</td>\n", | ||
" <td>-</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>2</td>\n", | ||
" <td>-1.0</td>\n", | ||
" <td>-</td>\n", | ||
" <td>-</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.2759</td>\n", | ||
" <td>0.9091</td>\n", | ||
" <td>1.0</td>\n", | ||
" <td>-</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>3</td>\n", | ||
" <td>-1.0</td>\n", | ||
" <td>-</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.069</td>\n", | ||
" <td>0.8571</td>\n", | ||
" <td>0.9091</td>\n", | ||
" <td>1.0</td>\n", | ||
" <td>-</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>4</td>\n", | ||
" <td>1.0</td>\n", | ||
" <td>-</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.2857</td>\n", | ||
" <td>0.9167</td>\n", | ||
" <td>1.0</td>\n", | ||
" <td>1.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>5</th>\n", | ||
" <td>5</td>\n", | ||
" <td>-1.0</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.0</td>\n", | ||
" <td>0.4000</td>\n", | ||
" <td>1.0</td>\n", | ||
" <td>1.0</td>\n", | ||
" <td>1.0</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" Stage Score T = -3 T = -2 T = -1 T = 0 T = 1 T = 2 T = 3\n", | ||
"0 0 - - - - 0.5375 - - -\n", | ||
"1 1 2.0 - - - 0.1818 - 0.9722 -\n", | ||
"2 2 -1.0 - - 0.0 0.2759 0.9091 1.0 -\n", | ||
"3 3 -1.0 - 0.0 0.069 0.8571 0.9091 1.0 -\n", | ||
"4 4 1.0 - 0.0 0.0 0.2857 0.9167 1.0 1.0\n", | ||
"5 5 -1.0 0.0 0.0 0.0 0.4000 1.0 1.0 1.0" | ||
] | ||
}, | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df = psl.inspect(5)\n", | ||
"\n", | ||
"pd.set_option(\"display.precision\", 4)\n", | ||
"df.fillna(\"-\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.11.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters