<?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 CHINMAY ACHARYA on Medium]]></title>
        <description><![CDATA[Stories by CHINMAY ACHARYA on Medium]]></description>
        <link>https://medium.com/@chinmayacharya28?source=rss-7185f9f22385------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*D2XBHpO2OSqJ3uHD.</url>
            <title>Stories by CHINMAY ACHARYA on Medium</title>
            <link>https://medium.com/@chinmayacharya28?source=rss-7185f9f22385------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:37:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chinmayacharya28/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[From Selfie to Prediction: How Face Recognition Really Works]]></title>
            <link>https://chinmayacharya28.medium.com/from-selfie-to-prediction-how-face-recognition-really-works-f0b8bd4971ed?source=rss-7185f9f22385------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0b8bd4971ed</guid>
            <category><![CDATA[face-recognition]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[CHINMAY ACHARYA]]></dc:creator>
            <pubDate>Sat, 06 Sep 2025 17:57:02 GMT</pubDate>
            <atom:updated>2025-09-06T18:15:45.358Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Face recognition is one of the most fascinating and practical applications of computer vision. Whether it’s unlocking your smartphone, tagging friends in social media photos, or enhancing airport security systems, the ability of machines to recognise human faces has rapidly moved from research labs into everyday life.</blockquote><p>In this post, I’ll walk you through how a face recognition pipeline can be built using <strong>VGG-Face embeddings</strong>, <strong>Principal Component Analysis (PCA)</strong> for dimensionality reduction, and an <strong>SVM classifier</strong> for person identification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*tmIMpvgQ3kN23jFqqZEYaw.gif" /></figure><h3>1. Dataset and Preprocessing</h3><p>The first step of any computer vision project is working with data. The dataset used here contained:</p><p>Dataset : <a href="https://www.kaggle.com/datasets/hereisburak/pins-face-recognition">https://www.kaggle.com/datasets/hereisburak/pins-face-recognition</a> (This images has been collected from Pinterest and cropped.)</p><ul><li><strong>17,534 total images</strong></li><li><strong>105 unique individuals</strong></li><li>An average of <strong>~167 images per person</strong></li></ul><p>Each image was resized to <strong>224×224×3 pixels</strong>, which is the required input format for the VGG-Face model (a variant of the popular VGG16 CNN). Resizing ensures consistency and makes the model’s learning process efficient.</p><p>Once resized, each image was passed through VGG-Face to generate <strong>feature embeddings</strong> — essentially numerical vectors that represent the unique facial characteristics of each person. Each embedding was <strong>512-dimensional</strong>, capturing a broad set of facial features such as jawline, eye spacing, and nose shape.</p><p>To load this data, we’ll use the following Python packages:</p><blockquote>TensorFlow version: 2.12.0<br>Keras version: 2.12.0<br>NumPy version: 1.23.5<br>OpenCV version: 4.12.0</blockquote><p>After Loading data o/p look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5dcK0Qf-lR6vUuzhK8jSA.png" /></figure><h3>2. Feature Extraction with VGG-Face</h3><p>VGG-Face works as a powerful feature extractor. Instead of training a deep network from scratch (which requires millions of images), we leverage a pre-trained model that already understands general facial features.</p><ul><li><strong>Input:</strong> (224, 224, 3) image</li><li><strong>Output:</strong> 512-dimensional feature vector</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*9gAowvc-VUJpnhv0SvOtuA.png" /></figure><h3>3. Dimensionality Reduction with PCA</h3><p>Working directly with 512 dimensions for thousands of images can be computationally expensive and may lead to overfitting. To address this, <strong>Principal Component Analysis (PCA)</strong> was applied:</p><ul><li>Reduced dimensions to <strong>239 components</strong></li><li>Retained <strong>95% of variance</strong> in the data</li><li>Achieved ~<strong>53% reduction</strong> in dimensionality</li></ul><p>This step makes the training faster and helps the model focus only on the most important features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3o_tqdjobfmqLpAXST26w.png" /></figure><h3>4.Training with SVM</h3><p>After feature extraction, an <strong>SVM (Support Vector Machine)</strong> classifier was trained. Unlike neural networks, SVMs are well-suited for smaller datasets and can handle high-dimensional data effectively.</p><ul><li><strong>Training samples:</strong> 14,027</li><li><strong>Testing samples:</strong> 3,507</li></ul><p>Distinguishing between over <strong>100 different individuals</strong> with varied lighting, expressions, and backgrounds. In practice, recognition tasks with many classes often require additional fine-tuning or advanced loss functions like triplet loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*8vqG2P6hsSQUsypnxwKT0Q.png" /><figcaption><em>Confusion Matrix</em></figcaption></figure><h3>5.What the System Can Do</h3><p>Even with limitations, the system demonstrates several useful capabilities:</p><ul><li>Identify a person from a single image</li><li>Compare two images and compute a <strong>similarity score</strong></li><li>Output <strong>confidence levels</strong> for predictions</li><li>Handle recognition across <strong>100+ unique individuals</strong></li></ul><p>For example, when comparing celebrity faces, the system can not only classify the person but also provide a confidence score that explains how “certain” it is about the prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ikcRE0LKjyLFs_zZHkGNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yj4h2KxoGU41PT4dfccv0Q.png" /></figure><h3>6.Example Results</h3><p>Here are some real-world test outcomes:</p><ul><li>An image of <strong>Avril Lavigne</strong> was correctly classified with <strong>90% confidence</strong>.</li><li>An image of <strong>Chris Hemsworth</strong> was misclassified as <strong>Tom Hardy</strong>, with only <strong>12% confidence</strong>.</li></ul><p>This shows that the model works well for distinct faces but struggles with visually similar individuals, which is common in large-scale recognition systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBPrxhuAL0trFrp7NotYOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_HjManw0DKUSl_2Q05akxw.png" /></figure><h3>Key Takeaways</h3><ol><li><strong>Pre-trained CNNs like VGG-Face</strong> are excellent for feature extraction, saving time and resources.</li><li><strong>PCA reduces complexity</strong>, keeping only the most meaningful features.</li><li><strong>SVMs scale well</strong> for multi-class classification but may need advanced methods for higher accuracy.</li><li>Face recognition is a <strong>challenging domain</strong>, especially when the number of identities is large.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ANaYme3qTjtpOGI-SDGIA.png" /></figure><h3>Future Improvements</h3><p>Some possible next steps to boost performance:</p><ul><li>Fine-tune VGG-Face on this dataset instead of using it only as a frozen feature extractor.</li><li>Experiment with state-of-the-art models such as <strong>FaceNet</strong> or <strong>ArcFace</strong>.</li><li>Apply <strong>data augmentation</strong> (e.g., rotations, lighting adjustments) to make the system more robust.</li><li>Use <strong>metric learning approaches</strong> like triplet loss to improve similarity detection.</li></ul><h3>Final Thoughts</h3><p>This project highlights how a functional face recognition system can be built using a combination of <strong>deep learning for feature extraction</strong> and <strong>traditional machine learning for classification</strong>. While the current results leave room for improvement, the pipeline lays a solid foundation to explore more advanced architectures and training techniques.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DWj5BAhw7HDEBWtepdpsw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0b8bd4971ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Now AI can tell when you’re ‘excited’ about Monday….]]></title>
            <link>https://chinmayacharya28.medium.com/now-ai-can-tell-when-youre-excited-about-monday-66172a8c6fe4?source=rss-7185f9f22385------2</link>
            <guid isPermaLink="false">https://medium.com/p/66172a8c6fe4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[CHINMAY ACHARYA]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 18:25:01 GMT</pubDate>
            <atom:updated>2025-08-03T18:25:01.777Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we’re building a model to detect whether a sentence is sarcastic or not, using <strong>Bidirectional LSTMs (Long Short-Term Memory)</strong>.</p><blockquote><strong><em>sarcasm</em></strong><em> : The use of remarks that clearly mean the opposite of what they say, made in order to hurt someone’s feelings or to criticise something in a humorous way…</em></blockquote><blockquote>Eg : “You have been <a href="https://dictionary.cambridge.org/dictionary/english/working">working</a> hard,” he said with <a href="https://dictionary.cambridge.org/dictionary/english/heavy"><strong>heavy</strong></a> sarcasm, as he <a href="https://dictionary.cambridge.org/dictionary/english/look">looked</a> at the <a href="https://dictionary.cambridge.org/dictionary/english/empty">empty</a> <a href="https://dictionary.cambridge.org/dictionary/english/page">page</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZH09RXGucYs4npvjhnxuw.jpeg" /></figure><p>To accomplish this, we’ll use <strong>Python</strong> as our scripting language, and for our dataset, we’ll rely on <strong>news headlines</strong> collected from two sources:</p><p>1. <a href="http://theonion.com/"><em>theonion.com</em></a> (a satirical news site)<br>2. <a href="http://huffingtonpost.com/"><em>huffingtonpost.com</em></a><em> </em>(a standard news outlet)</p><blockquote><em>Dataset Reference : </em><a href="https://github.com/rishabhmisra/News-Headlines-Dataset-For-Sarcasm-Detection">https://github.com/rishabhmisra/News-Headlines-Dataset-For-Sarcasm-Detection</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNTvLkUa8F5GaTnq8qhg0g.png" /></figure><p><strong>Step 1. Input (Load the data) :</strong><br>We’ll begin by downloading the Sarcasm_Headlines_Dataset.json file as our dataset.</p><p>To load this data, we’ll use the following Python packages:</p><ul><li>pandas</li><li>tensorflow</li><li>numpy</li></ul><p>While typical imports like os, json, etc. are assumed, here’s a quick snippet specifically for loading the JSON file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjqgdJCbuvilXCmt1kc2-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Pf_ic7HTpG45Smul8kgeA.png" /></figure><p>Next, let’s calculate the length of each sentence. This will help us later when padding sequences in TensorFlow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*f9NrpxpbW1WlNxcOS4rRVA.png" /></figure><p><strong>Step 2. Let’s add Tokenisation and Padding</strong></p><p>In Python, T<strong>okenisation</strong> is the process of breaking down text into smaller units called <em>tokens</em>. These can be:</p><ul><li>Words</li><li>Punctuation marks</li><li>Numbers</li></ul><p>It’s a fundamental step in <strong>Natural Language Processing (NLP)</strong>.</p><p>We’ll use TensorFlow’s Tokenizer from the tensorflow.keras.preprocessing.text module, which helps us convert text into numerical sequences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qIr8r_-MnfVGpyheaSGDVQ.png" /><figcaption><strong>Output : Number of Samples: 28619<br>First sequence: [354, 3166, 7473, 2643, 2, 660, 1118]</strong></figcaption></figure><p>To feed data into an LSTM, all sequences must have the <strong>same length</strong>.<br> We’ll use pad_sequences to:</p><ul><li>Convert lists of varying-length tokens into a uniform 2D NumPy array.</li><li>Add padding (usually zeros) either before or after each sequence.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shhlfdTtt5mxEWwHRGgMYQ.png" /><figcaption><strong>Output : Number of Labels: 28619<br>First label: 1<br>Features shape: (28619, 25)<br>Labels shape: (28619,)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*-p0XfsXQuYybLarrB7fYmQ.png" /></figure><p><strong>Step 3: Find the vector representation</strong></p><p>To represent words meaningfully as vectors, we use <strong>GloVe embeddings</strong>.</p><p><strong>GloVe (Global Vectors for Word Representation)</strong> captures relationships between words based on co-occurrence statistics from large text corpora.<br>It helps the model understand semantic relationships</p><blockquote>For example, the vector difference between “king” and “queen” might be similar to the difference between “man” and “woman”.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3I5ulxrBFRDPr25vg2Sm_w.png" /></figure><p>We are using small set for now that is <a href="https://nlp.stanford.edu/projects/glove/"><em>glove.6B.zip</em></a><em> </em>and adding that locally inside the project,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*mfv99cFhjFPWicxog-iY4g.png" /><figcaption>Vocabulary size: 30885</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJuFTuWrv6vbFkoe0uG1Og.png" /><figcaption><strong>GloVe embeddings loaded successfully<br>Embedding matrix shape: (30885, 200)</strong></figcaption></figure><p><strong>Step 4 : Define a Bidirectional LSTM Model</strong></p><p>A bidirectional LSTM (BiLSTM) sequential model is a type of recurrent neural network that processes input sequences in both forward and backward directions. This allows it to capture contextual information from both the past and the future, improving performance on tasks that rely on understanding relationships within sequences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*dQouzqpanIISibAixZFZ1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqLMcQ1apYxCT9EJgy9iiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dopJ4FEKzzgwqnp1x8SIRg.png" /></figure><p>After compiling the sequential model will be look like that…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wk_GN0952cFmJaBViL4edQ.png" /></figure><h3>The takeaway 😉</h3><p>We trained a model to detect sarcasm using headlines, and guess what? It <em>finally</em> understands that “Great, another Monday” doesn’t mean you’re excited. With Bidirectional LSTMs and GloVe embeddings doing the heavy lifting, our model now speaks fluent.</p><p>you can check out my other blogs which explore the role of<a href="https://medium.com/@chinmayacharya28"> machine learning</a> in the health and sports department.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Is4siEvskpKNHxVj01HlLQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66172a8c6fe4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to detect visual signals of Pneumonia using AI?]]></title>
            <link>https://chinmayacharya28.medium.com/how-to-detect-visual-signals-of-pneumonia-using-ai-8105d120638?source=rss-7185f9f22385------2</link>
            <guid isPermaLink="false">https://medium.com/p/8105d120638</guid>
            <category><![CDATA[visual-computing]]></category>
            <category><![CDATA[decision-science]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[CHINMAY ACHARYA]]></dc:creator>
            <pubDate>Sun, 08 Nov 2020 10:27:58 GMT</pubDate>
            <atom:updated>2025-08-03T18:27:44.729Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Pneumonia</strong> is an infection that inflames the air sacs in one or both lungs. The air sacs may fill with fluid or pus (purulent material), causing coughing with phlegm or pus, fever, chills, and breathing issues. A variety of organisms, including bacteria, viruses and fungi, can cause pneumonia. It can cause mild to life-threatening illness in people of all ages and is the single largest infectious cause of death, worldwide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*buNhPSprUWbaHcdXqxi04w.jpeg" /></figure><blockquote>Challenge Reference :<a href="https://www.kaggle.com/c/rsna-pneumonia-detection-challenge/data">https://www.kaggle.com/c/rsna-pneumonia-detection-challenge</a></blockquote><p>In this blog, we will build models to detect a visual signal for pneumonia. To do so, the algorithm needs to automatically locate lung opacities on chest radiographs. To build this model, I am using <a href="https://www.python.org/"><strong>Python</strong></a> as a scripting language and data from Kaggle site.</p><p><a href="https://www.kaggle.com/c/rsna-pneumonia-detection-challenge/data"><strong>Data</strong></a><strong> from Kaggle:</strong></p><p>1.<strong> </strong>Training Images — DICOM format</p><p>2. Testing Images — DICOM format</p><p>Images are in DICOM (Digital Imaging and Communications in Medicine) format and are represented as “.dcm.”. Now that we have everything ready, it’s time to get started!</p><h4>1. Load the data</h4><p>First, we need to show the images needed to import the required packages. These packages will help us to load the data and show the visual signals. We are using the following packages <strong>google.colab, os, zipfile, pandas, pydicom. </strong>As we are aware of other common packages imports. Here, I am just adding a snippet for pydicom. After the below step we will get all the attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*y7GwIUBo5K0djxrUW6ynUQ.png" /><figcaption>Importing the csv file.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*TnZrHcgWkZ8yADt_e8o8zQ.png" /><figcaption>Importing the dicom images.</figcaption></figure><p>The below step will load all the data to data frames.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*rZmbnk2tjDRUoavzlLVuow.png" /></figure><p>Now, we need to check the shape, unique values and <em>null</em> attributes. So, as we process the above small data analysis steps, we will create a training data frame. After which we will perform unique values operation again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*dpcd9-XJPl5Gjs_Pz_ndkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*yIfmZoq-UCFh5g9sakBrsw.png" /></figure><p>At this point, your training data frame is set for the visualization.</p><h4>2. Visualize relationships between attributes</h4><p>We will just use the required attributes to process further. ‘PatientId’, ‘Age’, ‘Gender’, ‘ViewPosition’, and ‘PixelSpacing’ are few of the attributes we will analyze. As we have already learned from the last blogs, we need to import some of the graphical packages like <strong>matplotlib, pyplot, &amp; seaborn.</strong></p><p>Using the above libraries and attributes we can show the categorical statistics very easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*O_bBHF2u14tyg4zd8Ur4_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*tNl3ydPSBWX9hUqVgIGsdQ.png" /></figure><p>As we are finished with the categorical representation, we can show the received dicom images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*hYfMJ4pyYx60Cq_jOl9IpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*kscVSrS4mJUzKxEvZ3x4zQ.png" /></figure><p>Now, we are set to find the visual patches of lung opacity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*Qhs2T39qyC7Wjdo2e-FE-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*81sfWCum-bwJPg02waUj0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*IUe_P_C-VorCqV_uSmTxJg.png" /></figure><p>Here, we can see all the visual patches which indicate Pneumonia.</p><h3>The takeaway</h3><p>As you can see in the radiographs, we have correctly predicted the presence of pneumonia patches. You can further work on modeling to predict the probability of a person suffering from Pneumonia, more accurately.</p><h4>Stay Healthy &amp; Safe!</h4><p><strong>P.S.</strong> I will be sharing the entire code soon. In the meantime, you can check out my other blogs which explore the role of<a href="https://medium.com/@chinmayacharya28"> machine learning</a> in the health and sports department.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8105d120638" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use machine learning to detect diabetes]]></title>
            <link>https://chinmayacharya28.medium.com/how-to-use-machine-learning-to-detect-diabetes-445e06147500?source=rss-7185f9f22385------2</link>
            <guid isPermaLink="false">https://medium.com/p/445e06147500</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[logistic-regression]]></category>
            <dc:creator><![CDATA[CHINMAY ACHARYA]]></dc:creator>
            <pubDate>Wed, 29 Jan 2020 02:07:23 GMT</pubDate>
            <atom:updated>2020-01-29T16:50:51.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*ytDmzdAKqLmmAW7lzn3iQg.jpeg" /></figure><blockquote><strong>“</strong>If we can reduce the cost and improve the quality of medical technology, we can more widely address the medical conditions that are prevalent and reduce the level of human suffering.<strong>”</strong></blockquote><p>In today’s age where most of us are relentlessly working on setting and achieving our goals — be it a bigger house, better job, better salary — there is one aspect we often overlook: our health.</p><p>Being healthy is not just vital for achieving our goals and facing adversaries; it also often contributes to the quality of life we live. Because of this, the necessity for having a modern health care system that correctly diagnoses medical conditions early on and help doctors treat them has become more prominent than ever. Apart from the traditional options, there is one more avenue which we can explore to address this necessity and that’s of course, machine learning implementation in health care.</p><p>According to the <a href="https://www.statista.com/statistics/271464/percentage-of-diabetics-worldwide/">Statics</a>, Around 9.3 percent of the global adult population suffered from diabetes in 2019 — by the year 2045 this number is expected to rise to almost 11 percent These overwhelming numbers and my past experience with machine learning modelling, made me wonder if we can harness the power of machine learning to detect diabetes. The aim for this experiment is to develop an automated mathematical model which accurately detects whether a person is suffering from diabetes based on his health statistics and historical data of other patients.</p><p>Here’s the conceptual diagram of the proposed mathematical model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Kcw9uR5m8Glc6OaeGOBXUg.jpeg" /></figure><p>To implement this mathematical model, I am using<a href="https://www.python.org/"> <strong>Python</strong></a> as a scripting language and mock diabetes statistics.</p><p>Now that we have everything we need, it’s time to get started!</p><h3>Step 1: Get the dataset ready</h3><p>For the purpose of this experiment, I am mocking only essential data. If you have the APIs of the relevant stats, you can use them instead for more accurate results.<br>In order to ensure that our model’s detection accuracy is as high as possible, we will use the following factors while making the prediction.</p><ul><li>Glucose</li><li>Blood pressure average</li><li>Insulin</li><li>BMI</li><li>Diabetes history stats (A function which determines the likelihood of diabetes based on patient’s family history)</li><li>Age</li><li>Detection</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/0*7maBMOWu_Qbligzp" /></figure><h3>Step 2: Put on your coding hat</h3><p>I have used Python as the scripting language. Being fairly new to Python, I have used<a href="https://docs.anaconda.com/anaconda/install/verify-install/"> </a><a href="https://jupyter.org/">Jupyter</a> Notebook.</p><h4>2.1 Import required packages</h4><p>The Anaconda environment provides some basic packages like ‘NumPy’, ‘Pandas’, ‘Json’, ‘Matplotlib’, and ‘Seaborn’. If you want to use APIs to fetch the data from your server, you can use the ‘Requests’ package. For training and testing set, you can use the ‘train_test_split’ and ‘sklearn’ package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/0*NAW3jMwaCD3cRNSs" /></figure><h4>2.2 Read the data from mock data set</h4><p>Now, It’s time to fetch the mock data we had added in the Excel sheet. You can alternatively use CSV or databases too.</p><p>Next, we will fetch the mock data using ‘Pandas’ package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/0*EJYNJ8bHlQVnSmdb" /></figure><h4>2.3 Print the detection results</h4><p>Let’s find out the detection results we have received for the historical data. Here, the number ‘1’ in ‘Detection’ column represents positive detection and ‘0’ represents negative detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*nWb0PSYUKso2Odvt" /></figure><h4>2.4 Divide the data into training and testing sets</h4><p>The ‘<strong>training data set’</strong> is the general term for the samples used to create the model, while the ‘<strong>test</strong> <strong>data set’</strong> is used to qualify performance. The observations in the training set form the experience that the algorithm uses to learn whereas, the test set is a set of observations used to evaluate the performance of the model using some performance metric.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/0*4b1QwTQx5krQsB20" /></figure><h4>2.5 Find the accuracy of training and testing sets</h4><p>Now, let’s find out the accuracy of existing training and testing sets. After this find out let’s focus on our implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/0*mmuBjeRbSMVuKg9h" /></figure><h4>2.6 Prepare Training and Testing set by dropping the ‘Detection’ column</h4><p>Let’s start preparing the Training set and Test Set. The Training set will be used for the model evaluation and Test set will be used for production verification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/0*PCrJDNT0G0ACM6vj" /></figure><p>To do this, I have dropped the ‘Detection’ column. I have divided these sets with a 70:30 ratio where the Training set contains 70% data and the Test set contains 30% data.</p><h4>2.7 Handle NULL values in data</h4><p>Since we are using mock data for model creation, it may contain some null values. To handle these null values, we are going to set column mean value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*Je1_oCrVbVa1xIhl" /></figure><h4>2.8 Apply Logistic Regression</h4><p><a href="https://en.wikipedia.org/wiki/Logistic_regression"><strong>Logistic Regression</strong></a> is a statistical model that in its basic form uses a <strong>logistic</strong> function to <strong>model</strong> a binary dependent variable, although many more complex extensions exist. In regression analysis, logistic regression is estimating the parameters of a logistic model.</p><blockquote>Formula : g(E(y)) = α + βx1 + γx2</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*LJf_R37lBBSuPLE2" /></figure><h4>2.9 Use Confusion Matrix to verify detection</h4><p>In the field of machine learning and specifically the problem of statistical classification, a confusion matrix, also known as an error matrix, is a specific table layout that allows visualization of the performance of an algorithm. Confusion matrix contains four conceptual visual for algorithm.</p><ol><li>True Positive</li><li>True Negative</li><li>Type I Error (False Positive)</li><li>Type II Error (False Negative)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/0*aqFwF8v-UUE23g7G" /></figure><p>Let’s apply this confusion matrix on our training and testing sets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/0*mrjZCOxa1AbilJEq" /></figure><p>Let’s check our confusion matrix to make observations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*HB3hGSexiCc0WnWc" /></figure><p>Observations :</p><ul><li>True Positives (TP): We correctly predicted that 19 people have diabetes.</li><li>True Negatives (TN): We correctly predicted that 65 people don’t have diabetes.</li><li>Type I error (FP): We incorrectly predicted that 9 people have diabetes.</li><li>Type II error (FN): We incorrectly predicted that 15 people don’t have diabetes.</li></ul><h3>Step 3: Find the score of model for conclusion</h3><p>After defining model and testing on training set, it is necessary to find out the accuracy or score of the model. Let’s find out our model score on test set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/0*jKuFKKn5N7hMh1Sr" /></figure><p>As we are creating a model for healthcare stream, it is really important that model score and accuracy has to be 99% to 100% . Only then can we apply this model on the actual environment. <br>So, we need to work on our model, equation, and actual stats to reach the desired accuracy level.</p><h3>The takeaway</h3><p>This was just a small experiment which showed that machine learning can be used to create highly efficient models which can cater to the healthcare industry. With the kind of promise being shown by machine learning, it won’t be far fetched to say that we can start using machine learning models along with the traditional methods to detect and cure medical conditions faster, in the near future.</p><p><strong>P.S.</strong> I will be sharing the entire code soon. In the meantime, you can check out my other blog which explores the role of <a href="https://medium.com/@chinmayacharya28/how-to-predict-the-winner-using-a-simple-piece-of-code-1f1bd563ae7a">machine learning in Sports</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*tfDhmkvQr0bSs87_I8RwHA.jpeg" /><figcaption><strong>Stay Healthy!</strong></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=445e06147500" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to predict the winner using a simple piece of code ]]></title>
            <link>https://chinmayacharya28.medium.com/how-to-predict-the-winner-using-a-simple-piece-of-code-1f1bd563ae7a?source=rss-7185f9f22385------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f1bd563ae7a</guid>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[winner]]></category>
            <category><![CDATA[predictions]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[CHINMAY ACHARYA]]></dc:creator>
            <pubDate>Mon, 30 Sep 2019 06:01:54 GMT</pubDate>
            <atom:updated>2019-09-30T06:33:09.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ee6_29sFsuLKVc-ZHJlWRA.jpeg" /></figure><p>What is the most valuable thing in the world right now? oil, gold, diamonds? While these are all great candidates, the only thing that surpasses them is ‘Data’. For a long time now, data has been the oil that is running tech, healthcare, marketing, entertainment, and other such industries smoothly. In today’s fast-paced world where customers are spoilt for choice, a single error in data analytics can cost you dearly. Because of this, the importance of harnessing and processing data accurately has increased significantly.</p><p>One such industry where data plays a crucial role is of course, ‘Sports’. Name any sport, and you will realize that it is mostly driven by numbers and statistics. And once you deep-dive in the world of sports statistics, there is one avenue you are bound to take: Winner prediction!</p><p>My interest in the NBA games and statistic nudged me to try my hand at winner prediction by analyzing the available data. I am aiming to make the winner prediction for the upcoming NBA games based on the overall performance and aggregate of each team with respect to their opponent. You can alternatively apply this method on any other sport, teams, or players to predict the outcome, as per your interest. It must be noted however, that sports is not just about statistics; it’s also about spur-of-the-moment decisions, missed opportunities, and last-minute heroics. So, the aim of this method is to judge the approximate winning chances of a team on any given day.</p><p>To do this, I am using<a href="https://www.python.org/"> <strong>Python</strong></a> as a scripting language and mock<a href="https://in.nba.com/?gr=www"> <strong>NBA</strong></a> data (created using 2018 season). Now that we have everything ready, it’s time to get started!</p><h3>Step 1: Get the dataset ready</h3><p>For the purpose of this experiment, I am mocking only essential data. If you have the APIs of the relevant sport, you can slice the data and use it instead. We would need to mock two sets of data:</p><p><strong>1. Team’s basic data: </strong>Containing the basic info about the participating teams</p><p><strong>2. Team’s historic data: </strong>Containing the previous season/tournament statistics for each team</p><h4>1. Team’s basic data</h4><p>In order to predict the winner, we would need a list of teams and their basic details. For now, I am using the TeamID and TeamName fields for mocking and adding them to an Excel sheet. You can optionally use additional fields such as TeamColor, TeamArena/TeamStadium too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*SO2SpqR4yHRvGxxsZtDkOg.png" /></figure><h4>2. Team’s historic data</h4><p>Apart from each team’s basic info, we would also need their past season/tournament statistics to make predictions. I would recommend using large data sets to achieve maximum accuracy. For now, I am mocking data for the following fields only:</p><p>gameID, homeTeamScore, homeTeamID, visitorTeamScore, visitorTeamID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*PkohCq9GP2KxJvazoUFpLg.png" /></figure><h3>Step 2: Put on your coding hat</h3><p>I have used Python as the scripting language. Being fairly new to Python, I have used <a href="https://docs.anaconda.com/anaconda/install/">Anaconda</a> navigator and<a href="https://jupyter.org/"> Jupyter</a> Notebook.</p><h4>2.1 Import required packages</h4><p>The Anaconda environment provides some basic packages like ‘NumPy’, ‘Pandas’, ‘Json’, ‘Matplotlib’, and ‘Seaborn’. If you want to use APIs to fetch the data from your server, you can use the ‘Requests’ package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*2ChcrWSjVmVu4HpYvnx46g.png" /></figure><h4>2.2 Initialize or fetch prediction game</h4><p>Let’s say we want to predict the winner for the next match between Atlanta Hawks vs Miami Heat (TeamID 101 vs TeamID 112). To do so, we will first set the variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*v4s9sj8TWrWqgVGRHSlliw.png" /></figure><h4>2.3 Fetch data to start</h4><p>Now, It’s time to fetch the mock data we had added in the Excel sheet. You can alternatively use CSV or databases too.</p><p>Next, we will fetch the mock data using ‘Pandas’ package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*-miLqDj5owh_E_AKaHXOzQ.png" /></figure><h4>2.4 Analyze and calculate games played and games won by each team</h4><p>To calculate the win games and played games for Miami Heat (Team1), we need to slice the mock data into sections. In sections, we found three subsets:</p><p>Subset A: Refers to the games played by Miami Heat (Team1)</p><p>Subset B: Refers to the games played by Atlanta Hawks (Team 2)</p><p>Intersection subsubset: Contains the common elements from Subset A and Subset B, i.e., games played by Miami Heat and Atlanta Hawks against each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*7Bt5hkHM2rqYvIDBAkyK-g.gif" /></figure><p>In a similar manner, we need to make slices from all data for the corresponding teams using the ‘Pandas’ packages. For data distribution, you need to simply check whether the respective team id is present in the home side or visitors side, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*RAYtPYZY7Oh5lASZV8MDcg.png" /></figure><p>Next, we need to calculate the total wins of each team using <strong>dataframes functions </strong>and <strong>total number of rows</strong>.</p><figure><img alt="Team1 subset from whole data" src="https://cdn-images-1.medium.com/max/754/1*1SH1kz_pIdqpPmx5uxikUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*89kNToDLnqhnzYcKqrrKsQ.png" /></figure><p>At this point, based on the overall team performance, you can get some insight on which team is most likely to win. But this is restricted to only each team’s individual performance. We would also need to take into account each team’s previous statistics against their opponent.</p><h4>2.5 Analyze performance with opponent</h4><p>In this section, we will analyze the total games played and total games won by each team against their opponent. This data bifurcation will be done based on the TeamIDs. So, in our example, Miami Heat (101) and Atlanta Hawks (102) has to belong to either homeTeamID column or visitorTeamID column.</p><h4>Perform the mathematical operations to get a graphical result</h4><p>Now that we know the total games played and total games won by both teams in the past tournaments, and total games played and total games won against each other, all we need to do is calculate the percentage. I have used the ‘Seaborn’ package to display the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*OZTpHFSPoS3rp-4K" /></figure><p>Print the result to predict the winner using a combination of ‘Seaborn’, ‘Matplotlib’, and ‘Pandas’ packages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/0*fT6xKkklLeFDWEiR" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*Nhj46B2wYa9wCIov" /></figure><h3>Step 3: Predict the winner</h3><p>Now that we have all the necessary data at hand, that too in a graphical format, we can easily predict the winner.</p><h4>Overall winner prediction</h4><p>When you check the comparison graph for both team’s overall performance, Miami Heat seems to be doing slightly better than Atlanta Hawks, and hence is more likely to win.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*vW6beNszj09HMPyF" /></figure><h4>Head-to-head winner prediction</h4><p>When you consider the head-to-head statistics and past records of Miami Heat and Atlanta Hawks, you can see that Atlanta Hawks emerge as the runaway winners!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*hpUAX9N4F92PGbGw" /></figure><h3>The takeaway</h3><p>As you can see, based on the historical data you can predict which team has the most chances of winning a particular game, but then again, with sports, you never know when a moment of brilliance or misjudgment can change the course of the game. So simply try to predict the outcome as best as you can, and then just enjoy the game!</p><p><strong>P.S.</strong> If you want to deep dive in the code, click <a href="https://github.com/ChinmayAcharya28/Winner-Predictor">here</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f1bd563ae7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>