Skip to content

Commit

Permalink
ready for binder
Browse files Browse the repository at this point in the history
  • Loading branch information
kwinkunks committed Oct 1, 2016
1 parent 14dcf83 commit 52b232c
Show file tree
Hide file tree
Showing 5 changed files with 959 additions and 822 deletions.
461 changes: 293 additions & 168 deletions Facies_classification.ipynb

Large diffs are not rendered by default.

44 changes: 26 additions & 18 deletions classification_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,50 @@ def display_cm(cm, labels, hide_zeros=False,
recall = np.diagonal(cm)/cm.sum(axis=1).astype('float')
F1 = 2 * (precision * recall) / (precision + recall)

precision[np.isnan(precision)] = 0
recall[np.isnan(recall)] = 0
F1[np.isnan(F1)] = 0

total_precision = np.sum(precision * cm.sum(axis=1)) / cm.sum(axis=(0,1))
total_recall = np.sum(recall * cm.sum(axis=1)) / cm.sum(axis=(0,1))
total_F1 = np.sum(F1 * cm.sum(axis=1)) / cm.sum(axis=(0,1))
#print total_precision

columnwidth = max([len(x) for x in labels]+[5]) # 5 is value length
empty_cell = " " * columnwidth
# Print header
print " " + " Pred",
print(" " + " Pred", end=' ')
for label in labels:
print "%{0}s".format(columnwidth) % label,
print
print " " + " True"
print("%{0}s".format(columnwidth) % label, end=' ')
print("%{0}s".format(columnwidth) % 'Total')
print(" " + " True")
# Print rows
for i, label1 in enumerate(labels):
print " %{0}s".format(columnwidth) % label1,
print(" %{0}s".format(columnwidth) % label1, end=' ')
for j in range(len(labels)):
cell = "%{0}d".format(columnwidth) % cm[i, j]
if hide_zeros:
cell = cell if float(cm[i, j]) != 0 else empty_cell
print cell,

print
print(cell, end=' ')
print("%{0}d".format(columnwidth) % sum(cm[i,:]))

if display_metrics:
print
print "Precision",
print()
print("Precision", end=' ')
for j in range(len(labels)):
cell = "%{0}.2f".format(columnwidth) % precision[j]
print cell,
print
print " Recall",
print(cell, end=' ')
print("%{0}.2f".format(columnwidth) % total_precision)
print(" Recall", end=' ')
for j in range(len(labels)):
cell = "%{0}.2f".format(columnwidth) % recall[j]
print cell,
print
print " F1",
print(cell, end=' ')
print("%{0}.2f".format(columnwidth) % total_recall)
print(" F1", end=' ')
for j in range(len(labels)):
cell = "%{0}.2f".format(columnwidth) % F1[j]
print cell,
print
print(cell, end=' ')
print("%{0}.2f".format(columnwidth) % total_F1)


def display_adj_cm(
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies:
- python=3.5.2
- numpy
- matplotlib
- seaborn
- jupyter
- pandas
- scikit-learn
21 changes: 12 additions & 9 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"\n",
"All the code and data to reproduce *everything* in that article is right here in this repository. You can read the code in a [Jupyter Notebook](http://jupyter.org/) here...\n",
"\n",
"<div style=\"width:50%; margin: 12px 0px 6px 20px; padding: 8px; border: 2px solid darkblue; border-radius: 6px; font-size: 125%; background: #EEEEFF;\">\n",
"[**Facies_classification.ipynb**](Facies_classification.ipynb)\n",
"</div>\n",
"\n",
"See [the February issue of *The Leading Edge*](http://library.seg.org/doi/abs/10.1190/tle35020190.1) for Matt Hall's user guide to the tutorials; it explains how to run a Jupyter Notebook.\n",
"\n",
Expand Down Expand Up @@ -77,15 +79,16 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:binder]",
"language": "python",
"name": "conda-env-binder-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda env:binder]",
"language": "python",
"name": "conda-env-binder-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand Down
Loading

0 comments on commit 52b232c

Please sign in to comment.