Skip to content

Commit

Permalink
classification_report_pd
Browse files Browse the repository at this point in the history
  • Loading branch information
wassname committed Oct 15, 2020
1 parent 195ffe3 commit 6cac624
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4096,20 +4096,7 @@
}
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import sklearn.metrics\n",
"import numpy as np\n",
"\n",
"def classification_report(*args, **kwargs):\n",
" out_df = pd.DataFrame(sklearn.metrics.classification_report(*args, **kwargs, output_dict=True)).T\n",
" # Order cols\n",
" out_df[[\"precision\",\"recall\",\"f1-score\",\"support\"]] \n",
" # Round\n",
" out_df[[\"precision\",\"recall\",\"f1-score\"]]= out_df[[\"precision\",\"recall\",\"f1-score\"]].apply(lambda x: round(x,2))\n",
" out_df[[\"support\"]]= out_df[[\"support\"]].apply(lambda x: x.astype(np.int))\n",
" return out_df"
]
"source": []
},
{
"cell_type": "code",
Expand Down Expand Up @@ -4278,6 +4265,7 @@
}
],
"source": [
"from deep_ml_curriculum.classification_report import pd_classification_report\n",
"df_report = classification_report(true, preds, labels=range(len(encoder.classes_)), target_names=encoder.classes_)\n",
"df_report[df_report.support>0]"
]
Expand Down Expand Up @@ -5508,18 +5496,6 @@
"1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-07T12:22:51.313045Z",
"start_time": "2020-10-07T12:22:51.218514Z"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 98,
Expand All @@ -5528,6 +5504,7 @@
"end_time": "2020-10-07T12:58:49.315876Z",
"start_time": "2020-10-07T12:55:35.018783Z"
},
"lines_to_next_cell": 0,
"scrolled": false
},
"outputs": [
Expand Down Expand Up @@ -6058,6 +6035,13 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -6121,7 +6105,12 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-07T12:22:51.313045Z",
"start_time": "2020-10-07T12:22:51.218514Z"
}
},
"outputs": [],
"source": []
}
Expand Down Expand Up @@ -6152,7 +6141,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.7.0"
},
"toc": {
"base_numbering": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,19 +761,6 @@ def training_loop(x_train, y_train, x_test, y_test, mode, epochs=1, bs=128, max_

# This beats the baseline, so the model is doing better than the naive answer of "the same again". But lets break it down by lithology

# +
import pandas as pd
import sklearn.metrics
import numpy as np

def classification_report(*args, **kwargs):
out_df = pd.DataFrame(sklearn.metrics.classification_report(*args, **kwargs, output_dict=True)).T
# Order cols
out_df[["precision","recall","f1-score","support"]]
# Round
out_df[["precision","recall","f1-score"]]= out_df[["precision","recall","f1-score"]].apply(lambda x: round(x,2))
out_df[["support"]]= out_df[["support"]].apply(lambda x: x.astype(np.int))
return out_df


# +
Expand All @@ -782,6 +769,7 @@ def classification_report(*args, **kwargs):
# df_report[df_report.support>0]
# -

from deep_ml_curriculum.classification_report import pd_classification_report
df_report = classification_report(true, preds, labels=range(len(encoder.classes_)), target_names=encoder.classes_)
df_report[df_report.support>0]

Expand Down Expand Up @@ -977,9 +965,6 @@ def plot_well(df, model, depth_min=0, depth_max=18000, well_name="30_6-11", devi
plot_well(df, model)
confusion_matrix(true, preds)
1
# -


# +
# Params
seq_length = 400 # CHANGE ME
Expand Down Expand Up @@ -1035,6 +1020,7 @@ def plot_well(df, model, depth_min=0, depth_max=18000, well_name="30_6-11", devi




# ## Further Reading
# - [Introduction to RNN](http://slazebni.cs.illinois.edu/spring17/lec02_rnn.pdf)
# - [A friendly introduction to Recurrent Neural Networks](https://www.youtube.com/watch?v=UNmqTiOnRfg)
Expand Down

0 comments on commit 6cac624

Please sign in to comment.