-
Notifications
You must be signed in to change notification settings - Fork 0
/
graf.py
60 lines (42 loc) · 1.75 KB
/
graf.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
50
51
52
53
54
55
56
57
58
59
60
# coding=utf-8
# Guardo métodos generales de visualización
# -----------------------------------------------------------------------------
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
def graf_GP(x, mu, std):
plt.plot(x, mu, color="#4682b4", alpha=0.3)
plt.fill(np.concatenate([x, x[::-1]]), np.concatenate([mu - 1.9600 * std,
(mu + 1.9600 * std)[::-1]]), alpha=.5, fc='#C0C0C0', ec='None',
label='95% confidence interval')
def graf_hist(values, label):
# std = np.std(values)
# mean = np.mean(values)
# x = np.linspace(mean - 4 * std, mean + 4 * std, 100)
# plt.plot(x, mlab.normpdf(x, mean, std), 'k--')
n, bins, patches = plt.hist(values, 60, normed=False, histtype='bar', alpha=0.6,
label=label)
def sample_hist(values, real = None, feature_name='Feature', save_path='', show=False):
"""
Parameters
----------
values: Valores con los que generar el histograma (features sampleadas)
real: Valor real de la feature
feature_name: Nombre de la feature
"""
mean = np.mean(values)
std = np.std(values)
x = np.linspace(mean - 4*std,mean +4*std,100)
plt.figure(figsize=(6*3.13,9))
plt.plot(x,mlab.normpdf(x,mean,std), 'k--')
n, bins, patches = plt.hist(values, 30, normed=1, histtype='bar', color = 'c', alpha=0.6)
plt.axvline(x= real, color = 'r', label=u'Real value')
plt.title(feature_name, size=18)
plt.xlabel('Feature Value', size=14)
#plt.ylabel('Probability density', rotation = 'horizontal', labelpad=60, size=14)
plt.legend(loc='upper right')
if show:
plt.show()
if save_path != '':
plt.savefig(save_path + feature_name + '.png')
plt.close()