<jupyter_start><jupyter_text>Preparation  Install Requirement<jupyter_code>!pip install -q tensorflow-gpu==2.0.0-beta1
!pip install -qU watermark<jupyter_output><empty_output><jupyter_text>Custom Matplotlib Style<jupyter_code>mpl_style = "https://gist.githubusercontent.com/m3hrdadfi/af8aca01094afb7d3e5b46de9ad8d509/raw/871ec5d721a3b438c3c896718ea4aafc91ea9744/gadfly.mplstyle"
!wget -q $mpl_style -O /root/.config/matplotlib/matplotlibrc<jupyter_output><empty_output><jupyter_text>General Paramas A random seed is a number used to initialize a pseudorandom number generator. For a seed to be used in a pseudorandom number generator, it does not need to be random<jupyter_code>RANDOM_SEED = 141<jupyter_output><empty_output><jupyter_text>Import requried packages<jupyter_code>import tensorflow as tf

import requests
import numpy as np
import pandas as pd

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import classification_report, confusion_matrix

import matplotlib as mpl
import matplotlib.pyplot as plt

from datetime import datetime


%matplotlib inline<jupyter_output><empty_output><jupyter_text>IRIS DatasetData Set Information:This is perhaps the best known database to be found in the pattern recognition literature. Fisher's paper is a classic in the field and is referenced frequently to this day. (See Duda & Hart, for example.) The data set contains 3 classes of 50 instances each, where each class refers to a type of iris plant. One class is linearly separable from the other 2; the latter are NOT linearly separable from each other. Predicted attribute: class of iris plant. This is an exceedingly simple domain. This data differs from the data presented in Fishers article (identified by <NAME>, spchadwick '@' espeedaz.net ). The 35th sample should be: 4.9,3.1,1.5,0.2,"Iris-setosa" where the error is in the fourth feature. The 38th sample: 4.9,3.6,1.4,0.1,"Iris-setosa" where the errors are in the second and third features.Attribute Information:1. sepal length in cm 2. sepal width in cm 3. petal length in cm 4. petal width in cm 5. class:     - Iris Setosa     - Iris Versicolour     - Iris Virginica<jupyter_code>def load_iris():
    download_link = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
    
    r = requests.get(download_link, allow_redirects=True)
    
    with open('./iris.csv', 'wb') as f:
        f.write(r.content)
    
    iris = pd.read_csv('./iris.csv', header=None)
    
    names = list(iris[iris.columns[-1]].unique())
    iris[iris.columns[-1]] = iris[iris.columns[-1]].apply(lambda x: names.index(x))
    
    x = iris[iris.columns[:-1]].values
    y = iris[iris.columns[-1]].values
    
    x_train, xt, y_train, yt = train_test_split(x, y, test_size=0.3, random_state=RANDOM_SEED)
    x_valid, x_test, y_valid, y_test = train_test_split(xt, yt, test_size=0.6, random_state=RANDOM_SEED)
    
    names = {i: name for i, name in enumerate(names)}
    features = ['sepal length', 'sepal width', 'petal length', 'petal width',]
    
    return (x_train, y_train), (x_valid, y_valid), (x_test, y_test), names, features<jupyter_output><empty_output><jupyter_text>Load the data<jupyter_code>(x_train, y_train), (x_valid, y_valid), (x_test, y_test), classes, features = load_iris()


y_train_c = tf.keras.utils.to_categorical(y_train)
y_valid_c = tf.keras.utils.to_categorical(y_valid)
y_test_c = tf.keras.utils.to_categorical(y_test)

print('Train set: \tx=> %s,\t y=> %s,\t y=> %s' % (x_train.shape, y_train.shape, y_train_c.shape))
print('Valid set: \tx=> %s,\t y=> %s,\t y=> %s' % (x_valid.shape, y_valid.shape, y_valid_c.shape))
print('Test set: \tx=> %s,\t y=> %s,\t y=> %s' % (x_test.shape, y_test.shape, y_test_c.shape))
print()
print('Features:\tc=> %s' % (features))
print('Classes:\tc=> %s' % (classes))<jupyter_output>Train set: 	x=> (105, 4),	 y=> (105,),	 y=> (105, 3)
Valid set: 	x=> (18, 4),	 y=> (18,),	 y=> (18, 3)
Test set: 	x=> (27, 4),	 y=> (27,),	 y=> (27, 3)

