-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscatterplot.py
More file actions
77 lines (63 loc) · 2.82 KB
/
scatterplot.py
File metadata and controls
77 lines (63 loc) · 2.82 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pandas as pd
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib
import random as rd
def tfpn(y_true,y_pred, max_points = 100):
y_false=pd.DataFrame(map(lambda x:not x,y_true))
y_pred_false =pd.DataFrame( map(lambda x:not x,y_pred))
y_true = pd.DataFrame(y_true)
y_pred = pd.DataFrame(y_pred)
tp = map(bool,y_true*y_pred)
tn =map(bool,(y_false)*(y_pred_false))
fp =map(bool,y_false*y_pred)
fn =map(bool,y_true*(y_pred_false))
return tp, tn, fp, fn
def kde_statsmodels_m(x, x_grid, bandwidth=0.2, **kwargs):
"""Multivariate Kernel Density Estimation using Statsmodels"""
kde = KDEMultivariate(x, bw=bandwidth * np.ones_like(x),
var_type='c', **kwargs)
return kde.pdf(x_grid)
def binary(data, y_true, y_pred, feature_names=None, twoD=True, threeD=False, max_points = 100, max_plots=3, figure_no=1, decision_fxn=None):
'''Randomly selects max_points data points to be plotted from each category'''
'''feature names must be nested list of lists of 3 features'''
colors = ['g','b','r','y']
data = pd.DataFrame(data)
tp, tn, fp, fn = tfpn(y_true,y_pred, max_points)
# print 'scattering1', data.info()
print 'tp, tn, fp, fn = ', sum(tp), sum(tn), sum(fp), sum(fn)
for i in range(max_plots):
# print 'scattering2'
fig = plt.figure(figure_no+i)
if threeD:
ax = fig.add_subplot(111, projection='3d')
cols = (data.columns[3*i],data.columns[3*i+1],data.columns[3*i+2])
# print 'cols ', cols
# print 'dims ;',data.columns
for outcome, c, m in [(tp,'g','o'),(tn,'b','o'), (fp,'r','^'), (fn,'y','^')]:
# print 'colour ', c, 'sum outcome ', sum(outcome), outcome
xs = data[outcome][cols[0]]
# print 'xs ',xs
ys = data[outcome][cols[1]]
# print len(ys)
zs = data[outcome][cols[1]]
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel(cols[0])
ax.set_ylabel(cols[1])
ax.set_zlabel(cols[2])
scatter1_proxy = matplotlib.lines.Line2D([0],[0], linestyle="none", c=colors[0], marker = 'o')
scatter2_proxy = matplotlib.lines.Line2D([0],[0], linestyle="none", c=colors[1], marker = 'v')
ax.legend([scatter1_proxy, scatter2_proxy], ['label1', 'label2'], numpoints = 1)
if decision_fxn:
'''plot decision boundary x-section'''
pass
if twoD: #make 2d plot
plt.scatter(data.T[0],data.T[1])
if decision_fxn:
'''plot decision boundary x-section'''
pass
plt.show()
def scatterRegression():
pass
if __name__ == '__main__':
pass