<?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 Rupesh on Medium]]></title>
        <description><![CDATA[Stories by Rupesh on Medium]]></description>
        <link>https://medium.com/@rupeshthetech?source=rss-23fdd684dda------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*sDvTYWJV6lmWAGMpBRPpuA.jpeg</url>
            <title>Stories by Rupesh on Medium</title>
            <link>https://medium.com/@rupeshthetech?source=rss-23fdd684dda------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:58:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rupeshthetech/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[Extract Face Embedding from Image]]></title>
            <link>https://rupeshthetech.medium.com/extract-face-embedding-from-image-c5e80a47d8e5?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5e80a47d8e5</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[facedetection]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 16:26:02 GMT</pubDate>
            <atom:updated>2021-02-09T16:26:02.871Z</atom:updated>
            <content:encoded><![CDATA[<p>Extract identity vector for individual faces</p><p>Here I am going to discuss how to extract the face encoding or face embedding from an image using pre-trained models that are available in open source. I have also attached the code <a href="https://github.com/RupeshMce/face_recognition/blob/master/Extract%20Face%20Encoding%20From%20Image.ipynb">refer</a> this git.</p><h4>Face Embeddings:</h4><p>It analyses the given image and returns numerical vectors that represent each detected face in the image.The vectors of different size 64,128,256,512. Here we are going to discuss the model which returns a vector of 128 sizes.</p><p>We can use this embedding we can able to perform face recognition and face verification and face Matching Application.</p><p>It is a deep learning-based method to represent identity for individual faces. The architecture named <em>FaceNet</em> is used to extract face embedding to know more about it refer <a href="https://arxiv.org/pdf/1503.03832.pdf">link</a>.</p><h4>Dlib :</h4><p>We can use Dlib to locate faces in an image as discussed in the <a href="https://rupeshthetech.medium.com/face-detection-models-and-their-performance-comparison-eb8da55f328c">previous</a> blog. Also by using it, we can extract the face encoding vector for faces in the image. The model named <em>dlib_face_recognition_resnet_model_v1.dat </em>is<em> </em>used to extract encodings in the Dlib module.</p><p>Here we need to say the location of faces in the given image. The advantage of Dlib is, It is a lightweight model and runs even in a CPU with low computational power and also has low inference time comparing to other models. One bonus in Dlib, By default it has a face detection module in it.</p><pre># Load the model using Dlib</pre><pre>dlib.face_recognition_model_v1(&#39;dlib_face_recognition_resnet_model_v1.dat&#39;)  </pre><p>Function to get encodings :</p><pre>def encodings(img,face_locations,pose_predictor,face_encoder):</pre><pre>    predictors = [pose_predictor(img, face_location) for face_location in face_locations]</pre><pre>    return [np.array(face_encoder.compute_face_descriptor(img, predictor, 1)) for predictor in predictors]</pre><p>Source code is available <a href="https://github.com/RupeshMce/face_recognition/blob/master/Extract%20Face%20Encoding%20From%20Image.ipynb"><em>here</em></a>. The pose predictor model can be downloaded <a href="http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2"><em>here</em></a>.</p><h4>TensorFlow Models :</h4><p>There is also a pre-trained TensorFlow model that can be used to extract encodings of faces in images. The architecture used is the same in both cases but the loss function and training data changes. Thus the encoding vector return from it will be different from the previous model but it is of size 128 dimension.</p><p>Here for a model, we need to pass only the cropped image which only has a face in it, because it will detect the face in the image it just read the image and pass the image into a network and returns a vector which is a face encoding.</p><p>To handle the above scenario, we need to crop the faces from the image and pass it into the model. To detect and crop the faces from the image using any one of the methods discussed in the previous blog.</p><p>In order to load the model...</p><pre>def load_model(modelpath):<br>    detection_graph = tf.Graph()<br>    with detection_graph.as_default():<br>        od_graph_def = tf.GraphDef()<br>        with tf.gfile.GFile(modelpath, &#39;rb&#39;) as fid:<br>            serialized_graph = fid.read()<br>            od_graph_def.ParseFromString(serialized_graph)<br>            tf.import_graph_def(od_graph_def, name=&#39;&#39;)<br>    return detection_graph</pre><p>To get embeddings...</p><pre>def get_embedding(graph,img):<br>    input_array = preprocess_input_img(img)<br>    with graph.as_default():<br>        with tf.Session() as sess:<br>            images_placeholder = tf.get_default_graph().get_tensor_by_name(&quot;input:0&quot;)<br>            embeddings = tf.get_default_graph().get_tensor_by_name(&quot;embeddings:0&quot;)<br>            phase_train_placeholder = tf.get_default_graph().get_tensor_by_name(&quot;phase_train:0&quot;)<br>            embedding_size = embeddings.get_shape()[1]<br>            feed_dict = {images_placeholder: input_array, phase_train_placeholder: False}<br>            embeddings = sess.run(embeddings, feed_dict=feed_dict)<br>    return embeddings</pre><blockquote>Need to pass the model graph and image (preprocessed image if needed).</blockquote><p>We can also pass multiple images in a time based on the machine capacity we need to set our batch size.</p><p>It runs on both CPU and GPU, while in GPU it runs faster.</p><p>The source code is <a href="https://github.com/RupeshMce/face_recognition/blob/master/Extract%20Face%20Encoding%20From%20Image.ipynb"><em>here</em></a>. The model can be downloaded <a href="https://drive.google.com/file/d/0B5MzpY9kBtDVOTVnU3NIaUdySFE/edit"><em>from</em></a>. Few other facenet TensorFlow models are also available to try if needed.</p><p>On comparing these models, Dlib is easy and holds less complexity in the case of extracting face embeddings compared to TensorFlow models. But in the case of having high computation power TF models performs well.</p><p>Here I have attached the source code <a href="https://github.com/RupeshMce/face_recognition/blob/master/Extract%20Face%20Encoding%20From%20Image.ipynb"><em>link</em></a> use it for reference.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5e80a47d8e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Face Detection Models and their Performance Comparison]]></title>
            <link>https://rupeshthetech.medium.com/face-detection-models-and-their-performance-comparison-eb8da55f328c?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb8da55f328c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[facedetection]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 16:17:25 GMT</pubDate>
            <atom:updated>2021-02-09T17:17:34.050Z</atom:updated>
            <content:encoded><![CDATA[<h4>let&#39;s make a machine to identify its user’s</h4><p>Here we discuss a few available and most used face detection deep learning-based models and their performance concerning the accuracy and computational cost.</p><h3>Dlib :</h3><p><a href="http://dlib.net/">Dlib</a> is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real-world problems. It conveniently has the necessary bindings that will enable you to run many tasks directly in Python. One of them we are going to try is Face Detection. To install Dlib follow the <a href="https://www.pyimagesearch.com/2017/03/27/how-to-install-dlib/"><em>link</em></a><em>.</em></p><p>Dlib offers different algorithms for face detection. One of them is a frontal face detector which works well. The detector is based on the <em>histogram of oriented gradients (HOG) </em>and <em>linear SVM. </em>It works well in the CPU itself.</p><pre>import dlib <br>face_detector = dlib.get_frontal_face_detector() # face_detector<br>face_detector(img)</pre><pre>==&gt; rectangles[[(174, 134) (353, 313)]] # return an dlib.rectangles</pre><p>Dlib front face detector is a light-weight package and executes with low computation power. It can even use to detect multiple faces in a single image. Sample prediction like...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szdWz0iIYsmDCsOCA0sdvg.jpeg" /><figcaption>multiple face detection ==&gt; Dlib</figcaption></figure><h3>MTCNN :</h3><p>Stands for <em>Multi-task Cascaded Convolutional Networks. </em>It is a python package that can be installed easily and they provide a high-level API for face detection. Its performance is better than Dlib but it needs more computation than Dlib. It works in both GPU and CPU. It uses Tensorflow as a backend. It also supports multiple face detection in an image. The prediction of the same image in MTCNN results like...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iw13AsCmDTfKUT_kzW1r-w.jpeg" /><figcaption>Multiple Face Detection ==&gt; MTCNN</figcaption></figure><p>When we compare these two results we can find that some of the occluded faces are not detected by Dlib but MTCNN detected it. Below is a simple snippet of MTCNN in python.</p><pre>from mtcnn import MTCNN<br>face_detector = MTCNN()<br>face_detector.detect_faces(img)</pre><pre>Returns:<br>[{&#39;box&#39;: [208, 122, 155, 207],<br>  &#39;confidence&#39;: 1.0,<br>  &#39;keypoints&#39;: {&#39;left_eye&#39;: (243, 205),<br>   &#39;mouth_left&#39;: (249, 276),<br>   &#39;mouth_right&#39;: (311, 274),<br>   &#39;nose&#39;: (271, 244),<br>   &#39;right_eye&#39;: (306, 203)}}]</pre><p>MTCNN will also return facial keypoints like eyes, nose, mouth. To know more about MTCNN refer <a href="https://arxiv.org/pdf/1604.02878.pdf">here</a>.</p><h3>Face Recognition</h3><p>A simple library is available in python for face detection and recognition. It can also be used in the command line if needed. It is easy to install, by just running the command “<em>pip install face_recognition</em>”. It also supports multiple face detection in an image. The full documentation of the package is attached <a href="https://github.com/ageitgey/face_recognition">here</a>. The small snippet of it</p><pre>import face_recognition<br>face_recognition.face_locations(img)</pre><pre>Output:<br>[(139, 366, 325, 180)]   # return the face Location</pre><p>Since it is built with a dlib in the back-end its performance is also similar to dlib. The sample detection is …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXrE6Frm-KpeZL3f6GzcXg.jpeg" /><figcaption>Multiple Face Detection ==&gt; face recognition module</figcaption></figure><p>Here we can see that some of the occluded faces are not detected by it and the same thing happen in dlib prediction.</p><h3>Tiny Face Detector in TensorFlow</h3><p>Tensorflow based model trained with a large dataset. It is a pre-trained model where we can use this model for inference. The setup and git are referred to <a href="https://github.com/cydonia999/Tiny_Faces_in_Tensorflow">here</a>. The advantage of this model is, it detects more accurately and precisely than all the existing models in real-time. But its computation time is much higher than other models. The reason is, it will scale the image in many ratios and try to predict faces and then combine the result with non-maximum suppression. The result of this model is …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OVAy5FchX5LQknOVF1Oykg.jpeg" /></figure><p>The above sample will not highlight this model performance. It looks at the sample as MTCNN or another model. But if we use an image that holds many faces we can see the difference (<a href="https://raw.githubusercontent.com/cydonia999/Tiny_Faces_in_Tensorflow/master/images/selfie.jpg">link</a>).</p><p>Here I have discussed more which can run in both CPU and GPU. The overall performance of the model is plotted below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*c3HPsmiwQ3Al8os5KFIAMA.png" /><figcaption>Model Performance Comparison</figcaption></figure><p>From the plot, we can infer that Tiny Face Tensorflow take much computational cost whereas dlib and FaceRecoginition module consume low computation cost.</p><p>But in terms of accuracy Tiny face model is best compared to dlib.</p><p>So based on the application we need to select a model. In the case of real-time face detection, we can use dlib and MTCNN (if GPU is available) models where it results in a good performance.</p><p>In the case of face analysis or the case of a low-quality image we can use the Tiny Face Tensorflow model since it takes more computational time but we can achieve high accuracy.</p><p>Here I have attached my Git <a href="https://github.com/RupeshMce/face_recognition">link</a> for this blog.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb8da55f328c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Document Code Without Writing Documentation]]></title>
            <link>https://rupeshthetech.medium.com/document-code-without-writing-documentation-c1040bb84b54?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1040bb84b54</guid>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pycco]]></category>
            <category><![CDATA[code-documentation]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Fri, 17 Jan 2020 09:29:58 GMT</pubDate>
            <atom:updated>2020-01-17T09:29:58.575Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automated Code Documentation</h3><blockquote>As developers we love to write code,but what about documenting it ?</blockquote><p>Being a developer we might read more about the code than what we write. So it is very frustrating to read badly documented code/scripts.</p><p>As a developer we need to read lots of documentation of library/frameworks and our colleague’s code.</p><p>Similarly, if someone wants to read your code then it requires documentation so they can understand the code in a better way.</p><p>Generally, programmers like us, won’t like to document the process. But we add comments for our codes, which will help us refer to the functionality at a later point of time. This is almost equivalent to a rough draft of documentation. Imagine if that comment is converted into a document automatically then how easy the task becomes for us. That is what we are going to discuss today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4QgU0qZBtrQLgEp0mqgZcg.jpeg" /></figure><h4><a href="https://github.com/pycco-docs/pycco">PYCCO</a> :</h4><p>Python Package is used to document python code from the comments we provide. It will also help us to do basic formatting in documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXNo-OXb1W9xFphsJzOE1Q.png" /><figcaption>Example of Pycco Output</figcaption></figure><h4>Overview :</h4><p>Takes the comments from the code and coverts it into a html file along with a CSS file for proper formatting, which results like the above image. The html page is split into two halves ,left-side is for documentation and right-side for scripts . If you need it in docs or pdf format convert the html file into pdf using html to pdf converter which is an open source tool available online.</p><h4>Hands on Pycco:</h4><p>We can install pycco easily with a simple pip commond .</p><pre>pip install Pycco</pre><p>We are not going to use it inside a python file. But run the cli command with this to generate report like.</p><pre>pycco main.py</pre><pre>returns ==&gt; pycco: main.py -&gt; docs/main.html</pre><p>The cli format should be like pycco &lt;python file&gt; . It will execute and return an html file with the same name as the file provided . The output is generated and stored in the docs &lt;dir&gt; by default.</p><p>Also try this,</p><pre>pycco folder_name/*.py -i</pre><p>In case you need to generate reports for all the files in a directory, then use the above command, “-i” args, which is an optional parameter. If we provide it, it will generate an index.html file that lists all the report files from which we can redirect to the required file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*VkJ-XiCqRDlNNnZj3_GLdQ.png" /><figcaption>Sample of Pycco Index.html</figcaption></figure><pre># Save Output in specified Directory --</pre><pre>pycco main.py -w path_to_save/</pre><p>Use “-w” args to specify the target directory where the corresponding html file needs to get saved.</p><h4>Formatting Options:</h4><p>By default each html file has an heading of corresponding python filename.</p><p>We can also add heading , highlight text ,format the text like bold and italic etc, for more formatting option refer the official documentation.</p><h4>Basic options</h4><p>Use equal sign(“=”) at before and end of statement to convert it into heading.</p><p>Based on number of signs the corresponding heading tag will get mapped.</p><p>Likewise add “*” sign to format the text as bold and italic.</p><p>It also supports an option to link the text with other text in same or different document, example by selecting the function name we can get function definition.</p><p>Here I have attached my sample script <a href="https://github.com/RupeshMce/Documentation-of-Python-Code/blob/master/main.py">here</a> for reference.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL and developer’s related blogs .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1040bb84b54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Complete Guide for Process Automation in Python]]></title>
            <link>https://rupeshthetech.medium.com/complete-guide-for-process-automation-in-python-752d32e79456?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/752d32e79456</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[roboticprocessautomation]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[pyautogui]]></category>
            <category><![CDATA[process-automation]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Fri, 20 Sep 2019 05:16:24 GMT</pubDate>
            <atom:updated>2019-09-20T05:16:24.113Z</atom:updated>
            <content:encoded><![CDATA[<p>Imitate Human Activities with Machine</p><p>I like to share my tool which is developed in order to imitate human interaction with machine.</p><p>It is a lightweight, customizable and OS independent application.</p><p>Here I have attached the <a href="https://github.com/RupeshMce/PythonProcessAutomation">Git</a> link of this tool, where you can find the scripts and its installation steps.</p><p>Before that, you need to know what the tool can do and how its works and where we can use it.</p><h3>What Can It Do ?</h3><p>The tool is used to replicate human action against machine which means it will listen to human behaviour with machine and execute it in same order and same time space (i.e) the time interval between two actions will also be maintained.</p><h3>How It Works ?</h3><p>Python is the platform used to build this tools also it includes Pynput and PyautoGui . Pynput is the package used to read keyboard and mouse actions. Here the tool is design to read all combinations of keyboard events and mouse actions. Pyautogui is an another package used to execute events records from previous module. The tool can able to read the time interval between events and reproduce in same manner. The tool is split into two phase</p><h4><strong>Training Phase</strong></h4><p>The training phase includes the recording of user actions. The actions are saved and reproduced later. In order to save the actions I have used the file format called <strong>pickle. </strong>The reason for selecting the pickle format is that we can read the data as it is as we save into to it.</p><p><a href="https://github.com/RupeshMce/PythonProcessAutomation/blob/master/Demo/training_phase.mp4">RupeshMce/PythonProcessAutomation</a></p><h4>Execution Phase</h4><p>It reads the pickle file and executes the actions and events stored in it. The interesting part is that the training can be done in one machine and execution can be done in another machine but it should have same type of hardware. So one trained file will be used in multiple machine.</p><p>The tool is designed in such a way it can do all possible combinations of keyboard events as well as mouse clicks. It can also be customised so that we can include any new kind of key combinations.</p><p><a href="https://github.com/RupeshMce/PythonProcessAutomation/blob/master/Demo/Execution_Phase.mp4">RupeshMce/PythonProcessAutomation</a></p><h4>Where can we use this ?</h4><p>In many business cases, there will be replicated actions of mouse clicks and typing actions in regular intervals of time without any change in order of actions. In such situations, this tool will reduce human power and manual error which occurs in some scenarios. It can act as a web scraping tool in order to scrap the data from highly secured sites where the scripts can’t do it.</p><p>I made an attachment of scraping dollar equivalent value of Indian rupee on daily basis and store it in excel file .</p><p>If you need to customize the tool,it in such a way mail that file to xyx@mail.com. you can do that.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=752d32e79456" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Feature Engineering]]></title>
            <link>https://rupeshthetech.medium.com/feature-engineering-8627e115d018?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/8627e115d018</guid>
            <category><![CDATA[missing-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[data-handling]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Sat, 07 Sep 2019 13:06:32 GMT</pubDate>
            <atom:updated>2019-09-07T13:06:32.565Z</atom:updated>
            <content:encoded><![CDATA[<p>Figure out quality and quantity of the feature from Data</p><p><em>Actually the success of all Machine Learning algorithms depends on how you present the data.</em></p><p>This is the continuation of my previous <a href="https://medium.com/@rupeshthetech/life-cycle-of-a-data-science-project-d82a74aa46e">post</a>. In this post, we are going to deal with the theory behind <strong>feature engineering</strong>.</p><p>Features in data refers to columns. It is the process of transforming the given data into a new form which is easy to interpret and understand. It is an important phase in the pipeline of building a ML model, since it creates a difference between a good and bad model. Lets dwelve deeper into the impact it has on the model performance.</p><h4><strong>Handling Missing(Nan) Values</strong></h4><p>Before looking into the data, try to know if there is any missing value in features. If you start analysing the data and later you find that if some values are missing, you need to handle it and start analysis once again from scratch. Try to figure out how many missing values or information is in our data and how many features are affected by it.</p><p><strong>Figure out the answer =&gt; </strong><em>Why the data is missing?</em></p><p>It is the important question we need to keep in mind and start looking into the data. <strong><em>Is the Data missing because it does not exist or it is not documented?</em></strong></p><p>By finding the answer to the same question the techniques to handle the missing data depend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*urxkidofDwE_fYk-YWkMyQ.jpeg" /><figcaption>Source : <a href="https://towardsdatascience.com/gans-and-missing-data-imputation-815a0cbc4ece">https://towardsdatascience.com/gans-and-missing-data-imputation-815a0cbc4ece</a></figcaption></figure><p>Consider the scenario where you have the data about a class of 100 students which includes height , weight and age. Let us say if the height of 5th record is missing then it is because an error occurred while documenting. In such cases, we fill the data by taking the mean of the column and replace NaN with mean or build a ML model with other factors as independent feature and height as dependent so we can predict those values or if similar data like same weight and age value exist with height in the data we can use those values. We will discuss it briefly in the next part.</p><p>Another scenario, consider you encounter a Movie rating data.In general rating related data will hold large amount of NaN values because we would not rate all products we use. This is the place where the data does not exist. In such cases if you try to implement the above mentioned methods it will collapse the model and story of the data. When I faced this issue in dealing with movie ratings I replaced NaN with Zero, reason being, the rating range is from 1 to 10 and so there is nothing called Zero rating. Now it makes sense that Zero rating implies that he/she has not watched the movie.</p><p>Now lets discuss about few technique used to handle missing values.</p><p><em>Drop the Features</em></p><p>If you feel that most of the values in a feature is NaN, it is better to drop that column from dataset. It is also applied to a record(rows) which holds multiple NaN values. This is because, if we try to fill most of the values, it may affect the nature of entire data. This technique is applied only if you have some large amount of data.</p><p><em>Replace with values</em></p><p>The term values mean that most frequent values occur in column and mean of the column but try one at a time. In case of small dataset if we delete a column or row it may lead to loss of information. So use this method to handle it. If you have many NaN values this method is not recommended as it may lead to Imbalanced Data</p><p><em>Predict Missing Values</em></p><p>Consider that If you have a training set in which one independent column holds some Nan values rest are not. Then try to build a model from the rest of data by considering them as independent feature and predict the missing data. This technique is used to predict missing categorical data since only classifier models are used here. In some cases we implement unsupervised models instead of supervised classifier which is also an option.</p><p>The another important part of feature engineering is,</p><p><strong>Handling Imbalanced Data</strong></p><p>Imbalance means the data in dataset is biased to one specific group or target class. It exists in most of the real time problems. The reason for imbalance is that the minority class events have not occurred in regular intervals. But the interesting part is the ML model need to predict that minority class in a more accurate manner. This is because, when we consider a case where 95% of data belong to class A and rest part is B. If Model says every thing is class A then its accuracy is 95%. For such prediction we don’t need a ML model we can label it with automation scripts.Here comes the part of data handling . In general, there are some techniques,</p><p><em>Over Sampling</em></p><p>It is used to increase the records of minority class by replicating them until it reaches the another class ratio. But it is just duplication of data. It is not a good idea because in data cleaning we remove duplicate records but here we add duplicate records. It work may any changes in models while training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*0ftNen8H5W4J1nFP6zqIhA.png" /><figcaption>Source:<a href="http://www.treselle.com/blog/handle-class-imbalance-data-with-r/">http://www.treselle.com/blog/handle-class-imbalance-data-with-r/</a></figcaption></figure><p><em>Under Sampling</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*F5HkWxUWfW2Z36tJ6f9qFg.png" /><figcaption>Source : <a href="http://www.treselle.com/blog/handle-class-imbalance-data-with-r/">http://www.treselle.com/blog/handle-class-imbalance-data-with-r/</a></figcaption></figure><p>It is the process of maintaining the distribution of records across different classes by eliminating the records in majority class. But the drawback is it leads to data loss and information loss. This loss will affect Model performance.</p><p><em>SMOTE =&gt;Synthetic Minority Over-sampling Technique</em></p><p>It is an Over Sampling technique which increase the count of minority class not by duplicating it .It will generate new data based on existing data. Data generation like this will consider that you plot your data in n-dimension and it will take two data point in serial and pick the new data point from the centre of two data point as see in fig</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*aHIGSu-kcZGQt2W1L4sY7g.png" /><figcaption>Source:<a href="https://www.arxiv-vanity.com/papers/1711.00837/#id7">https://www.arxiv-vanity.com/papers/1711.00837/#id7</a></figcaption></figure><p>The important factor is that the new data generated is assumed that it belongs to class minority. But in some cases our assumption may be wrong. Since these are not real data it is just synthetic data. Do proper analysis on newly generated data because it will be included in training part.</p><p><em>Ensemble Techniques</em></p><p>It is an alternative approach to handle same problem. Until now we discussed about how to do data handling. But now we build a ML Model which will help to solve our problem. Here we Build multiple ML Models with same training data and make to vote. For example consider we can build KNN, SVM,Naive Bayes and Logistic Regression Classifier with the same data and allow them to predict a new data. Among all classifier predict which class has got more vote consider it as the predicted class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*Y6gZ2AkTK3KsBN055hOZ5g.png" /><figcaption>Source : <a href="http://rasbt.github.io/mlxtend/user_guide/classifier/EnsembleVoteClassifier/">http://rasbt.github.io/mlxtend/user_guide/classifier/EnsembleVoteClassifier/</a></figcaption></figure><p>In my next post I will include the coding part for all the concepts that we discussed here. Try to be on both Python and R.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8627e115d018" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Life Cycle of a Data Science Project]]></title>
            <link>https://rupeshthetech.medium.com/life-cycle-of-a-data-science-project-d82a74aa46e?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/d82a74aa46e</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[project-life-cycle]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 11:17:45 GMT</pubDate>
            <atom:updated>2019-08-17T11:17:45.178Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Sequence of phases that a data science project goes through</em></p><p>If you plan to do a data science project, it is important to understand the various phases and stages that the project undergoes. It may be any project in Machine Learning or Deep Learning. The steps involved are listed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HS4j9oerUrAywKmT9FGRWQ.png" /></figure><h4>Data Collection or Data Gathering</h4><p>Data is the primary raw material for any machine learning project. How and where do we get the data?</p><p><strong>Web Scraping</strong></p><p>It is the technique used to extract the data from websites and store it in local storage for later use. It can be done either manually or in an automated fashion. The best practice of web scraping is to automate it, so it will perform the same task within a fraction of the time.</p><p><strong>APIs</strong></p><p>Application Program Interface (API) is a code that allows two software programs to communicate with each other. We mainly use API for data collection by passing the required params to it. The APIs are usually open source and not charged for usage. However, there are few other APIs that are monetised.</p><p><strong>Data Storage</strong></p><p>It is one of the most important tasks in data collection which indicates where we are going to save the collected data. We can use Database or any file system. In case of Big Data we use cluster based system architectures to save data but the best option in big data is to move to cloud storage which is safe and secure with minimum maintenance. Generally there are two types of storage, <em>hot</em> and <em>cold</em>.Most frequently used and high demand data is stored in <strong>Hot</strong> storage which we allows fast data access and will be available at anytime. In contrast, <strong>Cold</strong> storage does not allow faster access of data and it usually takes some time. Mostly historical data are stored here.</p><h4>Feature Engineering</h4><p>Features in data refers to columns. Basically all ML algorithms use some set of inputs to predict the outcome. But input to ML algorithms need to be clean and structured to obtain effective results. So, the algorithm demands that each feature should be important and relevant to perform well.</p><p><strong>Handling Missing(Nan) Values</strong></p><p>In most of the scenarios, the dataset will hold “NaN” in it. It is a common error that occurs in every dataset which needs to be handle in a proper way. The common methods used to replace the NaN values are by calculating the mean,median or with adjacent values or with zeros. In some rare cases either a row or feature with most of the values as NaN are deleted.</p><p><strong>Handling Imbalanced Data</strong></p><p>In real time problems , data will be highly imbalanced in nature. Imbalance means the data in dataset is biased to one specific group or target class. In such scenarios, data sampling is an important portion which needs to be handled in a smart way.The thing I did while facing the same problem is that, while splitting the data into train and test the ratio of data should be uniform to each class in both splits. Another thing is that, training data should hold all possible scenarios that occur in the data. The test set is just the new scenario of training data not a new data.</p><p><strong>Data Cleaning</strong></p><p>Data cleaning as the name implies, is cleaning the data by removing the impurities from it. It includes removing duplicate entries in rows and columns. Remove the outliers from the data using some anomaly detection techniques.</p><p><strong>Format the Data</strong></p><p>It is an important part, because this only makes the reader to understand the data quickly. Some of the formatting that is done like, renaming the columns in order to give a meaningful name to each col so they can imply proper meaning. Try to follow any number system to represent the numerical data in order to have good readability.</p><h4>Feature Selection</h4><p>It plays a vital role in predictive analysis. The algorithm performance is based on features used. While performing data collection and data cleaning we don’t consider about how many features the data holds. It is not a mandatory thing that each feature in the data, should have some weightage in predicting the output variable. So we need to remove the unwanted features, otherwise it makes the data, high dimensional. But we should remember about the <strong><em>curse of dimensionality</em></strong><em> (i.e)</em> as the dimension of data increases there is a complexity in training and also it may affect the performance of the model. So we need to consider only the features that will add more weightage to predict the output data. The few techniques used are listed below.</p><p><strong>Correlation</strong></p><p>If two feature holds good correlation between them and the one with good correlation with target feature will be selected while the another one is removed. It simply indicates the eradication of redundant data.</p><p><strong>Heatmap</strong></p><p>It is a graphical representation of features in matrix format, where each cell is filled with different shades of colors. From this we can say how each feature is related to one another.</p><p>Now, export the data as csv or excel file. These are the features of data I am going to use to train my model.</p><h4>Training the Model</h4><p>Once the data is ready, we need to start the training process. Here comes the question =&gt;what model should I use? and how to evaluate the performance of the trained model? So we need to know how each model will work and how they are different from each other.</p><p>Choose the Model and train the model with the data. If your model performance is as good as the expectation at the first run, you are a lucky human else you need to do hyper parameter turning like modifying the learning rate, regularisation, class weights, etc.,</p><p>The answer for second question is , you should know few evaluation metric terms like precision,recall,F1-score,AUC etc., The evaluation metrics are not as scarier as they sound, once you learn about them.</p><p><strong>Model Deployment</strong></p><p>In most cases we use cloud platforms such as AWS,GCP servers for deployment. In general <strong>Flask, </strong>a python framework, will be used to deploy the model with front-end. Once the setup is done, move to production servers.</p><p>Test your model in real time examples. If it works as excepted leave it but the regular maintenance needs to be done. If it does not perform well in the production setup, then we need to find out the part of the workflow that causes the problem and find a way to fix it. If it’s due to lack of data, then move to data collection step or if it is due to feature selection then try to redo the feature selection step in the correct way and then train the model and deploy it.</p><p>Here I have discussed about a High level view of Data science Project Life Cycle. In the following weeks, you will get a detailed explanation of each segment and its implementation in python and R.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d82a74aa46e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Regression Full Tutorial Guide]]></title>
            <link>https://rupeshthetech.medium.com/linear-regression-full-tutorial-guide-f32ac17caa9f?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/f32ac17caa9f</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Fri, 02 Aug 2019 12:58:45 GMT</pubDate>
            <atom:updated>2019-08-02T12:58:45.811Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post let’s explore regression algorithm and script it from scratch in python and R.</p><p>Linear regression is a simple and easy algorithm used in machine learning for predictive analysis. It is used to establish a relationship between an input variable(X) and output variable(Y). Input with single independent variable is predominantly called as linear regression and input with more than one independent variable is called as multiple linear regression.</p><h4><strong>Model Representation</strong></h4><p>The input variable is the independent variable and output variable is the dependent variable.</p><p>Equation of the line,</p><p><strong><em>Y=b0 + b1.X</em></strong></p><blockquote>where <strong>b1</strong> is the slope of the line and <strong>b0</strong> (bias) is the intercept of <strong>Y</strong> and they are also called as weights.</blockquote><p>Our end goal is to draw a line between X(independent) and Y(dependent) which fine tunes the relationship between them.</p><p>The problem is how to find these coefficients(weights). Here comes the learning procedure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZ3sEg_6D5FhJxAjIhYU8A.png" /><figcaption>Linear Regression Visual Representation.</figcaption></figure><h4>Loss Function (Cost Function)</h4><p>A <strong>loss function</strong> (error) is a measure of performance of a prediction model, in terms its ability to predict the expected outcome<strong>. </strong>By reducing the error we can get the accurate values for <em>b0</em> and <em>b1</em>. <strong>Mean Square Error(MSE)</strong> is the<strong> </strong>function used for error calculation.</p><p>Error Calculation steps are as follows.</p><ol><li>Find the difference between actual Y and predicted Y with respect to each value of X.</li><li>Square the difference.</li><li>Calculate the mean of the squares for each value of X.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*5ZZsitvUG2w1OIsbKGQafQ.png" /><figcaption>Mean Squared Error</figcaption></figure><blockquote>Here <strong>yᵢ</strong> is the actual value and <strong>ȳᵢ</strong> is the predicted value.</blockquote><p>Thus the loss function is defined.</p><p>Lets get into the part of reducing error, by finding <strong>b0 </strong>and <strong>b1 </strong>(weights)<strong>.</strong></p><h4>Ordinary Least Square Method(OLS)</h4><p>One of the easiest and most basic methods to calculate the coefficients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*RMGN1iWcl7l8iDy9Vk6HGg.png" /><figcaption>OLS Formula to Calculate b0 and b1</figcaption></figure><blockquote>x̄ is the mean value of input variable X and ȳ​ is the mean value of output variable Y.</blockquote><p>OLS method is predominantly used in cases of small data with one input variable. Whereas this method is not recommended for multiple regression, as it takes more computation time and it is a complex task to perform.</p><p><em>Implementation of </em><strong><em>OLS</em></strong><em> in </em><a href="https://github.com/RupeshMce/Machine-Learning/blob/master/Regression/Ordinary%20Least%20Square%C2%A0Method.ipynb"><strong><em>Python</em></strong></a><em> .</em></p><h4>Gradient Descent (GD)</h4><p><strong>Is an</strong> <strong>iterative machine learning optimization algorithm to reduce the cost function</strong> (error), so that we have models that make accurate predictions. It is used to find the optimised values for the coefficients <strong>b0</strong> and <strong>b1</strong>.</p><ol><li>Initially, the coefficients are assigned to <strong>zero (0) </strong>and fix the value of <strong>learning rate (</strong>α)</li><li>Calculate the gradient for the loss.</li><li>Update the coefficients and calculate the loss value.</li><li>Do step 2 and 3 in iterative manner to reduce the error as much as possible.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*bnhzmbWGgKW1-rsCSSGsPQ.png" /><figcaption>Gradient Descent Formula</figcaption></figure><blockquote>α is the learning rate and the part after minus in the formula is a partial derivative of cost function with respect to <em>βj</em>​. This is called as gradient.</blockquote><p>By changing the value of <em>βj</em>​ we can reduce cost function value. The value change of <em>βj</em>​ happens in baby steps such that we can obtain the minimum value of loss. If we find drastic changes in value, we might miss the minimum value. In order to make a small change in value we use the parameter called <strong>Learning rate (α) </strong>to control the gradient update.</p><h4>Learning Rate</h4><p>It controls by how much we should modify the weights (b0, b1) with respect to the loss gradient. Learning rates can either be initialized randomly or a specific value.</p><p><em>Implementation in </em><a href="https://github.com/RupeshMce/Machine-Learning/blob/master/Regression/Linear%20Regression%20Using%20Gradient%20Descent.ipynb"><strong><em>Python</em></strong></a><em>.</em></p><h4>Evaluation Metrics</h4><h4>R-squared Value</h4><p>R-squared value is a statistical measure of how close the data is, fitted to the regression line. It is a value between 0 and 1, that measures how well our regression line fits our data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JwEiZQSkL4I710994WaY4w.png" /></figure><blockquote>SSres is the residual sum of squared errors (Yi-Y-pred). SStot is the total sum of squared errors(Yi-Y-mean).</blockquote><p>It will become negative, if the model is completely wrong.</p><p>If the R-Square Value is close to 1 then, it’s a good one.</p><p>Here is the <a href="https://github.com/RupeshMce/Machine-Learning/tree/master/Regression">Git</a> reference for the whole blog.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f32ac17caa9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Initial Setup & Configuration to Enable GPU for Deep Learning Applications.]]></title>
            <link>https://rupeshthetech.medium.com/initial-setup-configuration-to-enable-gpu-for-deep-learning-applications-ae17ca0e17e?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae17ca0e17e</guid>
            <category><![CDATA[cuda]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Thu, 04 Jul 2019 05:55:41 GMT</pubDate>
            <atom:updated>2019-09-01T16:21:34.323Z</atom:updated>
            <content:encoded><![CDATA[<h3>Initial Setup &amp; Configuration to Enable GPU for Deep Learning Applications. (CUDA,cuDNN,TensorFlow,Nvidia)</h3><p>Here, I would like to share, how to setup Nvidia, cuDNN &amp; CUDA drivers for Deep Learning Applications for both local machines as well for cloud based applications in Linux platform.</p><h4>Step 1:</h4><p>Once your machine/instance is launched , initially update &amp; upgrade the machine.</p><pre>sudo apt-get update<br>sudo apt-get upgrade</pre><p>Install the basic dependencies like cmake ,git.</p><pre>sudo apt-get install build-essential<br>sudo apt-get install cmake git wget</pre><h4>Step 2:</h4><p>Post which, you need to verify that your machine can support NVIDIA drivers using this command. If your machine is not compatible with NVIDIA drivers, perform the same steps on a different machine/instance.</p><pre>lspci | grep -i nvidia</pre><p>If your machine supports NVIDIA then, the above command will result something like this:</p><pre>VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] (rev a1)</pre><h4>Step 3:</h4><blockquote>Install Nvidia Driver</blockquote><p>Choose the appropriate CUDA version which supports your Tensorflow version. Now, install corresponding nvidia driver which supports the same CUDA version . <a href="https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver">Explore</a> the link to find the appropriate nvidia driver for your CUDA version.</p><blockquote>NOTE: I’ve used CUDA 10.0</blockquote><pre>sudo add-apt-repository ppa:graphics-drivers/ppa<br>sudo apt update<br>sudo apt install nvidia-<strong>410</strong></pre><p>In case of any variation in the version, modify the nvidia number appropriately.</p><p>Restart machine and run the below command, to verify NVIDIA installation.</p><pre>nvidia-smi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s7sdt6HI8sypoCGervnZRA.png" /><figcaption>o/p for nvidia-smi command</figcaption></figure><p>Top Left Corner shows installed NVIDIA version.</p><p>If it works move to next step.</p><p>In case of Cloud Servers it might throw the following error in certain scenarios.</p><pre>NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.</pre><p>When such error occurs, try to identify the type of GPU machine. <em>For eg. Tesla M60 GPU.</em></p><p>Post identifying GPU’s type, navigate to this <a href="https://www.nvidia.in/Download/index.aspx?lang=in">link</a>. Specify the GPU type and download the driver with file extension <strong>.run</strong></p><p>Once the file is ready, run the below command.</p><pre>sudo apt remove nvidia-<strong>410</strong> # remove the existing nvidia<br>sudo /bin/sh NVIDIA-Linux-x86_64*.run</pre><p>Restart machine then try the linked <a href="#031c">command</a> to verify nvidia installation.</p><h4><strong>Step 4:</strong></h4><blockquote>Install CUDA</blockquote><p>Download the required version of <a href="https://developer.nvidia.com/cuda-toolkit-archive">CUDA</a> , then run</p><pre>sudo dpkg -i cuda-repo-ubuntu1604–10–1-local-10.1.168–418.67_1.0–1_amd64</pre><pre>sudo apt-key add /var/cuda-repo-&lt;version&gt;/7fa2af80.pub</pre><pre>sudo apt-get update</pre><pre>sudo apt-get install cuda</pre><p>While downloading CUDA , it will suggest to download and install an additional <strong>patch file(*.deb) </strong>which needs to be done after the CUDA installation.</p><pre>sudo dpkg -i cuda-repo-ubuntu1604-10-0-local-nvjpeg-update-1_1.0-1_amd64.deb</pre><p>Then export <strong>CUDA PATH</strong> as an environment variable. To do that, open <strong>.bashrc </strong>file in terminal and add the last two lines of the following section.</p><pre>sudo nano ~/.bashrc</pre><pre>export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}</pre><pre>export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}</pre><blockquote>NOTE: The CUDA version number above, should be based on the installed CUDA.</blockquote><p>Save .bashrc and refresh, and then check the CUDA version.</p><pre>source ~/.bashrc<br>nvcc -V</pre><h4><strong>Step 5:</strong></h4><blockquote>Install cuDNN</blockquote><p>Download the required <strong>cuDNN(*tgz)</strong> <a href="https://developer.nvidia.com/cudnn">file</a> which suits the installed CUDA version. The download requires login credentials. Once downloaded, un-tar the file.</p><pre>tar -xzvf cudnn-9.0-linux-x64-v7.tgz</pre><p>execute below commands to move files to the CUDA folder.</p><pre>sudo cp cuda/include/cudnn.h /usr/local/cuda/include</pre><pre>sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64</pre><pre>sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*</pre><h4>Step:6</h4><blockquote>Install TensorFlow</blockquote><p>In case of a new machine, pip(python 3) is required.</p><pre>sudo apt-get install python3-pip</pre><p>NOTE: Tensorflow version based on your requirement</p><pre>pip3 install tensorflow-gpu==1.13.1</pre><p>import tensorflow in python to validate installation.</p><pre>import tensorflow as tf</pre><p>Now the machine is ready to run Deep Learning applications.</p><p>If you are using cloud servers, you need to use <strong>wget</strong> CLI command to download all files . You can find all the downloadable links anchored in this article.</p><p>I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow <a href="https://medium.com/@rupeshthetech">me</a> for more ML/DL blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae17ca0e17e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Decorators]]></title>
            <link>https://rupeshthetech.medium.com/python-decorators-a6475feb7484?source=rss-23fdd684dda------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6475feb7484</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[decorators]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Rupesh]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 09:43:20 GMT</pubDate>
            <atom:updated>2019-06-04T09:43:20.941Z</atom:updated>
            <content:encoded><![CDATA[<h4>Add more functionality to your functions</h4><p>Decorators can be thought of as functions which modify the functionality of another function. It is a clean way of adding extra functionality to functions by using the “@” symbol. Also, it is a function which will accept another function as its parameter.</p><h4>Functions:</h4><p>Python uses the keyword called “def” to declare a function in it ,which stands for definition. The sample code is ,</p><pre>&gt;&gt;&gt; def medium():<br>...     print(&quot;Hello Medium!&quot;)<br>... <br>&gt;&gt;&gt; medium()<br>Hello Medium!</pre><blockquote>Here I have created a function called <strong>medium()</strong> which will print a statement “Hello Medium!”</blockquote><p>In case of adding new features to this above function we can create a new function call “wrapper” which will extend its behaviour.</p><pre>&gt;&gt;&gt; def wrapper(fun):<br>...     def inside():<br>...         print(&quot;Extra Code Before Medium Function&quot;)<br>...         fun()<br>...         print(&quot;Extra Code After Medium Function&quot;)<br>...     return inside</pre><blockquote>Let’s “<strong>decorate</strong>” our wrapper function by calling the decorator on it:</blockquote><pre>&gt;&gt;&gt; func=wrapper(medium)</pre><p>Let’s invoke the decorator as ,</p><pre>&gt;&gt;&gt; func()<br>Extra Code Before medium Function<br>Hello Medium!<br>Extra Code After medium Function</pre><p>As you see the output of the above code, we find that the embedded function named <strong>inside</strong> is executed. This is because the decorator returns the <strong>inside </strong>function and later can be accessed on call. It is defined within the local scope of the wrapper, which means that the argument fun was accessed by the “inside” function such that it can be called. This is how Decorators work.</p><p>Lets do this in a more readable way using “<strong>@</strong>” symbol above the function</p><pre>&gt;&gt;&gt; def wrapper(func):<br>...     def inside():<br>...         print(&quot;Extra Code Before Medium Function&quot;)<br>...         func()<br>...         print(&quot;Extra Code After Medium Function&quot;)<br>...     return inside<br>... <br>&gt;&gt;&gt; <a href="http://twitter.com/wrapper">@wrapper</a><br>... def medium():<br>...     print(&quot;Hello Medium!&quot;)<br></pre><h4>Output:</h4><pre>&gt;&gt;&gt; medium()<br>Extra Code Before Medium Function<br>Hello Medium!<br>Extra Code After Medium Function</pre><blockquote>The Statement <strong><em>@wrapper</em></strong><em> is equivalent to </em><strong><em>func=wrapper(medium)</em></strong><em>.</em></blockquote><h4>Passing Arguments:</h4><p>Here we are going to discuss how to pass parameters to decorators.</p><pre>&gt;&gt;&gt; def check(func):<br>...     def validate(a,b):<br>...         if b==0:<br>...             print(&quot;ZeroDivisionError: division by zero&quot;)<br>...             return<br>...         else:<br>...             return func(a,b)<br>...     return validate<br>... <br>&gt;&gt;&gt; <a href="http://twitter.com/check">@check</a>                              # Decorator<br>... def div(a,b):<br>...     return a/b</pre><p>Output:</p><pre>&gt;&gt;&gt; div(1,0)<br>ZeroDivisionError: division by zero<br>&gt;&gt;&gt; div(8,4)<br>2.0</pre><p>As mentioned above,</p><ol><li>The <strong>div</strong> function will be passed as an argument to the <strong>check</strong> function and in turn, it will return the <strong>validate</strong> function.</li><li>The validate function will accept the user’s parameters and execute if the dividend is not equal to Zero, else it will call and pass the args to <strong>div </strong>function which is referenced as func variable</li><li>In case dividend is Zero, then print statement in validate function is executed as shown above.</li></ol><p>Here I have included another example, where we can calculate the execution time of the functions.</p><pre>&gt;&gt;&gt; def timeit(func):<br>...     def time_calc(arg):<br>...         start=time.time()<br>...         param=func(arg)<br>...         print(&quot;Elapsed Time : {} Sec&quot;.format(time.time()-start))<br>...        # return param <br>...     return time_calc<br>... <br>&gt;&gt;&gt; <a href="http://twitter.com/timeit">@timeit</a><br>... def main_func(num):<br>...     temp=[]<br>...     for itr in range(num):<br>...         temp.append(itr)<br>...     return temp<br>... <br>&gt;&gt;&gt; main_func(10000000)<br>Elapsed Time : 0.8109278678894043 Sec</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6475feb7484" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>