<jupyter_start><jupyter_text>***Perceptron Model**** A single-layer perceptron is the basic unit of a neural network. A perceptron consists of input values, weights and a bias, a weighted sum and activation function.<jupyter_code>#importing All Required Libraries
import tensorflow as tf
import numpy as np
import pandas as pd
from keras.models import Sequential
from keras.layers import Dense
from tensorflow import keras
import matplotlib.pyplot as plt
# Reading from CSV Dataset file.
dataset = pd.read_csv('CO2_dataog.csv')

print(dataset)
# Assigning the values to two variables X & Y using List Slicing
X = dataset.iloc[:,:-1].values
Y = dataset.iloc[:,-1].values

print(X)
print(Y)
# Defining a single layer/ single Neuron Model
model = tf.keras.Sequential([keras.layers.Dense(units=3, activation='relu', input_shape=[1])])
model.add(Dense(1))
print(model.summary())
tf.keras.utils.plot_model(
    model,
    to_file="model.png",
    show_shapes=True,
    show_dtype=True,
    show_layer_names=True,
    rankdir="TB",
    expand_nested=False,
    dpi=96,
)
# Defining the model evaluation for backpropogation
model.compile(optimizer='sgd', loss='mean_squared_error')<jupyter_output><empty_output><jupyter_text>* Backpropagation, short for "backward propagation of errors," is an algorithm for supervised learning of artificial neural networks using gradient descent. Here we are using sgd as the optimizer.* SGD-Stochastic Gradient Descent (SGD) is a simple yet very efficient approach to fitting. It find the model parameters that correspond to the best fit between predicted and actual outputs. * In an artificial neural network and an error function, the method calculates the gradient of the error function with respect to the neural network's weights.* Loss is calculated as mean squared error.(Which should reduce with each epoch)<jupyter_code># Training the model in cycles or iterations both forwards & backwards on the Neural Network.
run_model = model.fit(X,Y, epochs=500)<jupyter_output>Epoch 1/500
5/5 [==============================] - 0s 3ms/step - loss: 70396.5938
Epoch 2/500
5/5 [==============================] - 0s 3ms/step - loss: 57548.2812
Epoch 3/500
5/5 [==============================] - 0s 2ms/step - loss: 47619.3203
Epoch 4/500
5/5 [==============================] - 0s 4ms/step - loss: 39508.5078
Epoch 5/500
5/5 [==============================] - 0s 4ms/step - loss: 32934.5039
Epoch 6/500
5/5 [==============================] - 0s 3ms/step - loss: 27543.0527
Epoch 7/500
5/5 [==============================] - 0s 4ms/step - loss: 23144.6914
Epoch 8/500
5/5 [==============================] - 0s 3ms/step - loss: 19556.9746
Epoch 9/500
5/5 [==============================] - 0s 2ms/step - loss: 16617.4004
Epoch 10/500
5/5 [==============================] - 0s 3ms/step - loss: 14225.8184
Epoch 11/500
5/5 [==============================] - 0s 4ms/step - loss: 12245.2764
Epoch 12/500
5/5 [==============================] - 0s 4ms/step - loss: 10627.7705
Epoch 13/500
[...]<jupyter_text>Loss here is high because data in X & Y is not in relation: y =(x/2) - 4<jupyter_code>print(model.predict([112.0]))
# List all data present in history(All The Intermediate Values Gained during each iteration.)
print(run_model.history.keys())
# Visualizing History for Accuracy
plt.plot(run_model.history['loss'])
plt.title('Model Loss v/s Epochs')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2028397565922921, 'fraction_numerical': 0.06635757751376413, 'mean_word_length': 5.098939929328622, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '601318', 'license': 'MIT', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1068, 'n_words': 353, 'path': 'Neural_Network(Perceptron_Model).ipynb', 'repo_name': 'Prathamesh-Shanbhag/MLDLS2021', 'size': '3451'}