<jupyter_start><jupyter_text>Implementing activation functions with numpy  Sigmoid<jupyter_code>x = np.arange(-10,10,0.1)
z = 1/(1 + np.exp(-x))

plt.figure(figsize=(20, 10))
plt.plot(x, z, label = 'sigmoid function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Tanh<jupyter_code>x = np.arange(-10,10,0.1)
z = (np.exp(x) - np.exp(-x))/(np.exp(x) + np.exp(-x))

plt.figure(figsize=(20, 10))
plt.plot(x, z, label = 'Tanh function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Relu<jupyter_code>x = np.arange(-10,10,0.1)
z = np.maximum(0, x)

plt.figure(figsize=(20, 10))
plt.plot(x, z, label = 'ReLU function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Leaky ReLU<jupyter_code>x = np.arange(-10,10,0.1)
z = np.maximum(0.1*x, x)

plt.figure(figsize=(20, 10))
plt.plot(x, z, label = 'LReLU function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>ELU<jupyter_code>x1 = np.arange(-10,0,0.1)
x2 = np.arange(0,10,0.1)
alpha = 1.67326324

z1 = alpha * (np.exp(x1) - 1)
z2 = x2

plt.figure(figsize=(20, 10))
plt.plot(np.append(x1, x2), np.append(z1, z2), label = 'ELU function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>SELU<jupyter_code>x1 = np.arange(-10,0,0.1)
x2 = np.arange(0,10,0.1)
alpha = 1.67326324
scale = 1.05070098

z1 = scale * alpha * (np.exp(x1) - 1)
z2 = scale * x2

plt.figure(figsize=(20, 10))
plt.plot(np.append(x1, x2), np.append(z1, z2), label = 'SELU function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Swish<jupyter_code>x = np.arange(-10,10,0.1)
z = x * (1/(1 + np.exp(-x)))

plt.figure(figsize=(20, 10))
plt.plot(x, z, label = 'Swish function', lw=5)
plt.axvline(lw=0.5, c='black')
plt.axhline(lw=0.5, c='black')
plt.box(on=None)
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Chapter 11<jupyter_code>import numpy as np
import tensorflow as tf
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
import pandas as pd
X,y = load_iris(return_X_y=True)
y = pd.get_dummies(y).values
y
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1)
X_train, X_valid, y_train, y_valid = train_test_split(X_train, y_train, test_size=0.2)
model = tf.keras.models.Sequential([
    tf.keras.layers.Dense(10, activation="relu", input_shape=X_train.shape[1:]),
    tf.keras.layers.Dense(10, kernel_initializer="he_normal"),
    tf.keras.layers.LeakyReLU(alpha=0.2),
    tf.keras.layers.Dense(10, activation="selu", kernel_initializer="lecun_normal"),
    tf.keras.layers.Dense(3, activation="softmax")
])


model.compile(loss="categorical_crossentropy", optimizer="sgd", metrics=["accuracy"])

history = model.fit(X_train, y_train, epochs=20, validation_data=(X_valid, y_valid))
model.summary()
train, test  = tf.keras.datasets.mnist.load_data()
X_train, y_train = train
X_test, y_test = test
model2 = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=[28, 28]),
    tf.keras.layers.BatchNormalization(),
    tf.keras.layers.Dense(300, activation="elu", kernel_initializer="he_normal"),
    tf.keras.layers.BatchNormalization(),
    tf.keras.layers.Dense(100, activation="elu", kernel_initializer="he_normal"),
    tf.keras.layers.BatchNormalization(),
    tf.keras.layers.Dense(10, activation="softmax")
])
model2.summary()
[(var.name, var.trainable) for var in model2.layers[1].variables]
[(var.name, var.trainable) for var in model2.layers[2].variables]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1949404761904762, 'fraction_numerical': 0.05084325396825397, 'mean_word_length': 6.227598566308243, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '29201', 'license': 'MIT', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1798, 'n_words': 263, 'path': 'practice/books/Hands On ML with scikit and TF - Aurelien Geron/chapter11/Chapter11.ipynb', 'repo_name': 'ItamarRocha/introduction-to-AI', 'size': '4032'}