Skip to content
Snippets Groups Projects
Commit 74a4732e authored by Antoine Lucas's avatar Antoine Lucas ⛷️
Browse files

Replace libLab3_Lidar.py

parent 98c6e5df
Branches main
No related tags found
No related merge requests found
...@@ -418,13 +418,15 @@ def plot_contours_compare(X, y, X_train , y_train, X_test, y_test, classifiers, ...@@ -418,13 +418,15 @@ def plot_contours_compare(X, y, X_train , y_train, X_test, y_test, classifiers,
### ###
def plot_contours(X, y, classifier, resolution=0.02): def plot_contours(X, y, classifier, resolution=0.02,level=50):
""" """
Function to plot single classifier contours Function to plot single classifier contours
---- ----
INPUT: INPUT:
@X: Numpy array with data @X: Numpy array with data, e.g. X.to_numpy()
@y: Numpy array with labels @y: Numpy array with labels
@resolution: resolution of the contour plot
@level: depth of the intersection of hyperplanes
---- ----
OUTPUT: OUTPUT:
...@@ -445,26 +447,48 @@ def plot_contours(X, y, classifier, resolution=0.02): ...@@ -445,26 +447,48 @@ def plot_contours(X, y, classifier, resolution=0.02):
from matplotlib import colors from matplotlib import colors
# setup marker generator and color map # setup marker generator and color map
markers = ('s', 'x', 'o', '^', 'v') # markers = ('s', 'x', 'o', '^', 'v')
colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan') # colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
cmap = ListedColormap(colors[:len(np.unique(y))]) # cmap = ListedColormap(colors[:len(np.unique(y))])
C = X[:, 0:2] # C = X[:, 0:2]
# plot the decision surface # # plot the decision surface
x1_min, x1_max = C[:, 0].min() - 1, C[:, 0].max() + 1 # x1_min, x1_max = C[:, 0].min() - 1, C[:, 0].max() + 1
x2_min, x2_max = C[:, 1].min() - 1, C[:, 1].max() + 1 # x2_min, x2_max = C[:, 1].min() - 1, C[:, 1].max() + 1
xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution), # xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution),
np.arange(x2_min, x2_max, resolution)) # np.arange(x2_min, x2_max, resolution))
Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T) # Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T)
Z = Z.reshape(xx1.shape) # Z = Z.reshape(xx1.shape)
plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap) # plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap)
plt.xlim(xx1.min(), xx1.max()) # plt.xlim(xx1.min(), xx1.max())
plt.ylim(xx2.min(), xx2.max()) # plt.ylim(xx2.min(), xx2.max())
for idx, cl in enumerate(np.unique(y)): # for idx, cl in enumerate(np.unique(y)):
plt.scatter(x=C[y == cl, 0], y=C[y == cl, 1], # plt.scatter(x=C[y == cl, 0], y=C[y == cl, 1],
alpha=0.8, c=cmap(idx), # alpha=0.8, c=cmap(idx),
marker=markers[idx], label=cl) # marker=markers[idx], label=cl)
x_values = np.linspace(0, 1, np.int32(1/resolution))
x_mesh = np.meshgrid(x_values, x_values)
x_plane = np.array([x.ravel() for x in x_mesh])
x_projection = level * X[:, 3].mean() * x_plane
x_input = np.vstack((x_plane, x_projection))
y_boundary = classifier.predict(x_input.T)
plt.figure()
plt.contourf(
x_mesh[0],
x_mesh[1],
y_boundary.reshape(x_mesh[0].shape),
levels=[0.5, 1.5, 2.5],
zorder=0,
)
plt.scatter(
X[:, 0],
X[:, 1],
c=y,
cmap="tab20",
zorder=2,
)
def plot_3dcladd(dx,dy,dz,y,density=1): def plot_3dcladd(dx,dy,dz,y,density=1):
...@@ -516,5 +540,4 @@ def plot_confMat(cnf_matrix,ClaName): ...@@ -516,5 +540,4 @@ def plot_confMat(cnf_matrix,ClaName):
plt.title("Confusion matrix using "+ClaName, y=1.1); plt.title("Confusion matrix using "+ClaName, y=1.1);
plt.ylabel('Actual label'); plt.ylabel('Actual label');
plt.xlabel('Predicted label'); plt.xlabel('Predicted label');
plt.show() plt.show()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment