<jupyter_start><jupyter_text>Implementation des Réseaux de Ne<NAME><jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs<jupyter_output><empty_output><jupyter_text>Création du Dataset<jupyter_code>X, y = make_blobs(n_samples=100, n_features=2, centers=2, random_state=0)
y = y.reshape((y.shape[0], 1))

print('dimensions de X:', X.shape)
print('dimensions de y:', y.shape)

plt.scatter(X[:,0], X[:, 1], c=y, cmap='summer')
plt.show()<jupyter_output>dimensions de X: (100, 2)
dimensions de y: (100, 1)<jupyter_text>Création de la fonction d'initialisation![image](84.png)<jupyter_code>def initialisation(X):
    W = np.random.randn(X.shape[1], 1)
    b = np.random.randn(1)
    return (W, b)<jupyter_output><empty_output><jupyter_text>Testons la Fonction d'Initialisation<jupyter_code>w, b = initialisation(X)
print(f'La taille de w: {w.shape}')
print(f'La taille de b: {b.shape}')

print(f'w: {w}\nb:{b}')<jupyter_output>La taille de w: (2, 1)
La taille de b: (1,)
w: [[0.15972912]
 [0.88707996]]
b:[1.7866817]<jupyter_text>Création du Modèle![image](model.png)  Création de la Fonction Sigmoïd<jupyter_code>def sigmoid(z):
    return 1 / (1+np.exp(-z))
def model(X, W, b):
    Z = X.dot(W) + b
    A = 1 / (1 + np.exp(-Z))
    return A<jupyter_output><empty_output><jupyter_text>Testons le Modèle<jupyter_code>A = model(X, w, b)
print(f'Shape de A: {A.shape}')<jupyter_output>Shape de A: (100, 1)<jupyter_text>La Fonction Coût de Notre Modèle![image](fonction_cout.png)<jupyter_code>def log_loss(A, y):
    return 1 / len(y) * np.sum(-y * np.log(A) - (1 - y) * np.log(1 - A))
loss = log_loss(A, y)
loss<jupyter_output><empty_output><jupyter_text>Les Gradients de Notre Modèle![image](gradients.png)<jupyter_code>def gradients(A, X, y):
    dW = 1 / len(y) * np.dot(X.T, A - y)
    db = 1 / len(y) * np.sum(A - y)
    return (dW, db)<jupyter_output><empty_output><jupyter_text>Testons les Gradients<jupyter_code>dw, db = gradients(X, A, y)
print(f'Shape de dw: {dw.shape}\ndb: {db}')<jupyter_output>Shape de dw: (1, 2)
db: 3.215940495699665<jupyter_text>Mise à Jour des Gradients![image](update.png)<jupyter_code>def update(dW, db, W, b, learning_rate):
    W = W - learning_rate * dW
    b = b - learning_rate * db
    return (W, b)<jupyter_output><empty_output><jupyter_text>Testons la Mise à Jour des Gradients<jupyter_code>update(dw, db, w, b, 0.05)<jupyter_output><empty_output><jupyter_text>Entrainement du Modèle![image](train_cnn.png)<jupyter_code>from sklearn.metrics import accuracy_score
def predict(X, W, b):
    A = model(X, W, b)
    # print(A)
    return A >= 0.5
 def artificial_neuron(X, y, learning_rate = 0.1, n_iter = 100):
    # initialisation W, b
    W, b = initialisation(X)

    Loss = []

    for i in range(n_iter):
        A = model(X, W, b)
        Loss.append(log_loss(A, y))
        dW, db = gradients(A, X, y)
        W, b = update(dW, db, W, b, learning_rate)

    y_pred = predict(X, W, b)
    print(accuracy_score(y, y_pred))

    plt.plot(Loss)
    plt.show()

    return (W, b)<jupyter_output><empty_output><jupyter_text>Testons Notre Modèle<jupyter_code>W, b = artificial_neuron(X, y)<jupyter_output>0.86
{'fraction_non_alphanumeric': 0.16066395239586595, 'fraction_numerical': 0.030065768869401818, 'mean_word_length': 4.8713235294117645, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '583814', 'license': 'MIT', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1368, 'n_words': 287, 'path': 'python/reseau_de_neurone_artificiel.ipynb', 'repo_name': 'camara94/formation-deep-learning', 'size': '3203'}