Réseaux de neurones#

Réseaux de neurones avec scikit-learn.

[1]:
%matplotlib inline
[2]:
from sklearn.linear_model import Perceptron

X = [[0.0, 0.0], [1.0, 1.0]]
y = [0, 1]
clf = Perceptron()
clf.fit(X, y)
[2]:
Perceptron(alpha=0.0001, class_weight=None, eta0=1.0, fit_intercept=True,
      n_iter=5, n_jobs=1, penalty=None, random_state=0, shuffle=True,
      verbose=0, warm_start=False)
[3]:
import matplotlib.pyplot as plt
import numpy


def softmax(x):
    return 1.0 / (1 + numpy.exp(-x))


def dsoftmax(x):
    t = numpy.exp(-x)
    return t / (1 + t) ** 2


x = numpy.arange(-10, 10, 0.1)
y = softmax(x)
dy = dsoftmax(x)
fig, ax = plt.subplots(1, 1)
ax.plot(x, y, label="softmax")
ax.plot(x, dy, label="dérivée")
ax.set_ylim([-0.1, 1.1])
ax.plot([-5, -5], [-0.1, 1.1], "r")
ax.plot([5, 5], [-0.1, 1.1], "r")
ax.legend(loc=2)
[3]:
<matplotlib.legend.Legend at 0x1b651aeacf8>
../../_images/notebooks_ml_reseau_neurones_3_1.png
[4]:
x
[4]:
array([ -1.00000000e+01,  -9.90000000e+00,  -9.80000000e+00,
        -9.70000000e+00,  -9.60000000e+00,  -9.50000000e+00,
        -9.40000000e+00,  -9.30000000e+00,  -9.20000000e+00,
        -9.10000000e+00,  -9.00000000e+00,  -8.90000000e+00,
        -8.80000000e+00,  -8.70000000e+00,  -8.60000000e+00,
        -8.50000000e+00,  -8.40000000e+00,  -8.30000000e+00,
        -8.20000000e+00,  -8.10000000e+00,  -8.00000000e+00,
        -7.90000000e+00,  -7.80000000e+00,  -7.70000000e+00,
        -7.60000000e+00,  -7.50000000e+00,  -7.40000000e+00,
        -7.30000000e+00,  -7.20000000e+00,  -7.10000000e+00,
        -7.00000000e+00,  -6.90000000e+00,  -6.80000000e+00,
        -6.70000000e+00,  -6.60000000e+00,  -6.50000000e+00,
        -6.40000000e+00,  -6.30000000e+00,  -6.20000000e+00,
        -6.10000000e+00,  -6.00000000e+00,  -5.90000000e+00,
        -5.80000000e+00,  -5.70000000e+00,  -5.60000000e+00,
        -5.50000000e+00,  -5.40000000e+00,  -5.30000000e+00,
        -5.20000000e+00,  -5.10000000e+00,  -5.00000000e+00,
        -4.90000000e+00,  -4.80000000e+00,  -4.70000000e+00,
        -4.60000000e+00,  -4.50000000e+00,  -4.40000000e+00,
        -4.30000000e+00,  -4.20000000e+00,  -4.10000000e+00,
        -4.00000000e+00,  -3.90000000e+00,  -3.80000000e+00,
        -3.70000000e+00,  -3.60000000e+00,  -3.50000000e+00,
        -3.40000000e+00,  -3.30000000e+00,  -3.20000000e+00,
        -3.10000000e+00,  -3.00000000e+00,  -2.90000000e+00,
        -2.80000000e+00,  -2.70000000e+00,  -2.60000000e+00,
        -2.50000000e+00,  -2.40000000e+00,  -2.30000000e+00,
        -2.20000000e+00,  -2.10000000e+00,  -2.00000000e+00,
        -1.90000000e+00,  -1.80000000e+00,  -1.70000000e+00,
        -1.60000000e+00,  -1.50000000e+00,  -1.40000000e+00,
        -1.30000000e+00,  -1.20000000e+00,  -1.10000000e+00,
        -1.00000000e+00,  -9.00000000e-01,  -8.00000000e-01,
        -7.00000000e-01,  -6.00000000e-01,  -5.00000000e-01,
        -4.00000000e-01,  -3.00000000e-01,  -2.00000000e-01,
        -1.00000000e-01,  -3.55271368e-14,   1.00000000e-01,
         2.00000000e-01,   3.00000000e-01,   4.00000000e-01,
         5.00000000e-01,   6.00000000e-01,   7.00000000e-01,
         8.00000000e-01,   9.00000000e-01,   1.00000000e+00,
         1.10000000e+00,   1.20000000e+00,   1.30000000e+00,
         1.40000000e+00,   1.50000000e+00,   1.60000000e+00,
         1.70000000e+00,   1.80000000e+00,   1.90000000e+00,
         2.00000000e+00,   2.10000000e+00,   2.20000000e+00,
         2.30000000e+00,   2.40000000e+00,   2.50000000e+00,
         2.60000000e+00,   2.70000000e+00,   2.80000000e+00,
         2.90000000e+00,   3.00000000e+00,   3.10000000e+00,
         3.20000000e+00,   3.30000000e+00,   3.40000000e+00,
         3.50000000e+00,   3.60000000e+00,   3.70000000e+00,
         3.80000000e+00,   3.90000000e+00,   4.00000000e+00,
         4.10000000e+00,   4.20000000e+00,   4.30000000e+00,
         4.40000000e+00,   4.50000000e+00,   4.60000000e+00,
         4.70000000e+00,   4.80000000e+00,   4.90000000e+00,
         5.00000000e+00,   5.10000000e+00,   5.20000000e+00,
         5.30000000e+00,   5.40000000e+00,   5.50000000e+00,
         5.60000000e+00,   5.70000000e+00,   5.80000000e+00,
         5.90000000e+00,   6.00000000e+00,   6.10000000e+00,
         6.20000000e+00,   6.30000000e+00,   6.40000000e+00,
         6.50000000e+00,   6.60000000e+00,   6.70000000e+00,
         6.80000000e+00,   6.90000000e+00,   7.00000000e+00,
         7.10000000e+00,   7.20000000e+00,   7.30000000e+00,
         7.40000000e+00,   7.50000000e+00,   7.60000000e+00,
         7.70000000e+00,   7.80000000e+00,   7.90000000e+00,
         8.00000000e+00,   8.10000000e+00,   8.20000000e+00,
         8.30000000e+00,   8.40000000e+00,   8.50000000e+00,
         8.60000000e+00,   8.70000000e+00,   8.80000000e+00,
         8.90000000e+00,   9.00000000e+00,   9.10000000e+00,
         9.20000000e+00,   9.30000000e+00,   9.40000000e+00,
         9.50000000e+00,   9.60000000e+00,   9.70000000e+00,
         9.80000000e+00,   9.90000000e+00])
[5]: