<?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 Anik Manik on Medium]]></title>
        <description><![CDATA[Stories by Anik Manik on Medium]]></description>
        <link>https://medium.com/@iamanik4?source=rss-df7fd58b7c81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f0az6QWntF-7zB_KH6bbog.jpeg</url>
            <title>Stories by Anik Manik on Medium</title>
            <link>https://medium.com/@iamanik4?source=rss-df7fd58b7c81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:34:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamanik4/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[Detection and Semantic Segmentation of Pneumothorax Disease from X-Ray Images using Deep Learning]]></title>
            <link>https://medium.com/analytics-vidhya/detection-and-semantic-segmentation-of-pneumothorax-disease-from-x-ray-images-using-deep-learning-890bbfcb5bd6?source=rss-df7fd58b7c81------2</link>
            <guid isPermaLink="false">https://medium.com/p/890bbfcb5bd6</guid>
            <category><![CDATA[semantic-segmentation]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[unet]]></category>
            <category><![CDATA[densenet121]]></category>
            <category><![CDATA[pneumothorax]]></category>
            <dc:creator><![CDATA[Anik Manik]]></dc:creator>
            <pubDate>Mon, 29 Mar 2021 04:57:45 GMT</pubDate>
            <atom:updated>2021-06-23T16:38:52.159Z</atom:updated>
            <content:encoded><![CDATA[<p>Build a binary image classification model to detect if the image contains pneumothorax. If yes, then pass it through a semantic segmentation model to identify and mark the affected part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2Q6DGutG8AYqGxEcGekVw.jpeg" /><figcaption>Source: <a href="https://www.svhlunghealth.com.au/conditions/pneumothorax">https://www.svhlunghealth.com.au/conditions/pneumothorax</a></figcaption></figure><p><strong>Table of Contents:<br></strong>1. Introduction<br>2. Types of Pneumothorax Disease<br>3. Symptoms <br>4. Diagnosis<br>5. Business Problem<br>6. DL Formulation<br>7. Business Constraints<br>8. Dataset Column Analysis<br>9. Performance metric<br>10. Exploratory Data Analysis<br>11. Existing Approaches and Improvements in my model<br>12. Data Preprocessing<br>13. Deep Learning Models<br>14. Final Data Pipeline <br>15. Error Analysis<br>16. Future work<br>17. LinkedIn and GitHub Repository<br>18. Reference</p><h3>1. Introduction:</h3><p><strong>What is Pneumothorax disease?<br></strong>A pneumothorax is when the lung has collapsed due to air entering the space around your lungs (known as the pleural space). In a healthy body, the lungs are touching the walls of the chest. Air can enter the pleural space through an opening in your chest wall or in the lung. Air in the pleural space creates an increase in pressure around the lung and causes it to collapse. The lung may fully collapse, but most often only a part of it collapses. This collapse can also put pressure on the heart, causing further symptoms.</p><p>A pneumothorax can be severe, depending on how much air is trapped in the pleural space. A small amount of trapped air can usually resolve by itself, provided there are no other complications. Larger amounts of trapped air can be serious and lead to death if medical treatment is not obtained.</p><h3>2. Types of Pneumothorax Disease</h3><p>There are mainly 4 types of pneumothorax observed.</p><p><strong>a) Primary spontaneous:<br></strong>Primary spontaneous pneumothorax(PSP) occurs in young people (aged 15–34) without any history of lung disease. The direct cause of PSP is unknown. People at risk include smokers, tall men, and those who have had a family member with a pneumothorax.</p><p><strong>2. Secondary spontaneous:<br></strong>Secondary spontaneous pneumothorax (SSP) can be caused by a variety of lung diseases(such as chronic obstructive pulmonary disease, cystic fibrosis, tuberculosis, pneumonia, lung cancer, sarcoidosis, pulmonary fibrosis or cystic lung diseases) and tissue disorders(such as Marfan’s Syndrome). SSP carries more serious symptoms than PSP, and it is more likely to cause death.</p><p><strong>3. Traumatic pneumothorax:<br></strong>A traumatic pneumothorax is the result of an impact or injury. Potential causes include blunt trauma or an injury that damages the chest wall and pleural space. One of the most common ways this occurs is when someone fractures a rib. The sharp points of the broken bone can puncture the chest wall and damage lung tissue. Other causes include sports injuries, car accidents, and puncture or stab wounds.</p><p><strong>4. Tension pneumothorax:<br></strong>Tension pneumothorax is caused by a leak in the pleural space that resembles a one-way valve. As a person inhales, the air leaks into the pleural space and becomes trapped. It cannot be released during an exhale. This process leads to increased air pressure in the pleural space that is life-threatening and needs immediate treatment.</p><h3>3. Symptoms:</h3><p>a) Shortness of breath<br>b) Abnormally fast heart rate (known as tachycardia)<br>c) Chest pain, which may be more severe on one side of the chest<br>d) Sharp pain when inhaling<br>e) Blue discoloration of the skin or lips<br>f) Cold sweats<br>Some cases of pneumothorax have almost no symptoms. These can only be diagnosed with an X-ray or another type of scan.</p><h3>4. Diagnosis:</h3><p>Diagnosis of a pneumothorax is typically done via a <strong>chest X-ray</strong>, which takes images to detect the presence of air in the pleural space (the area around the lungs). A CT scan and thoracic ultrasound can also be used to help diagnose a pneumothorax.<br>A doctor (radiologist) then examines the X-ray report to diagnose pneumothorax and the affected area.</p><h3>5. Business Problem:</h3><p>Pneumothorax is typically detected on chest X-ray, examined by a doctor or a radiologist. But this requires manual effort. Since current imaging volumes are large in number, it takes a long time to review every image and prepare a report. Pneumothorax can cause life-threatening emergency due to lung collapse and respiratory or circulatory distress if it is not detected early.</p><p>Our objective is to build an automated method to predict X-rays with pneumothorax and segmentize the affected area. This will help to prioritize the treatment of patients with pneumothorax. Automatic image segmentation can assist doctors in the treatment and diagnosis of diseases with higher accuracy, accelerate the diagnosis process, and improve efficiency.</p><h3>6. DL Formulation:</h3><p>As we have images with and without pneumothorax, we will build a classification model first then a semantic segmentation model.<br><strong>a) Classification Model:</strong><br>Build a binary image classification model first to predict if the image contains pneumothorax. I will use given images and class labels to train my classification model.<br><strong>b) Semantic Segmentation Model: <br></strong>Our task is to predict the mask affected by pneumothorax. This is a semantic segmentation problem. If the classification model predicts a positive result, then pass the image through another semantic segmentation model to mark the pneumothorax affected area. I will use the given images and RLE masks to train my model.</p><p><strong>What is image segmentation?<br></strong>Image segmentation is a task where we classify pixel values of images belonging to a particular object class. So based on the way of classifying these pixels there are broadly two types of Segmentation.<br><strong>I)</strong> Semantic segmentation and <strong>II)</strong> Instance segmentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YzDx4ZKI2WDFetUvMCzT5A.jpeg" /></figure><p><strong>I) Semantic Segmentation: <br></strong>In semantic segmentation, every pixel belongs to a particular class (either background or person). Also, all the pixels belonging to a particular class are represented by the same color (background as black and person as pink).</p><p><strong>II) Instance Segmentation:<br></strong>In instance segmentation also every pixel belongs to a particular class. However, different objects of the same class have different colors i.e different class labels (Person 1 as red, Person 2 as green, background as black, etc.).</p><p>As mentioned earlier, our problem is a semantic segmentation problem where we have to predict every pixel either mask or background.</p><h3>7. Business Constraints:</h3><p>a) There are no such latency constraints for this problem but the model should predict within few minutes.<br>b) Along with class label prediction, the model should segmentize the pneumothorax affected area.</p><h3>8. Dataset Column Analysis:</h3><p><strong>Source of Data: </strong>The dataset is given on Kaggle&#39;s website. Please find the link below.</p><ul><li><a href="https://www.kaggle.com/c/siim-acr-pneumothorax-segmentation/data">SIIM-ACR Pneumothorax Segmentation</a></li><li><a href="https://www.kaggle.com/seesee/siim-train-test">SIIM_TRAIN_TEST</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*oZXPvyd8SC3jAzC4irg02g.jpeg" /><figcaption><strong>Given Dataset</strong></figcaption></figure><p>The given data consists of ImageId and EncodedPixels. For every ImageId, we have an image in DICOM format. EncodedPixels with ‘-1’ value indicates the image is without pneumothorax. Images with pneumothorax have masks in run-length-encoded (RLE) format. We have to decode and create the mask.</p><h3>9. Performance metric:</h3><p><strong>a) Classification Model:<br></strong>I will measure the performance of the classification model based on <strong>“Recall”</strong>. In the pneumothorax detection problem, it is okay to predict a negative pneumothorax as positive because when it will be passed to the next segmentation model, most probably it will predict a blank mask. But, if a positive case is detected as negative it will not even pass through the segmentation model and the patient will suffer.<br>As this is a binary classification problem, I will take <strong>“binary_crossentropy”</strong> as the loss function.</p><p><strong>b) Segmentation Model:<br></strong>I have given the images along with masks. I have to train a model using that data and predict masks for the test data. So, this is a Semantic Image Segmentation problem.<br>In this Semantic Image Segmentation problem, I am going to measure the performance of the model based on the <strong>“IOU score”</strong>. I will use a <strong>combination of “binary_crossentropy” and “dice_loss”</strong> as loss functions. These terms are explained below.</p><p><strong>I. Intersection over Union (IoU) Score:<br></strong>The Intersection over Union (IoU) metric, also referred to as the Jaccard index. This is a method to quantify the percent overlap between the target mask and our prediction output. This metric is closely related to the Dice coefficient.<br>The IoU metric measures the number of pixels common between the target and prediction masks divided by the total number of pixels present across both masks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/0*EnmgImGE6M69JyI7.jpg" /></figure><p><strong>II. Pixel-wise cross-entropy loss:<br></strong>This loss examines each pixel individually, comparing the class predictions (depth-wise pixel vector) to our one-hot encoded target vector.<br>Pixel-wise loss is calculated as the log loss summed over all possible classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xnKm4Fhf_oTJkobf.jpg" /></figure><p><strong>III. Dice loss:<br>Dice Loss = 1-Dice Coefficient</strong><br>Where Dice Coefficient(D) =</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*tFdAwXerycv7rcHwtEq49g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*y9V50q0ys-xHT652YdmUTw.jpeg" /></figure><p>Here, pi = predicted pixel values.<br>gi = groung truth pixel values.<br>In the image segmentation scenario, the values of pi and gi are either 0 or 1.<br>1 → pixel is a boundary<br>0 → pixel is not a boundary<br>In the dice coefficient,<br>Numerator → 2 * Sum of correctly predicted boundary pixels. (when pi and gi both are 1)<br>Denominator → Sum of total boundary pixels of both predicted and ground truth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b5bzq29pO5j2GAf9.jpg" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b81d2f5d02685f77cd259e795168b62/href">https://medium.com/media/5b81d2f5d02685f77cd259e795168b62/href</a></iframe><h3>10. Exploratory Data Analysis:</h3><p>First, perform some basic data cleaning operations on the given data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*Hpjxa6-Klis5xWAYR6p23w.jpeg" /></figure><p>Out of 12954 image-ids, 12047 are unique. It means there are duplicates. So, I have to remove the duplicate image-ids.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e53de8459be998ff8adce265e3f92ec2/href">https://medium.com/media/e53de8459be998ff8adce265e3f92ec2/href</a></iframe><p>The images are given in DICOM format. We have to extract the information from the metadata for EDA. The metadata of a sample image is printed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*tte_cYiJAeuUcml68Wo4nA.jpeg" /></figure><p><strong>Extract some information from metadata: </strong>Extract age, sex, modality, body part, and view position of every image given. I will use this data for EDA.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c6496d05b339d9bd0e926ab8e581dd4/href">https://medium.com/media/9c6496d05b339d9bd0e926ab8e581dd4/href</a></iframe><p><strong>a) Distributions of Class Labels:</strong></p><p>If the RLE mask field for an image is “-1”, then this is negative pneumothorax otherwise positive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*a1fUlvURP9dojeXUs5f7xA.jpeg" /></figure><p><strong>Observation:<br></strong>This is an imbalanced dataset. Among all the x-ray images 77.85% are without Pneumothorax and 22.15% are with pneumothorax.</p><p><strong>b) Distribution of Gender:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*CJumop-TbmXZG_G9WNIhIg.jpeg" /></figure><p><strong>Observation:<br></strong>There are 55% male patients and 45% female patients in the given dataset.</p><p><strong>c) Distribution of Gender along with Class Label:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFUCiKbqJXgYkbS1kvy30Q.jpeg" /></figure><p><strong>Observation:<br></strong>Among all the male patients 77.53% are without pneumothorax and 22.47% are with pneumothorax and among all the female patients 78.23% are without pneumothorax and 21.77% are with pneumothorax. Pneumothorax distribution is almost similar for both male and female patients.</p><p><strong>d) Distribution of View Position:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*R2xa3Siu8PUp9kbhARts7w.jpeg" /></figure><p><strong>Posteroanterior view (PA):<br></strong>The x-ray source is positioned so that the x-ray beam enters through the posterior (back) aspect of the chest and exits out of the anterior (front) aspect, where the beam is detected.<br><strong>Anteroposterior view (AP):<br></strong>The x-ray source and detector are reversed: the x-ray beam enters through the anterior aspect and exits through the posterior aspect of the chest. AP chest x-rays are harder to read than PA x-rays and are therefore generally reserved for situations where it is difficult for the patient to get an ordinary chest x-ray, such as when the patient is bedridden.</p><p><strong>Observation:<br></strong>In the dataset for 60.38% of images view position is PA and 39.62% of images view position is AP.</p><p><strong>e) Distributions of Patient’s Age for different Class Labels:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQSSzzF1IBpyHTTtZhf0jA.jpeg" /></figure><p><strong>Observation:<br></strong>a) Patients within 0–6 years and 90–100 years are not suffering from Pneumothorax.<br>b) For patients with 16 years of age, pneumothorax count is more than without pneumothorax.</p><h3>11. Existing Approaches and Improvements in my model:</h3><p>In the existing approaches, all the images and their corresponding masks(if the mask is not available then a blank mask is passed) are used directly in the segmentation model to train the model. For prediction, the x-ray image is feed into the model to get the predicted mask. If the image does not contain pneumothorax it will show a blank mask otherwise it will mark and display the affected area.</p><p>As 78% of the given images does not contain pneumothorax, I have split the solution into 2 parts:<br><strong>a) Classification: </strong>Firstly, I will build a binary image classification model using pre-trained models and transfer learning to classify the image into positive pneumothorax or negative pneumothorax. I will use images along with their class labels to train the classification model.<br><strong>b) Segmentation: </strong>I will build an image segmentation model to segment the pneumothorax affected area. I will be using only the images which contain pneumothorax and their corresponding masks to train the segmentation model. I will use UNET architecture with the DenseNet121 as an encoder for image segmentation. If the classification model predicts positive pneumothorax, then the image will be passed through the segmentation model for mask prediction.</p><h3><strong>12. Data Preprocessing:</strong></h3><p><strong>a) Decode the images given in DICOM format: </strong>The images given in the dataset are in dicom format. We cannot use them directly in our model. I have to decode the images to be suitable for our model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae06166f92b4050f06d43c940f2a66c6/href">https://medium.com/media/ae06166f92b4050f06d43c940f2a66c6/href</a></iframe><p><strong>b) Convert RLE to png mask:<br></strong>The masks are given in Run Length Encoded (RLE) format. We have to covert RLE to png mask. The below function given by organizers converts RLE to mask.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58ae2d09148fc4f269f45a1d43512cd4/href">https://medium.com/media/58ae2d09148fc4f269f45a1d43512cd4/href</a></iframe><p><strong>What is Run Length Encoding?<br>Run-length encoding (RLE)</strong> is a very simple form of data compression in which a stream of data is given as the input (i.e. “AAABBCCCC”) and the output is a sequence of counts of consecutive data values in a row (i.e. “3A2B4C”). This type of data compression is lossless, meaning that when decompressed, all of the original data will be recovered when decoded. Its simplicity in both encoding (compression) and decoding (decompression) is one of the most attractive features of the algorithm. <br>In the RLE encoded format, the odd position indicates the number of occurrences and the even position right to it indicates the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*9Ud_eh6I4GHk-Jq5vnOPpw.jpeg" /></figure><h3>13. Deep Learning Models:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6kPY6W1V7VGeVCWp6hpIdQ.jpeg" /></figure><p><strong>a) Classification Model: </strong>Firstly, I have to build a data pipeline for the classification model using the decoded images and their corresponding labels. Below is the code snippet for the data pipeline for the classification model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ed82a51875cb3ccce34d925145712f3/href">https://medium.com/media/4ed82a51875cb3ccce34d925145712f3/href</a></iframe><p>Now, I will create my classification model using VGG19 architecture with pre-trained imagenet weights. I will set all the layers of the VGG19 model “trainable=False”. I tried VGG16 as well but received a better recall value using VGG16.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff9220b77dae4ca547695eb23be1bee0/href">https://medium.com/media/ff9220b77dae4ca547695eb23be1bee0/href</a></iframe><p>Now, I will compile and train this model and save the best one using checkpoints.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f031c94a76f47586cf2ee49ff6ab8239/href">https://medium.com/media/f031c94a76f47586cf2ee49ff6ab8239/href</a></iframe><p>Graphs obtained from tensorboard are displayed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*UIe8SDYum23DmdnFNs52Mg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*eutcXxUKaqBx467bpF83UA.jpeg" /></figure><p>As we can see from the graph, the best validation recall received at epoch 7. Weights are saved for this using model checkpoints.</p><p>As I said earlier, I tried VGG16 as well. Below is the comparison for both models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*IDlf3b44JBrhB5me72HQ9A.jpeg" /></figure><p>From the above table, we can see that vgg19 gives better recall compared to vgg16.</p><p>Now define a function to predict the class label for validation data using this classification model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a872d3a7501631d6ecf44b2b2b71e287/href">https://medium.com/media/a872d3a7501631d6ecf44b2b2b71e287/href</a></iframe><p>Now we have to check for which threshold value ranging from 0.1 to 0.9 gives the best prediction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39141765cd8d34e968d613384a86c0ff/href">https://medium.com/media/39141765cd8d34e968d613384a86c0ff/href</a></iframe><p>From the output of the above code snippet, I found that threshold=0.3 gives the best result in terms of all the parameters. The confusion matrix for this threshold value is plotted below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*IdqKIV8Z3dr4dkQheIN4pA.jpeg" /></figure><p>Below is the distribution of predicted probabilities for different class labels from the classification model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIXsbGaDOnFDVxNqntbC4A.jpeg" /></figure><p>It is observed that there is a large overlap between the probability scores of positive and negative class labels.</p><p><strong>b) Semantic Segmentation Model: </strong>Semantic Segmentation model is built on the positive pneumothorax data only along with their corresponding masks. Similar to the classification model, I have to build the data pipeline for the segmentation model as well. Below is the code snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad582d92a4e26816cec04fc3593a2e11/href">https://medium.com/media/ad582d92a4e26816cec04fc3593a2e11/href</a></iframe><p>I have used UNET architecture for this semantic segmentation task. I replaced the encoder part of the UNET model with pre-trained DenseNet121 backbone with imagenet weights and kept the same decoder part. Below is the code snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*RvXkxYBWiUgsgHqI5ESecQ.jpeg" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/829e5c94fed630ceb1344c4bf37c41e8/href">https://medium.com/media/829e5c94fed630ceb1344c4bf37c41e8/href</a></iframe><p>Define callbacks and compile and train the model. Also, save the best model using checkpoints.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bc888ab7e6736694f75b954528acde3/href">https://medium.com/media/1bc888ab7e6736694f75b954528acde3/href</a></iframe><p>Below are the graphs of IOU Score and Loss received from tensorboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*nd4scWMCmlPdpv8Dkae8lA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*MlGHk44BxIkRUfrfnmGyvg.jpeg" /></figure><p>Best validation score=0.3066 received at epoch 17. Saved the weights using checkpoints for future use.</p><p>Displaying some of the images and their corresponding original and predicted masks using the above model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2A1vP3GcS7HQfhM4pn4P8Q.jpeg" /></figure><p>Below is the distribution of iou score. for all the masks predicted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WFiMch9XQLoor-L6fJsAw.jpeg" /></figure><p><strong>Observation:<br></strong>a) There are around 200 images whose iou score is less than 0.1.<br>b) We need to train the model with more similar images for which iou score is very low, so that model can learn better.</p><h3>14. Final Data Pipeline:</h3><p>In the final data pipeline, we give the image path of the x-ray image as input. this function takes care of all the data preprocessing stuff and displays the image along with the predicted mask.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02685eb360e87f050be0343863ceb35d/href">https://medium.com/media/02685eb360e87f050be0343863ceb35d/href</a></iframe><p>Below are some sample predictions received from the final pipeline given an image path as input.</p><p>When the classification model gives negative result, it displays only image with title “THIS IMAGE DOES NOT CONTAIN PNEUMOTHORAX”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*6blJR0mPbApCtpeoPwHTYw.jpeg" /></figure><p>When the classification model gives positive result, the image is passed through segmentation model and the segmentation model predicts the mask. The image along with the mask is displayed with title “THIS IMAGE CONTAINS PNEUMOTHORAX”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhH9KCm-6fEkjLIqEihdKg.jpeg" /></figure><h3>15. Error Analysis:</h3><p>Let’s do some error analysis on both the classification and segmentation model. So that we can improve the performance in future models.</p><p><strong>a) Classification Model:<br></strong>Find out the <strong>false-negative</strong> points and display a few of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*iOnP8opCPoOKShcMzxWjbQ.jpeg" /><figcaption><strong>False Negative</strong></figcaption></figure><p><strong>Conclusion:<br></strong>1.<strong> </strong>False-negative points whose probability scores are very low(near zero) are classified completely wrongly. To fix this issue we need to oversample these data so that the model can learn from these similar images.<br>2. False-negative points whose probability score is less than the threshold but has a little higher value(near about threshold value), even though these are classified wrongly this can be fixed by training our model furthermore.</p><p>Find out the <strong>false positive</strong> points and display a few of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*n8yIF0etWdmqdRRZsK_YUA.jpeg" /></figure><p><strong>Conclusion:<br></strong>1. False-positive points whose probability score is higher(near one) are classified completely wrongly. We need to oversample these data and train our model to get a better result.<br>2. False-positive points whose probability score is lower(near the threshold value) but higher than the threshold, even though these points are classified wrongly this can be fixed by training our model further.</p><p><strong>b) Segmentation Model:<br></strong>Firstly, store the iou score for the predicted masks corresponding to every image. Then, sort the dataframe based on the iou score in descending order. Display a few images along with their original and predicted masks from the top of the dataframe i.e. with best iou scores.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43ec236ef98b1265313efa6c60cda983/href">https://medium.com/media/43ec236ef98b1265313efa6c60cda983/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*0B5pGAyVw03oAJKrwmV1YA.jpeg" /></figure><p>Display a few images along with their original and predicted masks from the bottom of the dataframe i.e. with a very low iou score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*sN3rx0bt27DEoeI0C_V94A.jpeg" /></figure><p><strong>Conclusion: </strong>Images for which iou score is less than 0.1 are generating very poor results.</p><h3>16. Future Work:</h3><ol><li>Due to the unavailability of good computation resources, I could not train my model for more epochs. If it is trained for more epochs, we will get a better prediction.</li><li>By doing error analysis, we have filtered the images for which we got false negative and false positive predictions for the classification model. If we oversample these images so that the model can learn more, we may get better results.</li><li>For the segmentation model also, I have filtered out the images with very low iou score. If oversampling is done for these images and retrain the model, we may get better results.</li></ol><h3>17. LinkedIn and GitHub Repository:</h3><p><em>LinkedIn:</em> <a href="https://www.linkedin.com/in/anik-manik-aa1594a4/">https://www.linkedin.com/in/anik-manik-aa1594a4/</a><br><em>GitHub: </em><a href="https://github.com/anikmanik04/SIIM-ACR-Pneumothorax-Segmentation">https://github.com/anikmanik04/SIIM-ACR-Pneumothorax-Segmentation</a></p><h3>18. References:</h3><ol><li>An overview of semantic image segmentation <a href="https://www.jeremyjordan.me/semantic-segmentation/">https://www.jeremyjordan.me/semantic-segmentation/</a></li><li>U-Net: Convolutional Networks for Biomedical Image Segmentation<br><a href="https://www.semanticscholar.org/paper/U-Net%3A-Convolutional-Networks-for-Biomedical-Image-Ronneberger-Fischer/6364fdaa0a0eccd823a779fcdd489173f938e91a">https://www.semanticscholar.org/paper/U-Net%3A-Convolutional-Networks-for-Biomedical-Image-Ronneberger-Fischer/6364fdaa0a0eccd823a779fcdd489173f938e91a</a></li><li>Metrics to Evaluate your Semantic Segmentation Model<br><a href="https://towardsdatascience.com/metrics-to-evaluate-your-semantic-segmentation-model-6bcb99639aa2#:~:text=The%20Intersection%2DOver%2DUnion%20(,segmentation%E2%80%A6%20and%20for%20good%20reason.&amp;text=For%20binary%20(two%20classes)%20or,each%20class%20and%20averaging%20them.">https://towardsdatascience.com/metrics-to-evaluate-your-semantic-segmentation-model-6bcb99639aa2#:~:text=The%20Intersection%2DOver%2DUnion%20(,segmentation%E2%80%A6%20and%20for%20good%20reason.&amp;text=For%20binary%20(two%20classes)%20or,each%20class%20and%20averaging%20them.</a></li><li>Decode DICOM files for medical imaging<br><a href="https://www.tensorflow.org/io/tutorials/dicom">https://www.tensorflow.org/io/tutorials/dicom</a></li><li><a href="http://www.appliedaicourse.com/">www.appliedaicourse.com</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=890bbfcb5bd6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/detection-and-semantic-segmentation-of-pneumothorax-disease-from-x-ray-images-using-deep-learning-890bbfcb5bd6">Detection and Semantic Segmentation of Pneumothorax Disease from X-Ray Images using Deep Learning</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Healthcare Provider Fraud Detection Analysis using Machine Learning]]></title>
            <link>https://medium.com/analytics-vidhya/healthcare-provider-fraud-detection-analysis-using-machine-learning-81ebf09ed955?source=rss-df7fd58b7c81------2</link>
            <guid isPermaLink="false">https://medium.com/p/81ebf09ed955</guid>
            <category><![CDATA[healthcare-provider-fraud]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[healthcare-fraud]]></category>
            <category><![CDATA[custom-model]]></category>
            <dc:creator><![CDATA[Anik Manik]]></dc:creator>
            <pubDate>Sat, 27 Feb 2021 08:03:29 GMT</pubDate>
            <atom:updated>2021-06-23T16:38:41.264Z</atom:updated>
            <content:encoded><![CDATA[<h4>Build a binary classification model based on the claims filed by the provider along with Inpatient data, Outpatient data, Beneficiary details to predict Healthcare Provider Fraud.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*kA4OOmnrEmf3jGZ__Eyi4w.png" /></figure><p><strong>Table of Contents:<br></strong>1. Introduction<br>2. Types of Healthcare Provider Fraud<br>3. Business Problem<br>4. ML Formulation<br>5. Business Constraints<br>6. Dataset Column Analysis<br>7. Performance metric<br>8. Exploratory Data Analysis<br>9. Existing Approaches and Improvements in my model<br>10. Data Preprocessing<br>11. Machine Learning Models<br>12. Final Data pipeline<br>13. Future work<br>14. LinkedIn and GitHub Repository<br>15. Reference</p><h3>1. Introduction:</h3><p><strong>What is Healthcare Fraud?</strong><br>Fraud is defined as any deliberate and dishonest act committed with the knowledge that it could result in an unauthorized benefit to the person committing the act or someone else who is similarly not entitled to the benefit. Healthcare fraud is one of the types of fraud. Here we will analyze and detect “Healthcare Provider Fraud” where the provider fills in all the details and makes a claim on behalf of the beneficiary. Provider Fraud is one of the biggest problems that Medicare is facing currently. Healthcare fraud is an organized crime that involves peers of providers, physicians, beneficiaries acting together to make fraud claims. As per U.S. legislation, an insurance company should pay a legitimate healthcare claim within 30 days. So, there is very little time to properly investigate this. Insurance companies are the most vulnerable institutions impacted due to these bad practices. As per the Government, the total Medicare spending increased exponentially due to frauds in Medicare claims.</p><h3>2. Types of Healthcare Provider Fraud:</h3><p>Healthcare fraud and abuse take many forms. Some of the most common types of frauds by providers are: <br><strong>a)</strong> Billing for services that were not provided. <br><strong>b)</strong> Duplicate submission of a claim for the same service. <br><strong>c)</strong> Misrepresenting the service provided. <br><strong>d)</strong> Charging for a more complex or expensive service than was actually provided. <br><strong>e)</strong> Billing for a covered service when the service actually provided was not covered.</p><h3>3. Business Problem:</h3><p>Statistics show that 15% of the total Medicare expense is caused due to fraud claims. Insurance companies are the most vulnerable institutions impacted due to these bad practices. The insurance premium is also increasing day by day due to this bad practice.<br>Our objective is to predict whether a provider is potentially fraudulent or the probability score of that provider’s fraudulent activity and also find the reasons behind it as well to prevent financial loss.<br>Depending on the probability score and fraudulent reasons insurance company can accept or deny the claim or set up an investigation on that provider.<br>Find out the important features which are the reasons behind the potentially fraudulent providers. Such as if the claim amount is high for a patient whose risk score is low, then it is suspicious.<br>Not only the financial loss is a great concern but also protecting the healthcare system so that they can provide quality and safe care to legitimate patients.</p><h3>4. ML Formulation:</h3><p>Build a binary classification model based on the claims filed by the provider along with Inpatient data, Outpatient data, Beneficiary details to predict whether the provider is potentially fraudulent or not.</p><h3>5. Business Constraints:</h3><p><strong>a)</strong> The cost of misclassification is very high. False Negative and False Positive should be as low as possible. If fraudulent providers are predicted as non-fraudulent (False Negative) it is a huge financial loss to the insurer and if legitimate providers are predicted as fraudulent (False Positive) it will cost for investigation and also it’s a matter of reputation of the agency.</p><p><strong>b)</strong>Model interpretability is very important because the agency or insurer should justify that fraudulent activity and may need to set up a manual investigation. It should not be a black box type prediction.</p><p><strong>c)</strong> The insurer should pay the claim amount to the provider for legitimate claims within 30 days. So, there are no such strict latency constraints but it should not take more than a day because depending on the output of the model the agency may need to set up an investigation.</p><h3>6. Dataset Column Analysis:</h3><p><strong>Source of Data: </strong>The dataset is given on Kaggle&#39;s website. Please find the link below.</p><p><a href="https://www.kaggle.com/rohitrox/healthcare-provider-fraud-detection-analysis">HEALTHCARE PROVIDER FRAUD DETECTION ANALYSIS</a></p><p><strong>Train-1542865627584.csv:<br></strong>It consists of provider numbers and corresponding whether this provider is potentially fraudulent. Provider ID is the primary key in that table.</p><p><strong>Test-1542969243754.csv</strong><br>It consists of only the provider number. We need to predict whether these providers are potential fraud or not.</p><p><strong>Outpatient Data (Train and Test):<br></strong>It consists of the claim details for the patients who were not admitted into the hospital, who only visited there. Important columns are explained below.</p><p><strong>BeneID:</strong> It contains the unique id of each beneficiary i.e patients.<br><strong>ClaimID:</strong> It contains the unique id of the claim submitted by the provider.<br><strong>ClaimStartDt:</strong> It contains the date when the claim started in yyyy-mm-dd format.<br><strong>ClaimEndDt:</strong> It contains the date when the claim ended in yyyy-mm-dd format.<br><strong>Provider:</strong> It contains the unique id of the provider.<br><strong>InscClaimAmtReimbursed:</strong> It contains the amount reimbursed for that particular claim.<br><strong>AttendingPhysician:</strong> It contains the id of the Physician who attended the patient.<br><strong>OperatingPhysician:</strong> It contains the id of the Physician who operated on the patient.<br><strong>OtherPhysician:</strong> It contains the id of the Physician other than AttendingPhysician and OperatingPhysician who treated the patient.<br><strong>ClmDiagnosisCode:</strong> It contains codes of the diagnosis performed by the provider on the patient for that claim.<br><strong>ClmProcedureCode:</strong> It contains the codes of the procedures of the patient for treatment for that particular claim.<br><strong>DeductibleAmtPaid:</strong> It consists of the amount by the patient. That is equal to Total_claim_amount — Reimbursed_amount.</p><h4>Inpatient Data (Train and Test):</h4><p>It consists of the claim details for the patients who were admitted into the hospital. So, it consists of 3 extra columns Admission date, Discharge date, and Diagnosis Group code.</p><p><strong>AdmissionDt:</strong> It contains the date on which the patient was admitted into the hospital in yyyy-mm-dd format.<br><strong>DischargeDt:</strong> It contains the date on which the patient was discharged from the hospital in yyyy-mm-dd format.<br><strong>DiagnosisGroupCode:</strong> It contains a group code for the diagnosis done on the patient.</p><p><strong>Beneficiary Data (Train and Test):</strong> This data contains beneficiary KYC details like DOB, DOD, Gender, Race, health conditions (Chronic disease if any), State, Country they belong to, etc. Columns of this dataset are explained below.</p><p><strong>BeneID:</strong> It contains the unique id of the beneficiary.<br><strong>DOB:</strong> It contains the Date of Birth of the beneficiary.<br><strong>DOD:</strong> It contains the Date of Death of the beneficiary if the beneficiary id deal else null.<br><strong>Gender, Race, State, Country:</strong> It contains the Gender, Race, State, Country of the beneficiary.<br><strong>RenalDiseaseIndicator:</strong> It contains if the patient has existing kidney disease.<br><strong>ChronicCond_*:</strong> The columns started with “ChronicCond_” indicates if the patient has existing that particular disease. Which also indicates the risk score of that patient.<br><strong>IPAnnualReimbursementAmt:</strong> It consists of the maximum reimbursement amount for hospitalization annually.<br><strong>IPAnnualDeductibleAmt:</strong> It consists of a premium paid by the patient for hospitalization annually.<br><strong>OPAnnualReimbursementAmt:</strong> It consists of the maximum reimbursement amount for outpatient visits annually.<br><strong>OPAnnualDeductibleAmt:</strong> It consists of a premium paid by the patient for outpatient visits annually.</p><h3>7. Performance metric:</h3><p>As the dataset in healthcare fraud is highly imbalanced(very few fraud cases), ‘accuracy’ won’t be the proper metric. An important initial step will be to plot the confusion matrix. Then we need to check the misclassification i.e. FP and FN. FN means the cases predicted by the model are legitimate but actually it is fraudulent. FP means the cases detected by the model are fraudulent, but actually, it is legitimate.</p><p>So, the performance metrics are:<br><strong>a) Confusion Matrix:</strong> It is the table where TP, FP, TN, FN counts will be plotted. From this table, we can visualize the performance of the model.</p><p><strong>b) F1 Score: </strong>It is the harmonic mean of precision and recall.<strong><br><em>F1 Score = 2(Precision * Recall)/(Precision + Recall)<br></em></strong>where <strong>Precision = TP/(TP+FP)</strong> and <strong>Recall = TP/(TP+FN)</strong>. As F1 score consists of both Precision and Recall it will be correct metric for this problem.</p><p><strong>c) AUC Score:</strong> AUC stands for Area Under ROC(Receiver Operating Characteristics) Curve. ROC plots TPR concerning FPR for different thresholds. The area under the curve depends on the ranking of the predicted probability score, not on absolute values.</p><p><strong>d) FPR and FNR:</strong> As the cost of misclassification is very high, we need to check the FPR and FNR separately, It should be as low as possible.</p><h3>8. Exploratory Data Analysis:</h3><h4><strong>Distribution of Class Labels (Provider Data):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*KmvNl5imxEnDHasHn10BNw.jpeg" /></figure><p><strong>Observation:</strong></p><p>This is a highly imbalanced dataset. There are 10% fraudulent providers and 90% non-fraudulent providers.</p><h4><strong>Distribution of Gender (Beneficiary Data):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*jeOhd1_KZwArQH9uWFnt0w.jpeg" /></figure><p><strong>Observation:</strong></p><p>The ratio of genders in beneficiary data is Gender_0 : Gender_1 = 57% : 43%.</p><h4><strong>Distribution of State (Beneficiary Data):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtPCBT5mM6AFNPZEBQmbVw.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>The top 20 states in terms of the beneficiary count are shown in the above picture.</li><li>States with codes 5, 10, 45, 33, and 39 are the top 5 states.</li><li>8.7% of the beneficiaries belong to state 5.</li></ol><h4><strong>Distribution of Country (Beneficiary Data):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*otj4frKD6Mok9Ezg3FaWmQ.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>The top 20 countries in terms of the beneficiary count are shown in the above picture.</li><li>Countries with codes 200, 10, 20, 60, and 0 are the top 5 states.</li><li>2.85% of the beneficiaries belong to country code 200.</li></ol><h4>Distribution of Race (Beneficiary Data):</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j6RqkU3q8sZV4HDhZHCVTw.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>Race 1 is the most in terms of beneficiary count.</li><li>85% of the beneficiaries belong to race 1.</li><li>There is no race 4 in the dataset.</li></ol><h4><strong>Distribution of Patient Risk Score (Beneficiary Data):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*73V24iAMHbrKTOuQ3bg_fA.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>The distribution of patient risk scores is right-tailed.</li><li>Most of the patients with risk scores 2, 3, 4, 5.</li><li>Very few patients are there with risk score 9, 10, 11, 12</li></ol><h4><strong>Annual Reimbursement Amount (Inpatient and Outpatient):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*vnQsrvy4etqFI1KycwXegQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*Fpybg8fExStkWKkksEKA6w.jpeg" /><figcaption><strong>Annual Reimbursement Amount — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>The total annual reimbursement amount for inpatient is 507162970 and outpatient is 179876080. The inpatient reimbursement amount is 2.81 times the outpatient amount.</li><li>There are some outliers in both inpatient and outpatient as the tail of both the distributions is flat with high value.</li></ol><h4><strong>Annual Deductible Amount (Inpatient and Outpatient):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*LncaYRcLUawBp9-AuovM8w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*Cm_OAuFAKyzIKinxP0B-HA.jpeg" /><figcaption><strong>Annual Deductible Amount — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>The total annual deductible amount for inpatient is 55401242 and outpatient is 52335131.</li><li>In both of the datasets there exists some outliers with high value.</li></ol><h4>Attending Physician (Inpatient and Outpatient):</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijPgtS0VW7weOAsmq1iWqQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m-uxF_JukMN2TsBgOffrYg.jpeg" /><figcaption><strong>Attending Physician — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>PHY422134, PHY341560, PHY315112, PHY411541, PHY431177 are the top 5 attending physicians for inpatient and PHY422134, PHY341560, PHY315112, PHY411541, PHY431177 are the top 5 attending physicians for outpatient in terms of the number of patients visit.</li><li>Physician PHY422134 treated 1% of the total inpatients and physician PHY330576 treated 0.5% of the total outpatients.</li></ol><h4><strong>Operating Physician (Inpatient and Outpatient):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6XCvmh3YtMXjRQr41qwvQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ertr63OSTNYxRI7pBuYcrw.jpeg" /><figcaption><strong>Operating Physician — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>PHY429430, PHY341560, PHY411541, PHY352941, PHY314410 are the top 5 operating physicians for inpatient and PHY330576, PHY424897, PHY314027, PHY423534, PHY357120 are the top 5 operating physicians for outpatient in terms of the number of patients operated.</li><li>Physician PHY429430 operated 0.56% of the total inpatients and physician PHY330576 operated 0.08% of the total outpatients.</li></ol><h4><strong>Other Physician (Inpatient and Outpatient):</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4Fpv5vnQVyFVmaPt1Bktg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_3Xsz28QbNu-eVzZtEuAKA.jpeg" /><figcaption><strong>Other Physician — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>PHY416093, PHY333406, PHY429929, PHY423728, PHY361563 are the top 5 attending physicians for inpatient and PHY412132, PHY341578, PHY338032, PHY337425, PHY347064 are the top 5 other physicians for outpatient in terms of the number of patients visit.</li></ol><h4>Procedure Code (Inpatient and Outpatient):</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yr3c0W781UmCw3oUGnEyqQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*az_wkqUpiiBwIA4v-FZo3Q.jpeg" /><figcaption><strong>Procedure Code — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>4019, 9904, 2714, 8154, 66 are the top 5 procedures for inpatient, and 9904, 3722, 4516, 2744, 66 are the top 5 procedures for outpatient in terms of the number of diagnoses done.</li><li>Procedure 4019 is done 6.5% of the total procedures for inpatient and procedure 9904 is done 7.35% of total procedures for outpatient.</li></ol><h4>Diagnosis Code (Inpatient and Outpatient):</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VM2L_XNLkldR2fgld-dZRQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3pOSCBFCMqfDDzrMG0WJ0Q.jpeg" /><figcaption><strong>Diagnosis Code — Inpatient</strong>(Left)<strong> </strong>and <strong>Outpatient</strong>(Right)</figcaption></figure><p><strong>Observation:</strong></p><ol><li>4019, 2724, 25000, 41401, 4280 are the top 5 diagnosis codes for inpatient, and 44019, 25000, 2724, V5869, 4011 are the top 5 diagnosis codes for outpatient in terms of the number of diagnoses done.</li><li>Procedure 4019 test is done 4.3% of the total diagnosis for inpatient and 4.65% for outpatient.</li></ol><h4><strong>Distribution of Inpatient Outpatient in Final Dataset</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*FV1wi-3awhK1S4lyxgJ9FQ.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>The number of claims is less for inpatient data compared to outpatient data.</li><li>Even though the claims are less in inpatient data, the percentage of fraudulent activity is more in inpatient data(57.8%) whereas it is 36.5% in outpatient data. This is because the per claim reimbursement amount for inpatient is much higher(35 times calculated earlier) than the per claim reimbursement amount for outpatient.</li></ol><h4>Insurance Claim Amount reimbursed in Final Data:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*aMVIAp4aj2M7bN5ylBr5Ug.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*AZvE33LjR35Wd7zZPh7Y7A.jpeg" /><figcaption><strong>Histogram (Left) and Box-Plot(Right)</strong></figcaption></figure><p><strong>Observation:</strong></p><ol><li>25th, 50th percentiles are very less for claim amount reimbursed.</li><li>75th percentile amount of Insurance Claim Amount reimbursed for fraudulent claims is higher than the legitimate claims.</li></ol><h4>Bivariate Analysis:</h4><h4>Scatter Plot of Patient Age vs Claim_Period:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*ohhHF3uai43Fqm9xtUWJTw.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>From the scatter plot we can see that when a patient’s age &lt;60 years and claim period more than 20 years, the probability of the transaction is fraudulent is high.</li></ol><h4>Scatter Plot of Patient Age vs InscClaimAmtReimbursed:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*IsYjvmtUWriXgJ5z6IaYCw.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>From the Scatter Plot of Patient Age vs InscClaimAmtReimbursed, I can observe that if patient’s age60000 it tends to be a fraudulent transaction.</li><li>If the patient’s age&gt;88 yrs and claim amount&gt;60000 the probability to be fraudulent is high.</li></ol><h4>Scatter Plot of IP_OP_TotalReimbursementAmt vs InscClaimAmtReimbursed:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*EOyoUj7IZcX80thJjJYg2w.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>If InscClaimAmtReimbursed&gt;10000 and IP_OP_TotalReimbursementAmt&gt;120000 then the chance to be a fraudulent transaction is high.</li></ol><h4>Scatter Plot of IP_OP_AnnualDeductibleAmt vs InscClaimAmtReimbursed:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*fIaMYB6-inaF5IWCpX1_Og.jpeg" /></figure><p><strong>Observation:</strong></p><ol><li>If IP_OP_AnnualDeductibleAmt&lt;5000 and InscClaimAmtReimbursed&gt;600000 then the chance to be a fraudulent transaction is high.</li></ol><h3>9. Existing Approaches and Improvements in my model:</h3><p>In the existing approaches mainly inbuilt models from scikitlearn were used and no proper strategy was taken for the data imbalance. In my solution, I have introduced random oversampling using SMOTE to handle the data imbalance. Along with the first cut models I have used custom ensemble models to get better performance.</p><h3>10. Data Preprocessing:</h3><p>First, create some features in the individual datasets.</p><p>Calculate patient’s age based on DOD, if DOD is not available calculate age based on the maximum date available in the data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/106617dc3e7cc4346c5432253c24d64e/href">https://medium.com/media/106617dc3e7cc4346c5432253c24d64e/href</a></iframe><p>Create a separate column whether the patient is dead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7ff6c24576ea54c1a8b1bb427e19988/href">https://medium.com/media/e7ff6c24576ea54c1a8b1bb427e19988/href</a></iframe><p>Calculate Claim Duration and Hospitalization Duration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc64045a6fc1df1e7a81fabdc3195247/href">https://medium.com/media/bc64045a6fc1df1e7a81fabdc3195247/href</a></iframe><p>If the number of days claimed for Inpatient treatment is more than no of days hospitalized is suspicious. So, I am adding this feature column.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41808f487a1cfae685cfa237f2224208/href">https://medium.com/media/41808f487a1cfae685cfa237f2224208/href</a></iframe><p><strong>Merge All the Datasets: </strong>We have 4 different datasets, which are interconnected by foreign keys. I need to merge them using the foreign keys to get a overall dataset. Below is a brief overview of the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*CkUMIPcls459Mq-7dY1Fvw.jpeg" /><figcaption><strong>Overall Representation of The Dataset</strong></figcaption></figure><ol><li>Merge Inpatient and Outpatient data based on common columns:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b47da491ef913a89263531ecb79014a/href">https://medium.com/media/7b47da491ef913a89263531ecb79014a/href</a></iframe><p>2. Merge beneficiary details with inpatient and outpatient data on BeneID.<br>3. Merge provider details with previously merged data on ProviderID.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00a86122fbfbd3c9a577a5b1eed306ae/href">https://medium.com/media/00a86122fbfbd3c9a577a5b1eed306ae/href</a></iframe><p>Once merging is done, create new features based on the merged data.</p><p>Create a new feature <strong>“total reimbursement amount”</strong> for inpatient and outpatient.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9cd5494236fcf62c2c66494953aad57/href">https://medium.com/media/a9cd5494236fcf62c2c66494953aad57/href</a></iframe><p>Create new features using ‘groupby’ and taking mean or aggregate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a37f02cd1a2369eb7ee1a4d27e7285ef/href">https://medium.com/media/a37f02cd1a2369eb7ee1a4d27e7285ef/href</a></iframe><p>As Providers fill and submit the claim they are mainly associated with the fraudulent activity. So, I will group by the provider and take the mean of reimbursed, deducted, etc. If the average claim amount or claim period is high for a provider, this is suspicious.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/986c7d214a12c45649c66ad7c1a64eb9/href">https://medium.com/media/986c7d214a12c45649c66ad7c1a64eb9/href</a></iframe><p>Beneficiaries also associated with fraudulent activity. So, group by the data-frame by Beneficiary Id and take mean. If the average claim amount is high for a beneficiary then this is suspicious.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/340120dd2eed3a8df7d549489f1c4935/href">https://medium.com/media/340120dd2eed3a8df7d549489f1c4935/href</a></iframe><p>Physicians are also associated with fraudulent activity. So, group by AttendingPhysician, OperatingPhysician, and OtherPhysician and take mean. High amounts for a physician are suspicious.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df1fd81a3243d4f7ea3e73f98de9114e/href">https://medium.com/media/df1fd81a3243d4f7ea3e73f98de9114e/href</a></iframe><p>I need to group by all diagnosis codes to combine the patients who performed the same tests and take the average of costs etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6cdda19816f0da780c4f70c3166bf19/href">https://medium.com/media/d6cdda19816f0da780c4f70c3166bf19/href</a></iframe><p>I need to group by all procedure codes to combine the patients who gone through same procedure take the average of costs etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a5f61dacca1e8e51638799abefb4006/href">https://medium.com/media/6a5f61dacca1e8e51638799abefb4006/href</a></iframe><p>Sometimes Providers along with physicians, beneficiaries, and sometimes diagnosis and procedures are also associated. So take another feature with provider id and group by. Take count after that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d072d42d0f20f4cd65ff8da46488ecf/href">https://medium.com/media/0d072d42d0f20f4cd65ff8da46488ecf/href</a></iframe><p>Remove the columns which are no longer required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a62b1ef64ed2a315763967a6276a6ded/href">https://medium.com/media/a62b1ef64ed2a315763967a6276a6ded/href</a></iframe><p>Convert the type of Gender and Race to categorical and do one-hot encoding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/733c51bc422f7240b8708eac4e7c8726/href">https://medium.com/media/733c51bc422f7240b8708eac4e7c8726/href</a></iframe><p>Our objective is to predict healthcare provider fraud. So, group by the provider and take sum to create a feature corresponding to each provider.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/081ebf3481d51f3c1aa402727427fda2/href">https://medium.com/media/081ebf3481d51f3c1aa402727427fda2/href</a></iframe><p>Now standardize the data using StandardScaler.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/975a0afe56f1e73f24c4f175b1e03b0e/href">https://medium.com/media/975a0afe56f1e73f24c4f175b1e03b0e/href</a></iframe><h3>11. Machine Learning Models</h3><p>Now our dataset is ready. We need to try different models, first cut models along with ensemble models and validate the performance of every model. Based on the performance of the validation data we need to pick the best one for deployment.</p><p>First, define some functions to validate every model, which will draw ROC curve and confusion matrix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f982179e1a24a50655809f191c7c50a8/href">https://medium.com/media/f982179e1a24a50655809f191c7c50a8/href</a></iframe><p>Below are the different approaches that we will follow in this case study.</p><p><strong>Approach 1:</strong><br>a. Split the data into Train and Validation (80:20)<br>b. Oversample the data using <strong>SMOTE</strong> (majority: minority) to make 80:20, 75:25, 65:35, and 50:50.<br>c. Use Logistic Regression, Decision Tree, Support Vector Classifier, and Naive Bayes for all these 4 oversampled datasets. Pick the best model based on the performance score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*u03iqQeD-6XhoXEgxpUpxg.jpeg" /></figure><p>After evaluating the above models across all the oversampled data, it is found that Logistic Regression performed the best with Oversampling Ratio 80:20 with AUC score of 0.9508</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BXqkz8hZKIxEKlWLFVQVSA.jpeg" /><figcaption><strong>AUC and Confusion Matrix for LR with all features</strong></figcaption></figure><p><strong>Approach 2:<br></strong>In this approach, we will calculate feature importance using the Random Forest model. Based on the decrease of Gini impurity when a variable is chosen to split a node the feature importance is calculated. Below is the code snippet to find feature importance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c07370006ce97117c4b62ed419cb37b/href">https://medium.com/media/3c07370006ce97117c4b62ed419cb37b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*Gk2suNm_YbXK_7UmpMemAA.jpeg" /><figcaption><strong>20 top important features</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*wgO9vUACcW8wK_tBnKklPA.jpeg" /><figcaption><strong>20 least important features</strong></figcaption></figure><p>Take the features whose feature importance is greater than 0.001. I found 161 such features. Now I will train the ML model using these features only. Trained Logistic Regression and Random Forest using the important features. Below are the observations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*i7xUk_3kP7jTVHu7T9gcnA.jpeg" /><figcaption><strong>Comparison of model with all features and important features.</strong></figcaption></figure><p>AUC and Confusion Matrix of LR model for Important Features:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWWfC0JQ1fKPc5xitmAsIQ.jpeg" /><figcaption><strong>AUC and Confusion Matrix for LR with important features</strong></figcaption></figure><p><strong>Observation:<br>1. </strong><em>Logistic Regression vs Random Forest with all the features</em><br>Using RF, F1 score increased from LR model with little decrease in AUC. Apparently, it can be said the RF model performing better than LR model. But if I look at the confusion matrix, the False Negative(Predicted Not-Fraud but actually it is Fraud) count is more in RF, which is very dangerous in our case. After looking at all the scores it can be said that LR is performing better than RF.<br>2. After filtering the important features there is no such improvement in model performance for both LR and RF. F1 score is increased even though False-negative also increased. In our case decreasing False Negative is more important than decreasing False Positive. So, I can say the model is performing better with all features than only using top important features.<br>3. After considering AUC, F1 Score, FNR it can be said the Logistic Regression model is the best model in healthcare provider fraud detection problem.</p><p><strong>Approach 3:</strong> Build a Custom Ensemble Model with base models along with a meta-model and see if we can achieve better accuracy.</p><p><strong>Steps to be followed:<br>a.</strong> Split whole data into train and validation(80–20).<br><strong>b.</strong> Now, in the 80% train set, split the train set into D1 and D2.(50–50).<br><strong>c.</strong> From D1, do sampling with replacement to create d1,d2,d3….dk(k samples).<br><strong>d.</strong> Now create ‘k’ models (combination of DT, LR, SVC, NB, RF, XGBClassifier) i.e. base learners with low bias and high variance and train each of these models with each of these k samples.<br><strong>e.</strong> Now, pass the D2 set to each of these k models. Now, I will get k predictions for D2 from each of these models.<br><strong>f.</strong> Now, using these k predictions, create a new dataset. The corresponding target values of this new dataset are already known. Train a meta-model using this new dataset.<br><strong>g. </strong>Now evaluate the model using the 20% validation data. Pass the validation set to each of the base models and get ‘k’ predictions. Create a new dataset using these predictions and pass it to the meta-model to get the final prediction. Using the predicted label and original label calculate the model’s performance score.<br><strong>h. </strong>Once the final model is ready it can be deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*vHI5NcS7kNx6vonGYHehcw.jpeg" /><figcaption><strong>Custom Ensemble ML Model</strong></figcaption></figure><p><strong>Code sample for custom ensemble model:</strong></p><p>Define a function to randomly sample data from D1 dataset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1efb712dbbc053d1b159c2f40251dd71/href">https://medium.com/media/1efb712dbbc053d1b159c2f40251dd71/href</a></iframe><p>Function to create ‘k’ sampled dataset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e4769852b99a1fb70360792fd974d9b/href">https://medium.com/media/5e4769852b99a1fb70360792fd974d9b/href</a></iframe><p>Function to create ‘k’ base learners:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afee706acd44fd167dcf0618ae30692e/href">https://medium.com/media/afee706acd44fd167dcf0618ae30692e/href</a></iframe><p>Train ML ensemble model for different values of ‘K’ and find best ‘K’</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a27068464069bb5408a853b54dae512f/href">https://medium.com/media/a27068464069bb5408a853b54dae512f/href</a></iframe><p><strong>Observation:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*qJDb250MMe4UR9aAgsE0Lw.jpeg" /><figcaption><strong>Model performance comparison for Meta Model</strong></figcaption></figure><p>Random Forest worked the best as meta-model using 50 different combinations of base learners. Test AUC = 0.9631</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACLP0kQqwtmuyJzvlqusFQ.jpeg" /><figcaption><strong>Performance of ensemble model with RF as a meta-model</strong></figcaption></figure><p><strong>Approach 4:</strong> StackingCVClassifier from mlextend</p><p>As hyperparameter tuning was not done for the base learners in the previous model, using StackingCVClassifier from “mlxtend”, the base models, as well as meta-model can be tuned. Then train the StackingCVClassifier with the best parameters to find the final prediction. Below is the code sample.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50c7fa84999b5234114370097add4431/href">https://medium.com/media/50c7fa84999b5234114370097add4431/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_T7jPwzRxRrmuOPwKffVXQ.jpeg" /></figure><p>As the performance of the StackingCvClassifier was not better compared to the custom ensemble model, I will not be using this as the final model.</p><h3>12. Final Data Pipeline:</h3><p>As we saw that custom ensemble model with RF as meta-model worked the best for this healthcare provider fraud detection problem, we will use this in our final model pipeline. Pleaase find the code snippet for complete pipeline.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3dcf6a1fbbef485a0ad73ea45720faf9/href">https://medium.com/media/3dcf6a1fbbef485a0ad73ea45720faf9/href</a></iframe><p>Final prediction received from the pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*rztFg_Dbv-9nijAU1aTT5g.jpeg" /><figcaption><strong>Final prediction along with the original labels</strong></figcaption></figure><h3>13. Future Work:</h3><p>This problem can be solved using deep learning techniques. Using deep multilayer we can use different kinds of activation functions(Relu, Leaky relu) and dropouts to prevent overfitting. As this a binary classification problem, we can use either sigmoid or softmax in the final layer.</p><h3>14. LinkedIn and GitHub Repository:</h3><p><em>LinkedIn:</em> <a href="https://www.linkedin.com/in/anik-manik-aa1594a4/">https://www.linkedin.com/in/anik-manik-aa1594a4/</a><br><em>GitHub: </em><a href="https://github.com/anikmanik04/healthcare-provider-fraud-detection">https://github.com/anikmanik04/healthcare-provider-fraud-detection</a></p><h3>15. References:</h3><ol><li><em>A survey on statistical methods for health care fraud detection<br></em><a href="https://cpb-us-w2.wpmucdn.com/sites.gatech.edu/dist/4/216/files/2015/09/p70-Statistical-Methods-for-Health-Care-Fraud-Detection.pdf">https://cpb-us-w2.wpmucdn.com/sites.gatech.edu/dist/4/216/files/2015/09/p70-Statistical-Methods-for-Health-Care-Fraud-Detection.pdf</a></li><li><em>The Detection of Medicare Fraud Using Machine Learning Methods with Excluded Provider Labels<br></em><a href="https://www.aaai.org/ocs/index.php/FLAIRS/FLAIRS18/paper/download/17617/16814">https://www.aaai.org/ocs/index.php/FLAIRS/FLAIRS18/paper/download/17617/16814</a></li><li><em>Machine Intelligence &amp; Data Mining in Healthcare Fraud Detection<br></em><a href="https://www.roselladb.com/healthcare-fraud-detection.htm#:~:text=Healthcare%20fraud%20detection%20involves%20account,feasible%20by%20any%20practical%20means">https://www.roselladb.com/healthcare-fraud-detection.htm#:~:text=Healthcare%20fraud%20detection%20involves%20account,feasible%20by%20any%20practical%20means</a>.</li><li><em>Predicting Healthcare Fraud in Medicaid: A Multidimensional Data Model and Analysis Techniques for Fraud Detection<br></em><a href="https://www.sciencedirect.com/science/article/pii/S2212017313002946">https://www.sciencedirect.com/science/article/pii/S2212017313002946</a></li><li>www.appliedaicourse.com</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81ebf09ed955" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/healthcare-provider-fraud-detection-analysis-using-machine-learning-81ebf09ed955">Healthcare Provider Fraud Detection Analysis using Machine Learning</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>