-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_all.py
49 lines (41 loc) · 1.29 KB
/
draw_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def draw_features(X, y, title):
"""
draw bar features
args:
X : X data
y : y labels
title : bar title
"""
import numpy as np
import matplotlib.pyplot as plt
#draw list of features
width = 0.4 # the width of the bars
ind = np.arange(len(X)) # the x locations for the groups
plt.barh(ind, X, width, color='green')
plt.yticks(ind, y)
plt.title(title)
plt.xlabel('Relative importance')
plt.ylabel('Feature')
plt.plot(figsize=(20, 20))
def draw_true_vs_predicted(X, y, model, title, binarize=False):
"""
draw true vs predicted histogram
args:
X : X data
y : y labels
model: model to be predicted
title: histogram title
binarize : in case binarizing is needed
"""
import matplotlib.pyplot as plt
import numpy as np
#this point with a histogram both predicted and true
y_pred = model.predict(X)
if binarize:
y_pred = np.where(model.predict(X)<0.5, 0,1)
legend = ['True ' + title, 'Predicted ' + title]
plt.hist([y, y_pred], color=['orange', 'green'])
plt.ylabel("Frequency")
plt.legend(legend)
plt.title('True vs- predicted ' + title)
plt.plot(figsize=(20, 20))