-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotModel.py
More file actions
44 lines (35 loc) · 1.45 KB
/
plotModel.py
File metadata and controls
44 lines (35 loc) · 1.45 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
import Clasificador
from matplotlib.colors import ListedColormap
import numpy as np
import matplotlib.pyplot as plt
# Autor Luis Lago y Manuel Sanchez Montanes
# Modificada por Gonzalo
def plotModel(x,y,clase,clf,title,diccionarios):
x_min, x_max = x.min() - .2, x.max() + .2
y_min, y_max = y.min() - .2, y.max() + .2
hx = (x_max - x_min)/100.
hy = (y_max - y_min)/100.
xx, yy = np.meshgrid(np.arange(x_min, x_max, hx), np.arange(y_min, y_max, hy))
if isinstance(clf, Clasificador.Clasificador):
z = clf.clasifica(np.c_[xx.ravel(), yy.ravel(),np.zeros(len(yy.ravel()))], [False, False, True], diccionarios)
elif hasattr(clf, "decision_function"):
z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
else:
z = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1]
z = z.reshape(xx.shape)
cm = plt.cm.RdBu
cm_bright = ListedColormap(['#FF0000', '#0000FF'])
#ax = plt.subplot(1, 1, 1)
plt.contourf(xx, yy, z, cmap=cm, alpha=.8)
plt.contour(xx, yy, z, [0.5], linewidths=[1.5], colors=['k'])
if clase is not None:
plt.scatter(x[clase==0], y[clase==0], c='#FF0000')
plt.scatter(x[clase==1], y[clase==1], c='#0000FF')
else:
plt.plot(x,y,'g', linewidth=3)
plt.gca().set_xlim(xx.min(), xx.max())
plt.gca().set_ylim(yy.min(), yy.max())
plt.grid(True)
plt.xlabel("X")
plt.ylabel("Y")
plt.title(title)