Features:	c=> ['sepal length', 'sepal width', 'petal length', 'petal width']
Classes:	c=> {0: 'Iris-setosa', 1: 'Iris-versicolor', 2: 'Iris-virginica'}<jupyter_text>Visualize the data<jupyter_code>plt.figure(figsize=(16, 6))
plt.subplot(1, 2, 1)
for i, name in classes.items():
    x_plot = x_train[y_train == i]
    plt.plot(x_plot[:, 0], x_plot[:, 1], linestyle='none', marker='o', label=name)
    
plt.xlabel(features[0])
plt.ylabel(features[1])
plt.axis('equal')
plt.legend();

plt.subplot(1, 2, 2)
for i, name in classes.items():
    x_plot = x_train[y_train == i]
    plt.plot(x_plot[:, 2], x_plot[:, 3], linestyle='none', marker='o', label=name)
    
plt.xlabel(features[2])
plt.ylabel(features[3])
plt.axis('equal')
plt.legend();<jupyter_output><empty_output><jupyter_text>Preprocessing<jupyter_code># Scaler [standard-scaler]
## your code comes here

# Train Fit and Scaled
## your code comes here

# Valid Scaled
## your code comes here

# Test Scaled
## your code comes here

print('Original Train: %s,\t Standard Train: %s' % (x_train[0], x_train_scaled[0]))<jupyter_output><empty_output><jupyter_text>**The answer:**```Original Train: [5.9 3.2 4.8 1.8],	 Standard Train: [0.08807936 0.30907539 0.60380199 0.8074111 ]```  Configure Neural Network Models  Create non-linear model<jupyter_code>def build_model():
    # model architecture comes here, then remove ```model = None``` and enter your code.
    model = None
    
    return model<jupyter_output><empty_output><jupyter_text>Summary of the model<jupyter_code>model = build_model()
model.summary()<jupyter_output><empty_output><jupyter_text>**The answer:**_________________________________________________________________Layer (type)                 Output Shape              Param    =================================================================dense_26 (Dense)             (None, 10)                50        _________________________________________________________________dense_27 (Dense)             (None, 8)                 88        _________________________________________________________________dense_28 (Dense)             (None, 3)                 27        =================================================================Total params: 165Trainable params: 165Non-trainable params: 0_________________________________________________________________  Tensorboard callbacks<jupyter_code>logdir = "logs/scalars/" + datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=logdir)<jupyter_output><empty_output><jupyter_text>Fit non-linear model.<jupyter_code>BATCH_SIZE = 2
EPOCHS = 100
VERBOSE = 1
CALLBACKES = [tensorboard_callback]
# [Fitting] code comes here
# [Fitting Hisoty] code comes here<jupyter_output><empty_output><jupyter_text>**The answer:**```history_list ['loss', 'accuracy', 'val_loss', 'val_accuracy']```  Plotting<jupyter_code># Plot with Sub-Plots come here<jupyter_output><empty_output><jupyter_text>**The answer: must be something like these plots**      Evaluation<jupyter_code># evaluation code comes here<jupyter_output><empty_output><jupyter_text>**The answer: muse be higher than our result**```Loss: 0.199	 Accuracy: 96.30%```  Accuracy of the predicted values<jupyter_code># reports come here<jupyter_output><empty_output><jupyter_text>**The answer:**Classification report:              precision    recall  f1-score   support           0       1.00      1.00      1.00         7           1       0.89      1.00      0.94         8           2       1.00      0.92      0.96        12    accuracy                           0.96        27   macro avg       0.96      0.97      0.97        27weighted avg       0.97      0.96      0.96        27Confusion matrix:[[ 7  0  0] [ 0  8  0] [ 0  1 11]]<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14035759897828864, 'fraction_numerical': 0.03665389527458493, 'mean_word_length': 4.3636986301369864, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 87, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '91275', 'license': 'MIT', 'n_tokens_mistral': 2854, 'n_tokens_neox': 2659, 'n_words': 680, 'path': 'ws-dl-tf2-s1/assignments/01/Assignment.ipynb', 'repo_name': 'i-ml/tf2-workshop', 'size': '7838'}