-
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.
- Loading branch information
1 parent
5e19df0
commit a21c8e1
Showing
5 changed files
with
304 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# CATEGORIES PER SEQUENCE" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"\n", | ||
"df_tgt = pd.read_csv(\"https://github.com/mostly-ai/public-demo-data/raw/refs/heads/dev/baseball/batting.csv.gz\")\n", | ||
"df_tgt.head(2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._coherence import pull_data_for_coherence\n", | ||
"\n", | ||
"df_tgt = pull_data_for_coherence(df_tgt=df_tgt, tgt_context_key=\"players_id\")\n", | ||
"df_tgt.head(2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._coherence import calculate_categories_per_sequence\n", | ||
"\n", | ||
"categories_per_sequence_df = calculate_categories_per_sequence(df=df_tgt, context_key=\"players_id\")\n", | ||
"categories_per_sequence_df.head(2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._accuracy import calculate_numeric_uni_kdes\n", | ||
"\n", | ||
"trn_num_kdes = calculate_numeric_uni_kdes(categories_per_sequence_df)\n", | ||
"trn_num_kdes[\"team\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._accuracy import bin_data\n", | ||
"\n", | ||
"\n", | ||
"cat_share_per_sequence_binned = bin_data(categories_per_sequence_df, bins=10)[0]\n", | ||
"cat_share_per_sequence_binned.head(2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._accuracy import calculate_categorical_uni_counts\n", | ||
"\n", | ||
"\n", | ||
"trn_bin_col_cnts = calculate_categorical_uni_counts(df=cat_share_per_sequence_binned, hash_rare_values=False)\n", | ||
"trn_bin_col_cnts[\"team\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._accuracy import plot_univariate\n", | ||
"\n", | ||
"for col in categories_per_sequence_df.columns:\n", | ||
" if col != \"players_id\": # Skip the context key\n", | ||
" display(\n", | ||
" plot_univariate(\n", | ||
" col_name=col,\n", | ||
" trn_num_kde=trn_num_kdes.get(col),\n", | ||
" syn_num_kde=trn_num_kdes.get(col),\n", | ||
" trn_cat_col_cnts=None,\n", | ||
" syn_cat_col_cnts=None,\n", | ||
" trn_bin_col_cnts=trn_bin_col_cnts[col],\n", | ||
" syn_bin_col_cnts=trn_bin_col_cnts[col],\n", | ||
" accuracy=0.5,\n", | ||
" )\n", | ||
" )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# SEQUENCES PER CATEGORY" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._coherence import calculate_sequences_per_category\n", | ||
"\n", | ||
"sequences_per_category_dict, sequences_per_category_binned_dict = calculate_sequences_per_category(\n", | ||
" df=df_tgt, context_key=\"players_id\"\n", | ||
")\n", | ||
"display(sequences_per_category_dict[\"team\"].head(2))\n", | ||
"display(sequences_per_category_binned_dict[\"team\"])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mostlyai.qa._accuracy import plot_univariate\n", | ||
"\n", | ||
"for col in categories_per_sequence_df.columns:\n", | ||
" if col != \"players_id\": # Skip the context key\n", | ||
" display(\n", | ||
" plot_univariate(\n", | ||
" col_name=col,\n", | ||
" trn_num_kde=None,\n", | ||
" syn_num_kde=None,\n", | ||
" trn_cat_col_cnts=sequences_per_category_dict[col],\n", | ||
" syn_cat_col_cnts=sequences_per_category_dict[col],\n", | ||
" trn_bin_col_cnts=sequences_per_category_binned_dict[col],\n", | ||
" syn_bin_col_cnts=sequences_per_category_binned_dict[col],\n", | ||
" accuracy=0.5,\n", | ||
" trn_col_total=df_tgt[\"players_id\"].nunique(),\n", | ||
" syn_col_total=df_tgt[\"players_id\"].nunique(),\n", | ||
" )\n", | ||
" )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"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.10.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Oops, something went wrong.