-
Notifications
You must be signed in to change notification settings - Fork 0
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
Belen Carolina Saldias Fuentes
committed
Jan 11, 2019
1 parent
ee21947
commit bd4f4df
Showing
11 changed files
with
27,561 additions
and
0 deletions.
There are no files selected for viewing
1,228 changes: 1,228 additions & 0 deletions
1,228
00. PYMC | BBVI - Bayesian YN question type.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
initial_yn_questions,id | ||
879,6 | ||
890,4 | ||
889,15 | ||
886,3 | ||
880,8 | ||
902,16 | ||
911,13 | ||
903,19 | ||
924,18 | ||
927,7 | ||
908,11 | ||
881,14 | ||
922,27 | ||
858,17 | ||
895,23 | ||
888,20 | ||
885,21 | ||
896,12 | ||
920,2 | ||
868,26 | ||
906,10 | ||
887,22 | ||
940,5 |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,20 @@ | ||
initial_yn_questions,id | ||
868,19 | ||
883,15 | ||
899,18 | ||
883,11 | ||
879,10 | ||
872,21 | ||
913,2 | ||
912,7 | ||
899,5 | ||
873,20 | ||
885,9 | ||
919,12 | ||
925,8 | ||
905,17 | ||
883,16 | ||
902,6 | ||
880,4 | ||
856,13 | ||
880,14 |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,74 @@ | ||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
from sklearn.metrics import confusion_matrix | ||
from sklearn.metrics import accuracy_score | ||
from sklearn.metrics import precision_score | ||
from sklearn.metrics import recall_score | ||
from sklearn.metrics import f1_score | ||
|
||
class ListTable(list): | ||
def _repr_html_(self): | ||
html = ["<table>"] | ||
for row in self: | ||
html.append("<tr>") | ||
|
||
for col in row: | ||
html.append("<td>{0}</td>".format(col)) | ||
|
||
html.append("</tr>") | ||
html.append("</table>") | ||
return ''.join(html) | ||
|
||
def draw_theta(theta, labels=None): | ||
"""Draw the confusion matrix received. | ||
Parameters | ||
---------- | ||
theta : np.array | ||
confusion matrix drawn | ||
""" | ||
|
||
if labels is None: | ||
labels = [] | ||
|
||
row_sums = theta.sum(axis=1) | ||
new_matrix = theta / row_sums[:, np.newaxis] | ||
print(np.round(new_matrix,3)) | ||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(111) | ||
res = ax.imshow(new_matrix, cmap=plt.cm.Blues, interpolation='nearest') | ||
plt.title('Confusion matrix\n') | ||
ticks = [i for i in range(len(theta))] | ||
ax.set_xticks(ticks) | ||
ax.set_yticks(ticks) | ||
ax.set_xticklabels(labels) | ||
ax.set_yticklabels(labels) | ||
plt.ylabel('True Class') | ||
plt.xlabel('Predicted Class') | ||
plt.show() | ||
|
||
def draw_metrics(y_true, y_pred, labels): | ||
""" | ||
This method is only for to draw metrics | ||
""" | ||
draw_theta(confusion_matrix(y_true, y_pred) , labels) | ||
table = ListTable() | ||
print("Acurracy score",accuracy_score(y_true, y_pred)) | ||
table.append(["Metrics / Classes"]+list(labels)) | ||
table.append(["Precision score"]+list(np.round(precision_score(y_true, y_pred, average=None),3))) | ||
table.append(["Recall score"]+list(np.round(recall_score(y_true, y_pred, average=None),3))) | ||
table.append(["F score"]+list(np.round(f1_score(y_true, y_pred, average=None),3))) | ||
return table | ||
|
||
def metrics(y_true, y_pred): | ||
|
||
to_ret = { | ||
'p':precision_score(y_true, y_pred, average=None), | ||
'r':recall_score(y_true, y_pred, average=None), | ||
'f':f1_score(y_true, y_pred, average=None), | ||
} | ||
|
||
return to_ret | ||
|