<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sahil-Adivarekar on Medium]]></title>
        <description><![CDATA[Stories by Sahil-Adivarekar on Medium]]></description>
        <link>https://medium.com/@sahiladivarekar99?source=rss-1bd911ed6d93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Sahil-Adivarekar on Medium</title>
            <link>https://medium.com/@sahiladivarekar99?source=rss-1bd911ed6d93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:56:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sahiladivarekar99/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[VGG16 CNN Architecture]]></title>
            <link>https://medium.com/@sahiladivarekar99/vgg16-cnn-architecture-b707331f20b4?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/b707331f20b4</guid>
            <category><![CDATA[ann]]></category>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[mls]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[vgg16]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Sun, 08 Jan 2023 08:56:04 GMT</pubDate>
            <atom:updated>2023-01-08T08:56:04.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TKD9YTQj-BgmwJAu9kEkw.png" /><figcaption>VGG16 CNN Architecture</figcaption></figure><p>VGG16 is a convolutional neural network model trained on the ImageNet dataset. This model and its variants are widely used for image classification tasks. The “VGG” in the name stands for Visual Geometry Group, which is the group at Oxford that developed the model.</p><p>The VGG16 model consists of 16 layers, including 13 convolutional layers and 3 fully connected layers. The convolutional layers are arranged in a series of convolutional blocks, where each block consists of a set of convolutional layers, followed by a max pooling layer. The input to the model is a 224x224x3 image, and the output is a 1000-dimensional vector representing the class probabilities for the input image.</p><p>One of the key features of the VGG16 model is the use of small convolutional filters, with a size of 3x3 pixels. This is in contrast to many other models that use larger filters, such as 7x7 or even 11x11 pixels. The use of small filters allows the model to learn more fine-grained features, at the cost of requiring more computation.</p><p>One of the key benefits of the VGG16 model is its simplicity. The model is relatively straightforward, with a linear sequence of layers, and uses a small number of hyperparameters. This makes the model easy to understand and implement, and reduces the risk of overfitting.</p><p>The VGG16 model was trained on the ImageNet dataset, which is a large dataset consisting of over one million images, labeled with one of 1000 different classes. The model was trained using a variant of stochastic gradient descent called “batch normalization”, which has been shown to be effective at training deep neural networks.</p><p>In addition to being widely used for image classification, the VGG16 model and its variants have also been used for other tasks such as object detection and semantic segmentation.</p><p>One interesting aspect of the VGG16 model is the use of “skip connections”, which are connections that bypass one or more layers. These skip connections can help to improve the performance of the model by allowing the gradients to flow more easily through the network, which can help to prevent the vanishing gradient problem.</p><p>Another notable feature of the VGG16 model is the use of “max pooling” layers, which are used to down-sample the spatial dimensions of the feature maps. The max pooling layers are used to reduce the dimensionality of the feature maps, which can help to reduce the computational complexity of the model, as well as to introduce some degree of translation invariance.</p><p>Overall, the VGG16 model has been highly influential in the field of computer vision, and has contributed to the development of many other successful models. It is still widely used today, although it has been surpassed by more modern models that have been developed in recent years. The model has been widely influential, and the design choices made in the model have been adopted by many other models that have been developed since.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b707331f20b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activation Functions in ANN]]></title>
            <link>https://medium.com/@sahiladivarekar99/activation-functions-in-ann-f3a22366c8d0?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3a22366c8d0</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ann]]></category>
            <category><![CDATA[mls]]></category>
            <category><![CDATA[sigmoid-relu-tanh]]></category>
            <category><![CDATA[activation-functions]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Fri, 06 Jan 2023 22:31:43 GMT</pubDate>
            <atom:updated>2023-01-08T19:46:34.386Z</atom:updated>
            <content:encoded><![CDATA[<p>Activation functions are a crucial component of artificial neural networks, which are a type of machine learning model inspired by the structure of the brain. Neural networks consist of layers of interconnected nodes, which process the input data and pass it through the network. Activation functions are used to introduce non-linearity into the model, allowing it to learn and model more complex relationships in the data.</p><p>There are several different types of activation functions, each with its own characteristics and suitability for different types of problems. Some of the most commonly used activation functions include the sigmoid function, the tanh function, and the ReLU (Rectified Linear Unit) function.</p><blockquote>Sigmoid Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*0RlqlTXUEYLQZXGlWPmcVA.png" /><figcaption>Graphical representation of Sigmoid function</figcaption></figure><p>The sigmoid function is a smooth, S-shaped curve that maps any input value to a value between 0 and 1. It is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*2cx0zKctPijbuYcFrDfBRA.png" /></figure><p>where ‘e’ is the base of the natural logarithm (approximately 2.718). The sigmoid function has the property of “squashing” the input values into a range between 0 and 1, which makes it useful for modeling probabilities. It is often used as the activation function for the output layer of a binary classification model, as it can output a probability value. However, the sigmoid function has the drawback of saturating for large positive or negative input values, which can slow down the training process.</p><blockquote>Tanh Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*Hefga2BdQyiBATDRdOYQ4w.png" /><figcaption>Graphical representation of Tanh function</figcaption></figure><p>The tanh function, also known as the hyperbolic tangent function, is similar to the sigmoid function, but it maps the input values to the range -1 to 1. It is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*FYgWtsClRTBw_j7m_OFR2w.png" /></figure><p>The tanh function has a similar “squashing” effect as the sigmoid function, but it is centered around 0 and has a range of -1 to 1. This makes it more suitable for modeling data that is centered around 0 and is symmetrical around the midpoint. It is often used as an activation function in the hidden layers of a neural network.</p><blockquote>ReLU Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*kJmM7tpVyeG5XwmZmSIicw.png" /><figcaption>Graphical representation of ReLU function</figcaption></figure><p>The ReLU (Rectified Linear Unit) function is a simple function that maps all negative input values to 0 and all positive input values to the same value. It is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*e40ssBhqp0wBQM2RqtUgCA.png" /></figure><p>The ReLU function has the advantage of being computationally efficient and does not saturate like the sigmoid or tanh functions. It has been found to be particularly effective in deep learning models and has become a popular choice for activation functions in recent years.</p><p>In conclusion, activation functions are an important component of artificial neural networks, and the choice of which one to use depends on the characteristics of the problem being solved and the desired properties of the model. The sigmoid and tanh functions are suitable for modeling probabilities and data that is centered around 0, while the ReLU function is suitable for deep learning models and has good computational efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3a22366c8d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is ChatGPT?]]></title>
            <link>https://medium.com/@sahiladivarekar99/what-is-chatgpt-2e388a10aca5?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e388a10aca5</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mls]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Thu, 05 Jan 2023 09:09:58 GMT</pubDate>
            <atom:updated>2023-01-05T09:09:58.847Z</atom:updated>
            <content:encoded><![CDATA[<p>GPT (short for “Generative Pre-trained Transformer”) is a type of language model developed by OpenAI. It is a machine learning model that is trained to generate human-like text by predicting the next word in a sequence based on the words that come before it. In other words, given a prompt, GPT can generate a response by predicting the most likely next word, and then continuing to predict subsequent words based on the context.</p><p>GPT is a “transformer” model, which means that it uses self-attention mechanisms to process the input data and generate the output. Self-attention allows the model to weigh the importance of different words in the input, and to take into account the relationships between them when generating the output. This makes it particularly well-suited for tasks such as translation, summarization, and question answering, where the meaning of a word depends on the words around it.</p><p>GPT was originally trained on a dataset of millions of web pages, and has since been fine-tuned on a variety of other tasks. It has shown impressive results in generating coherent and coherent text, and has been used in a variety of natural language processing applications.</p><p>One of the key features of GPT is that it can be fine-tuned on specific tasks by training it on a smaller dataset of labeled examples. For example, it could be fine-tuned on a dataset of customer service conversations, in order to generate more relevant and accurate responses to customer inquiries. This ability to adapt to different tasks allows GPT to be used in a wide range of language applications, from language translation to chatbots.</p><p>Overall, GPT is a powerful tool for natural language processing, and has the potential to revolutionize the way we interact with machines and automate a wide range of language-based tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e388a10aca5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ensemble Techniques]]></title>
            <link>https://medium.com/@sahiladivarekar99/ensemble-techniques-beab8ff803a9?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/beab8ff803a9</guid>
            <category><![CDATA[boosting]]></category>
            <category><![CDATA[ensemble-method]]></category>
            <category><![CDATA[bagging]]></category>
            <category><![CDATA[ensemble-learning]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 18:41:05 GMT</pubDate>
            <atom:updated>2022-12-06T18:41:05.742Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>An ensemble is a machine learning model that combines the prediction of 2 or more models. The models that contribute to ensemble are called ensemble member. They may be of the same type or different types.</p><p>The ensemble member may or may not be trained on the same training data. The ensemble method uses multiple independent similar or different models to derive an output or make some predictions. For example, Random Forest is an ensemble method of multiple decision trees.</p><blockquote>Bagging</blockquote><p>Bagging is a short form for Bootstrapping Aggregating. It is an ensemble technique designed to improve the stability and accuracy if classification algorithms. It reduces bias and variance from the predictive models.</p><p>It involves 3 steps:</p><ol><li>Creating multiple sub-sets: The original dataset is divided into multiple sub-sets by randomly drawing datapoints.</li><li>Building multiple models: Classification models are built for each sub-set. Generally the same model is used for each sub-set</li><li>Combine models: The classification prediction from each classifier is combined using methods like voting and stacking.</li></ol><blockquote>Boosting</blockquote><p>Boosting is an ensemble technique designed to combine several weak classifiers into a strong classifier. Weak classifier are only slightly related to the final classification and strong classifiers are well correlated with the final classification. Boosting is an iterative process and is continued till a sufficiently strong model is found.</p><p>It involves 2 steps:</p><ol><li>Iteratively building models and for each time, assigning weights and correcting errors from the previous models.</li><li>Combining the results from several models to get a strong model via methods like voting and stacking.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beab8ff803a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Are Performance Metrics?]]></title>
            <link>https://medium.com/@sahiladivarekar99/what-are-performance-metrics-b1a4fc3fb8dd?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1a4fc3fb8dd</guid>
            <category><![CDATA[performance-metrics]]></category>
            <category><![CDATA[accuracy]]></category>
            <category><![CDATA[r2-score]]></category>
            <category><![CDATA[roc]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Sat, 26 Nov 2022 12:13:43 GMT</pubDate>
            <atom:updated>2022-11-26T12:13:43.427Z</atom:updated>
            <content:encoded><![CDATA[<p>To evaluate the performance or quality of a model, different metrics are used which are called Performance Metrics or Evaluation Metrics</p><p>These metrics help us to understand how well the model will perform on a given data.</p><p>Most supervised machine learning problem statements are either regression or classification and in each case different performance metrics are used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*eYg-CvyJTMzEZkF9_1qsQQ.png" /></figure><blockquote><strong>Performance Metrics for Regression</strong></blockquote><ul><li><strong>Mean Absolute Error (MAE)</strong>: It is the mean absolute difference between the actual and predicted value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*dS9nSHD8NdD7fnzJ9tUEfA.png" /></figure><ul><li><strong>Mean Square Error (MSE)</strong>: It is the mean squared of the difference between the actual and predicted value. MSE is usually used as if it differential therefore better optimized.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*WqxDoxMuxMnhtD3KaqP4EQ.png" /></figure><ul><li><strong>R-2 Score (R Squared Score or Coefficient of Determination)</strong>: It is used to compare the model with a baseline constant to understand the performance of the model. The constant baseline is chosen by taking the mean of the data and drawing a line at the mean. The R-2 score is always less than or equal to 1.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*ncBWzh8F4VjeDW9eMFdAvw.png" /></figure><p>The problem with R-2 score is the limitation of the score after increasing the terms. It give misleading information although the model is not improving. Hence we use the concept of Adjusted R-2 Score.</p><ul><li><strong>Adjusted R-2 Score</strong>: It is an improved version of R-2 score and it always shows a lower value than R-2 score. The reason being Adjusted R-2 Score adjusts the values of increasing predicators and shows improvement in case of any real improvement. In the given formula, n indicates number of observations and v indicates the number of independent variables.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*1VSft1ScZKFQe1NS4JiqkA.png" /></figure><blockquote><strong>Performance Metrics for Classification</strong></blockquote><ul><li><strong>Accuracy</strong>: It is the measure of the number of correct predictions to the total number of predictions made.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*h_BoErNT-zodF42pIVHf5w.png" /></figure><ul><li><strong>Confusion Matrix</strong>: It is a tabular comparison between predicted classification and actual classification. The table shown below shows the confusion matrix for class A and class B.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*1DhhuDsRturB5yeu_kNCeQ.png" /></figure><p>Where,</p><p>TP (True Positive): The predicted and actual made both are true</p><p>FP (False Positive): The prediction made is true by in reality the outcome is false</p><p>TN (True Negative): The predicted and actual made both are false</p><p>FN (False Negative): The prediction made is false by in reality the outcome is true</p><ul><li><strong>Precision</strong>: The proportion of positive predictions that are actually correct</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*O-_uWvK1AjJ6RTx9zAFncQ.png" /></figure><ul><li><strong>Recall or Sensitivity</strong>: The proportion of actual positive predictions that are identified incorrectly</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*Z1BFD5wEEtDYZVHsBLFmDQ.png" /></figure><ul><li>F1 — Score: It is the harmonic mean of precision and recall.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*oNYdhcoAItyvltfk2ffe3Q.png" /></figure><ul><li><strong>ROC Curve (Receiver Operating Characteristic)</strong>: It evaluates the performance of a classifier based on the true positive and false positives regardless of other factors such as class distribution and error cost.</li><li><strong>AUC (Area under the Curve)</strong>: It is calculated by measuring the area under the ROC Curve.</li></ul><p>The code below calculates the ROC curve and the calculated AUC.</p><p><strong>Program</strong>:</p><pre>from sklearn.metrics import accuracy_score, confusion_matrix, roc_auc_score, roc_curve<br>import numpy as np<br>import matplotlib.pyplot as plt<br><br>dataset = np.array([<br>    [7,3,7],<br>    [1,2,8],<br>    [3,8,8],<br>    [5,2,9],<br>    [4,4,8],<br>    [2,2,9],<br>    [3,10,8],<br>    [9,2,6],<br>    [6,10,7]<br>])<br>labels = np.array([[1],[1],[0],[1],[1],[0],[0],[1],[1]])<br>def sigmoid_function(x):<br>    return 1/(1+np.exp(-x))<br>def sigmoid_derivative(x):<br>    return sigmoid_function(x) * (1 - sigmoid_function(x))<br>class Layer:<br>    <br>    def __init__(self, input_size, output_size):<br>        self.weights = np.random.rand(input_size,output_size)<br>        <br>    def forward_propagation(self, dataset):<br>        sum_of_product = np.dot(dataset, self.weights)<br>        result = sigmoid_function(sum_of_product)<br>        return result<br>    <br>    def backward_propagation(self,result, label, dataset):<br>        error = result - label<br>        adjustment = error - sigmoid_derivative(result)<br>        updated_weights = np.dot(dataset.T, adjustment)<br>        self.weights = self.weights - updated_weights<br>        return self.weights<br>&quot;&quot;&quot;<br>Output: There are only 3 input parameters (Study, Play and Sleep) and 1 output i.e. Pass/Fail<br>&quot;&quot;&quot;<br>output_layer = Layer(3,1)<br>#Train:<br>for i in range(100):<br>    result = output_layer.forward_propagation(dataset)<br>    weights = output_layer.backward_propagation(result, labels, dataset)<br>    output_layer.weights = weights<br>#Confusion Matrix:<br>pred = []<br>for r in result:<br>    if r&gt;0.5:<br>        pred.append(1)<br>    else:<br>        pred.append(0)<br>pred = np.array(pred)<br><br>def plot_roc_curve(label, pred):<br><br>    fp, tp, thresholds = roc_curve(label, pred)<br>    plt.plot(fp, tp)<br>    plt.xlabel(&#39;False Positive Rate&#39;)<br>    plt.ylabel(&#39;True Positive Rate&#39;)<br><br>plot_roc_curve(labels, pred)<br>print(f&#39;AUC score: {roc_auc_score(labels, pred)}&#39;)</pre><p><strong>Output</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/0*ynSMBPmjoTgkIehG" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1a4fc3fb8dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is CNN?]]></title>
            <link>https://medium.com/@sahiladivarekar99/what-is-cnn-1dbcf01e64a5?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dbcf01e64a5</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[mnist-dataset]]></category>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[convolution-neural-net]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Fri, 21 Oct 2022 17:24:56 GMT</pubDate>
            <atom:updated>2023-01-05T09:05:26.861Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Convolutional Neural Network</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ns0Dt8-FwHB9mlfd" /><figcaption>Convolutional Neural Network</figcaption></figure><p>The Convolutional Neural Network is inspired from the visual cortex of the human brain and hence its basic architecture is similar to that of the neurons in the human brain.</p><p>It is an artificial neural network with convolution input layers which act as feature extractors directly from the input image. Thus it can perform both feature extraction and classification.</p><p>Convolutional Neural Networks are based on three main components: Convolutional Layers, Pooling Layers and Activation Functions — most common is Rectified Linear Units (ReLU). Various architectures follow a variety of arrangement of layers and other parameters.</p><h4><strong>Convolution Layer:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ILiLliLNn4Rbt9S9" /><figcaption>Working of Convolutional Layer</figcaption></figure><p>Convolutional layer is the basic entity used in the convolutional neural networks.</p><p>The process of convolution involves the operation of filters on the input, resulting in an activation which eventually results in a map of activation called feature map. This feature map is used to determine the location of a detected feature and its strength in the input.</p><p>As shown in the figure above, convolution is the operation where the set of weights (filter/ kernel) are multiplied with input. After each convolution operation, Rectified Linear Unit activation function is applied to the feature map to add non-linearity to the model.</p><h4><strong>Pooling:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/0*upAu5hgkpbiMY2cT" /><figcaption>Working of Max-Pooling</figcaption></figure><p>Pooling layer is used for reducing the dimensions of the feature map, thus reducing the number of parameters in the input.</p><p>There are two main type of pooling:</p><ol><li>Max pooling: The filter chooses the pixel with the maximum value within the boundary to the output. The figure above shows the implementation of max-pooling.</li><li>Average pooling: The filter calculates the average value within the receptive field and sends it to the output array.</li></ol><h4><strong>Fully Connected Layer:</strong></h4><p>In Fully Connected Layer, each neuron of the layer is connected to each neuron of the next layer. This layer performs the classification based on the features extracted from the previous layers and filters used. The fully connected layer uses “<strong>Softmax</strong>” activation function to classify the input based on the probability between 0 to 1.</p><h3>IMPLEMENTATION:</h3><h4>Dataset used:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/0*Pzv6AsRj9BzimMst" /><figcaption>Number 0 of MNIST dataset</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/0*D-QMzBikMcP9doSp" /><figcaption>Number 5 of MNIST dataset</figcaption></figure><p>The MNIST (Modified National Institute of Standards and Technology) dataset is a collection of handwritten digits with training set size as 60,000 and testing set size as 10,000. It is a subset of a larger set available from NIST. The digits are size-normalized and centered in a fixed-size image.</p><h4>Program and Output:</h4><pre>from keras.datasets import mnist</pre><pre>from keras.models import Sequential, Model</pre><pre>from keras.layers import Conv2D, MaxPool2D, Dense, Flatten</pre><pre>from skimage.io import imshow</pre><pre>from sklearn.metrics import confusion_matrix</pre><pre>import numpy as np</pre><pre>import matplotlib.pyplot as plt</pre><pre>import seaborn as sns</pre><pre>(X_train, y_train), (X_test, y_test) = mnist.load_data()</pre><pre>img_shape = list(X_train[0].shape)</pre><pre>print(&quot;Shape of images:&quot;, img_shape)</pre><pre>## Shape of images: [28, 28]</pre><pre>def create_model():<br># create_model starts</pre><pre>model = Sequential()</pre><pre>model.add(Conv2D(filters = 64, kernel_size = (3,3),padding = &#39;same&#39;, input_shape = img_shape + [1], activation = &quot;relu&quot;))</pre><pre>model.add(Conv2D(filters = 64, kernel_size = (3,3), padding = &#39;same&#39;, activation = &quot;relu&quot;))</pre><pre>model.add(MaxPool2D((2,2), strides = 2))</pre><pre>model.add(Conv2D(filters = 32, kernel_size = (3,3), padding = &#39;same&#39;, activation = &quot;relu&quot;))</pre><pre>model.add(Conv2D(filters = 16, kernel_size = (3,3), padding = &#39;same&#39;, activation = &quot;relu&quot;))</pre><pre>model.add(MaxPool2D((2,2), strides = 2))</pre><pre>model.add(Flatten())</pre><pre>model.add(Dense(units = 10, activation = &quot;softmax&quot;))</pre><pre># create_model ends</pre><pre>return model</pre><pre>model = create_model()</pre><pre>model = Model(inputs = model.input, outputs = model.output)</pre><pre>model.compile(optimizer=&#39;adam&#39;, loss = &#39;sparse_categorical_crossentropy&#39;,metrics=[&#39;accuracy&#39;])</pre><pre>model.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/0*YPF67wtb6ZaKIKua" /><figcaption>Summary of the model showing the arrangement of the layers</figcaption></figure><pre>history = model.fit(X_train, y_train, epochs = 25, validation_split = 0.1)</pre><pre>plt.plot(history.history[&#39;accuracy&#39;])</pre><pre>plt.plot(history.history[&#39;val_accuracy&#39;])</pre><pre>plt.title(&#39;Model Accuracy&#39;)</pre><pre>plt.xlabel(&#39;epoch&#39;)</pre><pre>plt.ylabel(&#39;accuracy&#39;)</pre><pre>plt.legend([&#39;training_accuracy&#39;, &#39;validation_accuracy&#39;], loc = &#39;lower right&#39;)</pre><pre>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/0*mqIYPwzC9E0nrNSi" /><figcaption>Model Accuracy Graph</figcaption></figure><pre>plt.plot(history.history[&#39;loss&#39;])</pre><pre>plt.plot(history.history[&#39;val_loss&#39;])</pre><pre>plt.title(&#39;Model Loss&#39;)</pre><pre>plt.xlabel(&#39;epoch&#39;)</pre><pre>plt.ylabel(&#39;accuracy&#39;)</pre><pre>plt.legend([&#39;training_loss&#39;, &#39;validation_loss&#39;], loc = &#39;lower right&#39;)</pre><pre>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/0*gmCMKMDdFrT0eu3W" /><figcaption>Model Loss Graph</figcaption></figure><pre>y_prediction = model.predict(X_test)</pre><pre>y_pred = np.array([np.argmax(label) for label in y_prediction])</pre><pre>cf_matrix = confusion_matrix(y_test, y_pred)</pre><pre>plt.figure(figsize = (9,9))</pre><pre>sns.heatmap(cf_matrix, annot=True, fmt=&#39;g&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*m7CAfhHZj3b9WLwz" /><figcaption>Confusion Matrix for MNIST dataset using the above created model</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dbcf01e64a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple Introduction to Neural Networks]]></title>
            <link>https://medium.com/@sahiladivarekar99/a-simple-introduction-to-neural-networks-7771c2286d8a?source=rss-1bd911ed6d93------2</link>
            <guid isPermaLink="false">https://medium.com/p/7771c2286d8a</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-neural-network]]></category>
            <category><![CDATA[feedforward-net]]></category>
            <category><![CDATA[backpropagation]]></category>
            <dc:creator><![CDATA[Sahil-Adivarekar]]></dc:creator>
            <pubDate>Sun, 31 Jul 2022 10:32:52 GMT</pubDate>
            <atom:updated>2022-08-04T05:32:58.446Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>Neural Networks or Artificial Neural Networks (ANNs) or Simulated Neural Networks (SNNs) are a subset of machine learning. The structure of the neural networks is inspired from the human brain. The nodes/neurons in the network are connected in such a way that it looks similar to neurons of the human brain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O33xjWf_ilRqy-sY3dUyLA.png" /></figure><p>An ANN consists of a number of layers which includes an input layer, one or more hidden layers and an output layer. Each neuron in the network is connected and is assigned a weight and a threshold. If the output of a particular neuron crosses the threshold value of that particular neuron, then the node is activated thereby sending data to the next layer.</p><p>The weights assigned help to determine the importance of the given variable. Greater the value of the weight, the more important that variable is.</p><p>Consider the perceptron (Single layered neural network) given.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*guH1aRavRs_koFuF" /></figure><p>There are three input variables X1, X2 and X3, one hidden layer and one output layer. Here weights are assigned as shown. The input variables are multiplied by their respective weights and are then summed together with the bias. Bias is considered incase all the weights become zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AaCXTEKH4tznt7-W" /></figure><p>The value calculated is then passed to the activation function — such as sigmoid function or linear activation (activation function is chosen according to the requirement of the problem statement) — to determine the output. The node is activated only if the value crosses the threshold of the node and moves to the next layer. This process is the feedforward part of the neural network.</p><p>The Y calculated is the predicted value (i.e. mathematically calculated value). Now to calculate the loss function (or cost function) we calculate the difference between the predicted and actual (practically retrieved) value is calculated i.e. Y actual — Y predicted.</p><p>Loss function / Cost function = MSE (Mean Square Error) is calculated as shown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AUGXP473Gm1qUwvr" /><figcaption><strong>Mean Square Error (MSE)</strong></figcaption></figure><p>The goal is to minimize the loss made in the feedforward, and this is done by adjusting the weights and bias value. This is done during backpropagation using optimizers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/0*lMlYi8FfXIaEx0L6" /></figure><p><strong>η </strong>is the learning rate and the negative symbol indicates that the new value of W is in the opposite direction of the old value.</p><p>Similar formula is used to update the bias.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/0*b8wUFAXTBPd3PlE5" /></figure><p>Consider the following dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*RLgm64Ny0-RCpBeuRqzsOQ.png" /></figure><p>Now lets make a neural network from scratch to classify whether the student will pass or fail the test based on the input parameters Study, Play and Sleep.</p><p>Since this would be classification type of problem, we are going to use Sigmoid Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/0*OumtCTr9au9e9dDC" /><figcaption><strong>Sigmoid Function</strong></figcaption></figure><pre>import numpy as np</pre><pre>dataset = np.array([<br>    [7,3,7],<br>    [1,2,8],<br>    [3,8,8],<br>    [5,2,9],<br>    [4,4,8],<br>    [2,2,9],<br>    [3,10,8],<br>    [9,2,6],<br>    [6,10,7]<br>])</pre><pre>labels = np.array([[1],[1],[0],[1],[1],[0],[0],[1],[1]])</pre><pre>def sigmoid_function(x):<br>    return 1/(1+np.exp(-x))</pre><pre>def sigmoid_derivative(x):<br>    return sigmoid_function(x) * (1 - sigmoid_function(x))</pre><pre>class Layer:<br>    <br>    def __init__(self, input_size, output_size):<br>        self.weights = np.random.rand(input_size,output_size)<br>        <br>    def forward_propagation(self, dataset):<br>        sum_of_product = np.dot(dataset, self.weights)<br>        result = sigmoid_function(sum_of_product)<br>        return result<br>    <br>    def backward_propagation(self,result, label, dataset):<br>        error = result - label<br>        adjustment = error - sigmoid_derivative(result)<br>        updated_weights = np.dot(dataset.T, adjustment)<br>        self.weights = self.weights - updated_weights<br>        return self.weights</pre><pre>&quot;&quot;&quot;<br>Output: There are only 3 input parameters (Study, Play and Sleep) and 1 output i.e. Pass/Fail<br>&quot;&quot;&quot;</pre><pre>output_layer = Layer(3,1)</pre><pre>#Train:<br>for i in range(100):<br>    result = output_layer.forward_propagation(dataset)<br>    weights = output_layer.backward_propagation(result, labels, dataset)<br>    output_layer.weights = weights</pre><pre>#Confusion Matrix:<br>pred = []<br>for r in result:<br>    if r&gt;0.5:<br>        pred.append(1)<br>    else:<br>        pred.append(0)<br>pred = np.array(pred)</pre><pre>from sklearn.metrics import confusion_matrix<br>cf_matrix = confusion_matrix(labels, pred)<br>print(cf_matrix)</pre><p>Output:</p><pre>[[1 2]<br> [0 6]]</pre><p>I hope that now you have a better understanding of Neural Networks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7771c2286d8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>