IAC / TP 1 - Perceptron

Ce TP est destiné à l'étude d'un perceptron pour la classification binaire linéaire.

Prerequisite

MatPlotLib configuration

We're using the Python language and the MatPlotLib library. The MatPlotLib library can be installed with the command:

pip install matplotlib

or for conda installation:

conda install -c conda-forge matplotlib

Using MatPlotLib within a Python program need to add the import:

import matplotlib.pyplot as plt

The MatPlotLib library displays geometric rendering in an independent interactive window. Depending on the Python environment, this window may be rendered as a frozen image, preventing user interaction. To correct this problem, here are solutions according to the underlying Python environment.

Jupyter Notebook

Execute following code within the Jupyter Notebook:

%matplotlib qt

PyCharm

Go to Settings / Tool / Python Plot and uncheck the option Show plots in tool windows.

Spyder

Go to Tools / Preferences / IPython console / Graphics / Backend:Inline and change "Inline" to "Automatic". Click OK button and restart the IDE.

MatPlotLib Drawing functions

MatPlotLib enable to display various primitives and shapes. In this work we focus on drawing points and lines. 

Point

The drawing of a point with $(x,\ y,\ z)$ coordinates is made by the code:

plt.plot(x, y, z, marker='m', color='c')

where:

  • m is the marker (shape) to use for displaying the point ('o' for round, '+' for right cross, 'x' for cross)
  • c is the point color ('red', 'greed', 'blue', …)

Line

The drawing of a line between two points $(x_{1}, y_{1}, z_{1})$ and $(x_{2}, y_{2}, z_{2})$ is made by the code:

plt.plot([x1 , x2],[ y1, y2],[ z1, z2], color='c', linestyle='s')

where:

  • c is the line color ('red', 'greed', 'blue', ...)
  • s is the line style ('solid', 'dashed', 'dashdot' or 'dotted')