<?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 Abhishek Mishra on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Mishra on Medium]]></description>
        <link>https://medium.com/@abhishekmishra_22309?source=rss-36c52c523c6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3LIxy85Z6YrHCnqpjRuJ_A.png</url>
            <title>Stories by Abhishek Mishra on Medium</title>
            <link>https://medium.com/@abhishekmishra_22309?source=rss-36c52c523c6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:57:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhishekmishra_22309/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[IEEE-CIS Fraud Detection]]></title>
            <link>https://medium.com/@abhishekmishra_22309/ieee-cis-fraud-detection-d011d6ef2fec?source=rss-36c52c523c6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d011d6ef2fec</guid>
            <dc:creator><![CDATA[Abhishek Mishra]]></dc:creator>
            <pubDate>Wed, 08 Jul 2020 13:02:41 GMT</pubDate>
            <atom:updated>2020-07-08T13:02:41.282Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A case study of detecting fraudulent transaction when transaction is going on.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*uuCc9trOe-3VB0HPd1o52w.png" /></figure><h4><strong>Introduction :</strong></h4><p>Imagine standing at the check-out counter at the grocery store with a long line behind you and the cashier not-so-quietly announces that your card has been declined. In this moment, you probably aren’t thinking about the data science that determined your fate.</p><p>Embarrassed, and certain you have the funds to cover everything needed for an epic nacho party for 50 of your closest friends, you try your card again. Same result. As you step aside and allow the cashier to tend to the next customer, you receive a text message from your bank. “Press 1 if you really tried to spend $500 on cheddar cheese.”</p><p>While perhaps cumbersome (and often embarrassing) in the moment, this fraud prevention system is actually saving consumers millions of dollars per year. Researchers from the <a href="https://cis.ieee.org/">IEEE Computational Intelligence Society</a> (IEEE-CIS) want to improve this figure, while also improving the customer experience. With higher accuracy fraud detection, you can get on with your chips without the hassle.</p><h4>About Data :</h4><p><a href="https://www.kaggle.com/c/ieee-fraud-detection/data">IEEE-CIS Fraud Detection</a></p><p>The data is broken into two files identity and transaction, which are joined by TransactionID. Not all transactions have corresponding identity information.</p><p>Dataset has two part train and test.</p><p>Train dataset has two part one is train_transaction.csv and another is train_identity.csv, similarly test set also has two part test_transaction.csv and test_identity.csv. transction file has 394 features and identity file has 41 features.</p><h4>Business Problem :</h4><blockquote>If some kind of fraud happens with the transaction while the transaction in happening the company should immediately block the card.</blockquote><blockquote>The model should avoid not to make a transaction fraud which is in reality is a legit transaction.</blockquote><blockquote>The Model should give the probability score of a transaction being fraud.</blockquote><p>Now we have our business problem and we have to tackle this problem by ML and convert these business requirements to our ML problem.</p><p>Now we have to predict two class one for fraudulent transaction and other for legit transaction, i.e. it is a binary classification problem.</p><h4>Objectives &amp; Constraints are :</h4><blockquote>Performance metric used in this case study is area under the ROC curve. Because the dataset is highly imbalanced dataset and we want to improve the accuracy of both the classes so roc curve is a good option. AUC score is a degree/measure of separability, and we want this model can well separate legit transaction from fraud transaction</blockquote><blockquote>The model should give probabilistic output(probability of transaction being fraudulent transaction)</blockquote><blockquote>Low latency requirements(Since the business problems says that if the system finds any unusual transaction it should immediately block the card).</blockquote><blockquote>Minimize both false positive and false negative(Means minimizing both falsely predicted legit as fraud and fraud as legit transaction)</blockquote><h4>Exploratory Data Analysis :</h4><p>First load train_transaction.csv and train_identity.csv and merge both on TransactionID column similarly test_transaction.csv and test_identity.csv and merge on TransactionID column. You can find full project on <a href="https://github.com/abhishekmishra2612/IEEE-CIS-Fraud-Detection">here</a>.</p><p>I have done the data analysis on almost all of the features presented in both identity data and transaction data. But showing all of them is not possible. I will show some of the important features analysis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4be7cb79dae10f232a8b75909bcba247/href">https://medium.com/media/4be7cb79dae10f232a8b75909bcba247/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*M2bGlxOK6e6D2EYownJepA.png" /></figure><p>In training data 96.5% of data points belongs to legit transactions and only 3.5% of datapoints belongs to fraudulent transactions, hence its a highly imbalanced dataset.</p><p>Now some analysis on TransactionDT features, this feature represent some time references in second so first convert it to day number of week.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ae49850a99ee5f4f4f80b9bcec05c1a/href">https://medium.com/media/3ae49850a99ee5f4f4f80b9bcec05c1a/href</a></iframe><p>And also create HOUR feature from the TransactionDT feature and i found it shows some interesting behaviour.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c87a94cde010f8b961289c63378286c5/href">https://medium.com/media/c87a94cde010f8b961289c63378286c5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*_pQclLO98ak6CkY4guwZNg.png" /></figure><p>HOUR of the day feature shows that from hour 2 to hour 11 and at 23 there are more fraudulent transactions happened, and from 12 to 17 more legit transactions happened so in the morning time we have to be more alert. Hence from this behaviour i have created a feature called <strong>alert.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7de2c7d5a2aaf3ef3f34b67844869566/href">https://medium.com/media/7de2c7d5a2aaf3ef3f34b67844869566/href</a></iframe><p><strong>Analysis of TransactionAmt feature :</strong> It is the amount of transaction in USD.</p><p>First plot the distribution of TransactionAmt feature for train and test data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d302c935b1752eecbcdd11d81c6e437b/href">https://medium.com/media/d302c935b1752eecbcdd11d81c6e437b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*h2wszdkutxaB7BtiZOt-Ig.png" /><figcaption>Distribution of TransactionAmt</figcaption></figure><p>The distribution of TransactionAmt is looks like skewed distribution, in test data all the values are less than 10000 but for train data there may be present of outliers so we have to check the presence of outliers by printing percentiles values.</p><p>Since the distribution of TransactionAmt feature looks like skewed so lets take log of it that will make it like Gaussion distribution, and create logTransactionAmt feature using this feature and i found that it is very important feature.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/070671bcdb8f8f906e47774b8a129a46/href">https://medium.com/media/070671bcdb8f8f906e47774b8a129a46/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*lEckWBOswA4eSxGCaKvARw.png" /><figcaption>Distribution of logTransactionAmt</figcaption></figure><p><strong>Analysis of ProductCD feature :</strong> It is a categorical feature containing 5 distincts(W,H,C,S,R) categories, and lets plot the histogram to see the frequency of each categories.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76f068a8bebc4be5667c4c650b15e592/href">https://medium.com/media/76f068a8bebc4be5667c4c650b15e592/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*1MlwSKI0atlLLE_ypb8XIg.png" /></figure><p>The relative frequency of each category in train and test data are very similar, here categories W,C have very high frequency compare to other categories.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c5762b8b32c4c4dcb9981e095aa0209/href">https://medium.com/media/5c5762b8b32c4c4dcb9981e095aa0209/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*BkxdBl65zl7o76YeS7iIQg.png" /></figure><p>Here for train data Transactions having ProductCD C,H,S are more likely to be fradulent transactions, so it would be an important feature for separating fraudulent transactions from legit transactions.</p><p><strong>Analysis of Card features : </strong>In this dataset 6 different types of cards Card-1 to Card-6. Distribution for card -1 are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*8Q0ernKmowJOL-xXPchemg.png" /><figcaption>Distribution of Card-1</figcaption></figure><p>It shows that the distribution of card-1 has some periodic behaviour some values are more frequent and some other values are less frequent.</p><p>Card-4 is categorical feature , it is the company of card by which transaction happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*qNyZOBbl-22Iw0Dq3pZUBg.png" /></figure><p>It shows that there are lots of people that are using visa and mastercard but very less people that are using american express and discover. Here separating power of this feature is very less.</p><p>Card-6 is also a categorical feature and it is the type of card by which transactions happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*M40thVe6glJMDMNXZgC2Fw.png" /></figure><p>As expected the user of credit card is more than any other cards, and the percentage of user using debit or credit and charge card is very very less almost 0% so we have to map debit or credit and charge card to debit card.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3206efce975a01cfca06a5f5eaec233f/href">https://medium.com/media/3206efce975a01cfca06a5f5eaec233f/href</a></iframe><p>Ploting the histogram to see the relative fraction of datapoints belonging to fraudulent and legit transactions shows transactions by credit card are more likely to being fraudulent transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*ND4XdVUcqV3KP512Eafsjg.png" /></figure><p>Now Addr1 is the address of location where transactions happened</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9mIG-UOobjGVxQgJieC35w.png" /></figure><p>P_emaildomain and R_emaildomain are the purchaser and receiver respectively email domain features and lets create a feature of company corresponding to email prefix and another feature of email suffix. Lets first separate first part from second part of the mail.From first part one new feature will be created and from second part another new feature will be created.Some little bit analysis and we can see that second part consist of net,com,de,es,jp,fr,uk,mx,es type of extension.From the first part it consist of msn,hotmail,outlook,gmail,me,icloud etc. All of the first part belongs to some company,like msn,hotmail,outlook belongs to Microsoft then me,icloud belongs to Apple like wise we can categorize these first part.Here is the code for it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/404d581fe89890354c497ea172583fb1/href">https://medium.com/media/404d581fe89890354c497ea172583fb1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M7yOJrJAzq8S9-BJAUzTOw.png" /></figure><p>Most transactions happened through the google(Gmail) and hence more transactions are fraudulent by the user of gmail.And the user having email domain of Yahoo,aol and some other are more likely to done legit transactions.</p><p>Now lets do some analysis on ‘C’ features.I will show the analysis on only one C feature here.Lets first see the description of the <strong>C12</strong> feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*EbyV8MRj-cgpx2jrs8KliA.png" /></figure><p>From the plot it is observed that values of “C12” which are very small close to zero are more likely to belong to legit transactions, and most values are very are less than 2000 and some 1% values are more than 2000 so we have to check the presence of outliers by printing the the percentiles values.</p><p>Now lets do some analysis on ‘D’ features.Basically D features deal with the time reference.I will show the analysis on only one D4 feature here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*0FJk2zg6BZov8PS5JxxB6Q.png" /><figcaption>Distribution of D4 feature</figcaption></figure><p>Distribution of D4 for train and test looks very similar and looks like a skewed distribution, since D feature represent some time reference hence it can’t be negative so we should have to remove the datapoints having negative D features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*geEzGy_S4ks5c6NjAqOvoA.png" /></figure><p>Here some values of D4 are -ve so we will remove those datapoints that contain negative D4.</p><p><strong>Analysis of M1 to M9 features :</strong> I have observed from the EDA that all the M1 to M9 features are categorical features and for some features more points with one category belongs to one class and more points with other category belongs to other class hence these features are very important features for classification except “M1”. For example for feature “M5” more points with M5=F are belongs to legit transactions and more points with M5=T are belongs to fraudulent transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*qPPAqOAMXOG1OFtGfPm-VQ.png" /><figcaption>Histogram of M5</figcaption></figure><p>Feature “<strong>DeviceInfo</strong>” contain information of by which device transaction happened, this feature gives the name of the company of device and version of the device, so first from this feature we create two feature one is device name and another is device version and then map each device name to their corresponding brand name, here is code snippet for this task.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9587cecd61140056774fbb1bb25812e9/href">https://medium.com/media/9587cecd61140056774fbb1bb25812e9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-ukpSaqrirrqzxzW312Zg.png" /></figure><p>From above plot it is observed that transactions by some device like “Windows”, “Ios device”, “MacOs” , “Trident” are more likely to be legit transactions, and transactions by “Samsung”, “Motorola”, “Others” are more likely to be fraudulent transactions so i concluded that “Device_name” feature would be an important feature for classification of fraudulent transactions from legit transacctions.</p><p>Now from the analysis on “<strong>DeviceType</strong>” feature it is observed that transactions by mobile device are more fraudulent transactions and transactions by desktop device are more legit transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IfauT1VxRhQOXCC2l-jVaA.png" /></figure><p>Analysis on <strong>Id-1 to Id-39</strong> features, id_x features are the features of identity file ,id-1 to id-11 are numerical features and id-12 to id-39 are categorical features , some id-x features have interesting characteristic like feature “<strong>id_30</strong>” represent the operating system and their version of the device by which transaction happened. So from id-30 i have create a feature which contain only the operating system name of the device and it has nice characteristics for classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3VSdQfr1DVgPHzqhxKsgQ.png" /></figure><p>Here transactions by “Ios”, “Android” are more likely to be fraudulent transactions and transactions by “Windows”,”Mac” are more likely to be legit transactions , it shows the nature of DeviceType feature, i.e. Transactions by mobile device are more likely to be fraudulent transactions and and by desktop computer are more likely to be legit transactions.</p><p><strong>Id-31</strong> feature tells by which type of browser and its version transaction happened , so we will create two feature from id-31 one feature is browser name feature and other is its version</p><p><strong>Id-33</strong> feature tells the screen dimension of the device by which transactions happened, so we will create screen height and screen width feature from feature Id-33.</p><p><strong>TransactionAmt</strong> feature has decimal values and now we will create a feature of number of digits after decimal point it shows an interesting result</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/513ca86a74d6045d4f9690832c9f8b2b/href">https://medium.com/media/513ca86a74d6045d4f9690832c9f8b2b/href</a></iframe><p>that if number of digits after decimal point are more then it is more likely to be fraudulent transactions.</p><p>We print the % of NULL in each id_x feature and we fount many id-x features have more than 80% missing values so these features will not contribute much in the classification process but can leads to increase the training time. Hence we should remove those features which contain more than 80% of NULL values.</p><p>Now we created some aggregated engineered features, these features are based on the counts of categorical features and TransactionAmt devided by mean and std TransactionAmt for each card and similarly for id_x also.Here is the code snippet for aggregation feature engineering</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf002eb999a89fbb8e6bc0d6825d60dd/href">https://medium.com/media/cf002eb999a89fbb8e6bc0d6825d60dd/href</a></iframe><p>Later for modeling i found that these engineered features are very important feature.</p><p>Now analysis of <strong>Vx</strong> features since these features are engineered features by <strong>CIS</strong> and there are 339 features so it is impossible to analyse each feature so we train a classifier model on <strong>Vx</strong> features so see which features are important and which other features are not important so we will remove those features which are not very important features. We train <strong>LGBMClassifier</strong> on <strong>Vx </strong>featured data because it is superfast algo. after training printing the training and validation<strong> AUC</strong> score it gave Train_AUC=0.88 and Val_AUC=0.84 , now we removed all the <strong>Vx </strong>features which have importance score less than 3, and train <strong>LGBMClassifier</strong> on remaining <strong>Vx</strong> featured data and then it gave Train_AUC=0.88 and Val_AUC=0.84 , so after removing 122 less important features the performance did not reduces so hence we have to keep the remaining <strong>Vx </strong>features.</p><p>Now since many features have missing values with reasonable number of missing datapoints so if we remove those datapoints which have missing values then we will throw much information, so we imputed the missing values of numerical features by replacing the NULL with median of that column and for categorical features replacing the NULL with mode of that column, and i found imputation by this technique performed well.</p><p>Now for categorical features we can do featurization by using one hot encoding or responce coding but in this task replacing each distinct category by a numerical value for each categorical variable performed very well.</p><p>Splitting the data in 70:30 ratio for train &amp; validation data, but splitting is the time based splitting not random splitting because it is the time series data and all the datapoints in test data are after train datapoints.</p><p>After splitting of dataset into into train and validation we should have to standardize dataset so we do standardizing of data by the technique of mean centring and variance scaling</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a48b8220d109bdfa0385f55e1058009e/href">https://medium.com/media/a48b8220d109bdfa0385f55e1058009e/href</a></iframe><p>We have define a function which will use to display the confusion matrix , Precision matrix and Recall matrix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/942666e6ac3eab024a2ef6c4b249d12a/href">https://medium.com/media/942666e6ac3eab024a2ef6c4b249d12a/href</a></iframe><h4>Training &amp; Evaluation Part :</h4><p>First train the <strong>Logistic Regression</strong> model because it is fast and perform very well on high dimensional data but in this problem the dimensionality of data is reasonable good not too high so lets train LR and see the performance</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5468d314382feba06e1b9299baf3c48/href">https://medium.com/media/e5468d314382feba06e1b9299baf3c48/href</a></iframe><p>here above code snippet is for the hyperparameter tuning of Logistic Regression model and i found “alpha=0.001” is the best alpha. Then train the Logistic Regression model with best hyperparameter and then evaluate it on train and validation data then it gave Train_AUC=0.8698 and Val_AUC=0.8328, it shows that model is not overfit because the difference between train AUC and Val AUC is small.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*Je4E8fe5Q8_mZ24O94y-cA.png" /></figure><p>From feature importance we found that some of the engineered features are very important, we have display top 50 important features</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*QU8u5HyJC_NV9uQUVGCFig.png" /></figure><ul><li>Creating some more proper interaction feature may increase the model auc,Because more the higher dimension more the tendency to data to be linear separable generally.</li><li>Since logistic regression is distance based algorithm it’s separating hyper plane is affected by the extreme outliers.May be doing some analysis and removing some extreme outliers may benefit the auc score.</li></ul><p><strong>Training &amp; Evaluation of LGBMClassifier model :</strong> For the non-linear model we can choose the random forest or XGBoost algo but it is somewhat slow hence we choose LGBMClassifier model because it is superfast model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9075cfdbdbc7e9afb1df2018fe2092a/href">https://medium.com/media/e9075cfdbdbc7e9afb1df2018fe2092a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c61cf83625153f29c39aaf42d576582/href">https://medium.com/media/1c61cf83625153f29c39aaf42d576582/href</a></iframe><p>After tuning the hyperparameters of LGBMClassifier we have found the best hyperparameters as {‘learning_rate’: 0.01, ‘max_depth’: 5, ‘min_child_samples’: 446, ‘min_child_weight’: 0.001, ‘n_estimators’: 1100, ‘reg_alpha’: 7, ‘reg_lambda’: 0.1, ‘subsample’: 0.20426008083869115}. We trained the LGBMClassifier model with these parameters and then we found that the Train_AUC=0.9268 &amp; Val_AUC=0.8944 and the ROC curve is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*l193TMhNaNzL2BZTOZRQVw.png" /></figure><p>It shows that the model is not overfit because the difference between train AUC and validation AUC is very small , the performance of LGBMClassifier model is pretty well and i got 0.91 score on kaggle submission. Top 50 important features for the LGBMClassifier model are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*77bEmqZgri3bQI-kk-5hfQ.png" /></figure><p>Here again the engineered features are very important for LGBMClassifier so it shows that created features are working well for both model.</p><p>Now plotted the heatmap of the correlation between each <strong>Dx</strong> features</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*WsybIlt1NrY6OolPxfL9Zw.png" /></figure><p>and correlation between each “<strong>C</strong>” features are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*tLLBkxHl0Mv6NuDuJreexg.png" /></figure><p>from the above two correlation matrix of features <strong>D</strong> and features <strong>C</strong> it is observed that correlation between D1 and D2, between D6,D12 &amp; D5 are very high and in C features correlation between C1, C4, C6, C8 &amp; C11 are very high so we have to remove the correlated features because it will not contribute much in the classification so we have to remove the highly correlated features.</p><p><strong><em>So one question arises is that is removing correlated features is a good idea are not we throwing the information?</em></strong></p><p>It depends. Basically if the prediction value can be addressed by one feature why to use another feature which is highly correlated with the first feature.Since tree based model internally choose a feature for splitting based on information gain it does not matter actually to have correlated features.It will ignore them but training time decreases.For distance based method like logistic regression yes it will not affect the AUC score but the weight we will get will be stable one.</p><p>“ <strong>Tree</strong>-<strong>based</strong> models have an innate <strong>feature</strong> of being robust to <strong>correlated features</strong>. … For XGBoost users: as you are using the combination of both (<strong>tree</strong>-<strong>based</strong> model, GBM-<strong>based</strong> model), adding or <strong>removing correlated</strong> variables should not hit your scores but only decrease the computing time necessary.”</p><p>Now train the Logistic Regression model to see whether the performance reduced or unchanged after the droping of highly correlated features</p><p>The ROC AUC curve of LR model trained on the dataset after removing all the highly correlated features is as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*T4sZgViz8skmAROuWKeVxw.png" /></figure><p>The performance of the Logistic Regression model did not change after removing all the highly correlated features so the decision of removing of highly correlated features was right.</p><h4>Test Prediction :</h4><p>So finally after doing all of the things,our journey has come to end now it is time for the result.Since the LGBM model gives us the best auc i applied it on the test data and submit in the kaggle competition.And it gives 91.08 in test data.Which is great.</p><h4>End Notes :</h4><p><strong>Is it over?</strong>No never ,It is just a beginning. Datascience is all about experiment.Do some more analysis and try to find some new features which are helpful for our model.Try to apply different feature elimination technique even in this blog we have removed some of them still it is overfitting. Read the discussion forums in the kaggle it is great way of learning like how other peoples are approaching the same problem.Some of the great new features i found from the kaggle.</p><p>So thanks readers for reading my blog hope you like it and any suggestions to improve is highly welcomed.</p><p>Find full work on my GitHub repo <a href="https://github.com/abhishekmishra2612/IEEE-CIS-Fraud-Detection">here</a></p><p>Contant me on <a href="https://www.linkedin.com/in/abhishek-mishra-858609169/">LinkedIn</a></p><h3>Thank You</h3><h4>References</h4><ul><li><a href="https://www.kaggle.com/artgor/eda-and-models">EDA and models</a></li><li><a href="https://www.kaggle.com/c/ieee-fraud-detection/discussion/100400">IEEE-CIS Fraud Detection</a></li><li><a href="https://www.kaggle.com/c/ieee-fraud-detection/discussion/101696">IEEE-CIS Fraud Detection</a></li><li><a href="https://analyticsindiamag.com/5-ways-handle-missing-values-machine-learning-datasets/">5 Ways To Handle Missing Values In Machine Learning Datasets</a></li><li><a href="https://www.kaggle.com/jesucristo/fraud-complete-eda">Fraud complete EDA</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d011d6ef2fec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detect Nuclei- Semantic Segmentation]]></title>
            <link>https://medium.com/@abhishekmishra_22309/detect-nuclei-semantic-segmentation-c8212cf69ef0?source=rss-36c52c523c6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8212cf69ef0</guid>
            <dc:creator><![CDATA[Abhishek Mishra]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 12:40:48 GMT</pubDate>
            <atom:updated>2020-07-03T12:40:48.938Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A Case study of Nucleus segmentation from microscopic cell image using U-net</em></p><h3>Overview :</h3><p>Imagine speeding up research for almost every disease, from lung cancer and heart disease to rare disorders. <a href="https://www.kaggle.com/c/data-science-bowl-2018/overview">The 2018 Data Science Bowl</a> offers our most ambitious mission yet: create an algorithm to automate nucleus detection.</p><p>We’ve all seen people suffer from diseases like cancer, heart disease, chronic obstructive pulmonary disease, Alzheimer’s, and diabetes. Many have seen their loved ones pass away. Think how many lives would be transformed if cures came faster.</p><p>By automating nucleus detection, you could help unlock cures faster — from rare disorders to the common cold. Identifying the cells’ nuclei is the starting point for most analyses because most of the human body’s 30 trillion cells contain a nucleus full of DNA, the genetic code that programs each cell. Identifying nuclei allows researchers to identify each individual cell in a sample, and by measuring how cells react to various treatments, the researcher can understand the underlying biological processes at work.</p><p>So this is the task of Nucleus segmentation(Detect Nuclei) from microscopic cell image.</p><h4>Comparison between Image classification, Object detection and Semantic Segmentation:</h4><h4>Image classification :</h4><p>It is the basic task of computer vision field, where given an image of valid object and the model has to predict the class label of the object(out of some categorical class labels) in the given image. For image classification typically the training sample should have one image .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*K2enjlD0xkOP9qXHeHgXhA.png" /><figcaption>Image of Cat</figcaption></figure><p>here for example given an image of cat the model has to predict cat out of all the categories(cat, dog, rat, horse, car, truck, …) on which model have trained.</p><h4>Object Detection :</h4><p>It is also the computer vision task where given any image of multiple valid objects and model has to predict type of each objects and localize their position by bounding box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*DMh2oNjWhZ391PZMtv3puw.png" /><figcaption>Object Detection</figcaption></figure><p>Here for a given image containing multiple objects model predicted the class type of each valid objects and their position by bounding box.</p><h4>Semantic Segmentation :</h4><p>The goal of semantic image segmentation is to label each <strong>pixel </strong>of an image with a corresponding <strong>class</strong> of what is being represented. Because we’re predicting for every pixel in the image, this task is commonly referred to as <strong>dense prediction</strong>.</p><p>Note that unlike the previous tasks, the expected output in semantic segmentation are not just labels and bounding box parameters. The output itself is a high resolution image (typically of the same size as input image) in which each pixel is classified to a particular class. Thus it is a pixel level image classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgHLw45KG7-LR_ZSkAqRsw.png" /><figcaption>Semantic Segmentation</figcaption></figure><h3><strong>Business Problem :</strong></h3><p>Automatic segmentation of microscopy images is an important task in medical image processing and analysis. Nucleus detection is an important example of this task. Imagine speeding up research for almost every disease, from lung cancer and heart disease to rare disorders. The <a href="https://www.kaggle.com/c/data-science-bowl-2018"><strong>2018 Data Science Bowl</strong></a> offers our most ambitious mission yet: create an algorithm to automate nucleus detection.</p><p>For given a microscopic cell image having different pattern of nuclei and we have to detect the nuclei in the microscopic image, we will achieve this goal by deep learning model of Semantic segmentation using U-net.</p><h4>Understanding the Data :</h4><p>The DATASET for this problem can be get from <a href="https://www.kaggle.com/c/data-science-bowl-2018/data">here</a>.</p><p>There are 670 microscopic cell images and corresponding multiple mask images for each cell image for training data.</p><p>nd for test data there are 65 microscopic cell images and we have to predict their corresponding mask image. Here two sample of train data, where left image is the microscopic cell image and right image is corresponding mask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*vtcx4nfSNczU3NSZtiNV5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*OCSF6cQaD0KTLeafB8fSGA.png" /></figure><h4>Performance metrics :</h4><p>Performance metrics for this problem of semantic segmentation is mean IoU.</p><p>The Intersection-Over-Union (IoU), also known as the Jaccard Index, is one of the most commonly used metrics in semantic segmentation… and for good reason. The IoU is a very straightforward metric that’s extremely effective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*qULq1KaWx2HpXKuwxJuTfQ.png" /></figure><p><strong>IoU is the area of overlap between the predicted segmentation and the ground truth divided by the area of union between the predicted segmentation and the ground truth</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*tx9IqgSpyt3cd8UXfIFZdw.png" /><figcaption>Code snippet to compute mean IoU</figcaption></figure><h4>Data Augmentation :</h4><p>After getting the dataset for training and test since we have only 670 samples for train that is not enough data samples for training because the biggest problem in deep learning is chance of overfitting is very high because typically the parameters are very high for deep neural network so we have to collect huge training sample, but in this case we have few data points so we will do data sugmentation using <a href="https://keras.io/api/preprocessing/image/">keras ImageDataGenerator </a>module. Data augmentation an important task when we have less data. keep the same seed while augmenting the test and val images because it will initialize from the same point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mg8Bk3XT0LjsKj7sr0OBqg.png" /></figure><h3><strong>U-Net Architecture :</strong></h3><p>The <a href="https://arxiv.org/abs/1505.04597"><em>UNET </em></a>was developed by Olaf Ronneberger et al. for Bio Medical Image Segmentation. The architecture contains two paths. First path is the contraction path (also called as the encoder) which is used to capture the context in the image. The encoder is just a traditional stack of convolutional and max pooling layers. The second path is the symmetric expanding path (also called as the decoder) which is used to enable precise localization using transposed convolutions. Thus it is an end-to-end fully convolutional network (FCN), i.e. it only contains Convolutional layers and does not contain any Dense layer because of which it can accept image of any size.</p><p>In the original paper, the UNET is described as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*yDBszOL43WtPW5nsEKuNmw.png" /></figure><p>Note that in the original paper, the size of the input image is 572x572x3, however, we will use input image of size 128x128x3. Hence the size at various locations will differ from that in the original paper but the core components remain the same.</p><p>Keras code which describe the above U-net architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*Q1vNkpc7Z2LffGTCMv5ptA.png" /><figcaption>Contraction part : Encoder</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*qdUstq4-wtFl6NywQqNlOA.png" /><figcaption>Bottom part between Encoder and Decoder</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*0AQHod1e9twAnKPQ7ztMVg.png" /><figcaption>Expansion part : Decoder, and defining model</figcaption></figure><h4><strong>Training :</strong></h4><p>Model is compiled with Adam optimizer and we use binary cross entropy loss function since there are only two classes (Nucleus and no Nucleus).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*Hn0wWT6KRcAvbiz8aJA7-A.png" /><figcaption>Compile</figcaption></figure><p><strong>We use </strong><a href="https://keras.io/api/callbacks/"><strong>Keras Callback</strong></a><strong> to implement</strong></p><blockquote><em>Early Stopping to stop training if validation loss does not decreases for 4 continues epochs.</em></blockquote><blockquote><em>Save the weights only if there is decrease in the validation loss.</em></blockquote><blockquote><em>Save the best model till the training has stopped.</em></blockquote><p>We used 30 epochs, and batch size of 10.</p><p>Note that there could be a lot of scope to tune these hyper parameters and further improve the model performance.</p><h4><strong>Inference :</strong></h4><p>Note that for each pixel we get a value between 0 to 1.<br>0 represents no Nucleus and 1 represents Nucleus.<br>We take 0.5 as the threshold to decide whether to classify a pixel as 0 or 1.</p><p>However deciding threshold is tricky and can be treated as another hyper parameter.</p><h4><strong>Result on a training cell image</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*dhKuzAoo-TmfbKrkJnIATw.png" /></figure><h4><strong>Result on some unseen test microscopic cell images</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*n39Sw3PnLAeHyIGcxG5cnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*K7lcafFHDPsmRT_HcM62bA.png" /></figure><h4><strong>Conclusion</strong></h4><p>Thank you for interest in the blog. Please leave comments, feedback and suggestions if you feel any.</p><p>Full code on my GitHub repo <a href="https://github.com/abhishekmishra2612/Nucleus-segmentation-using-U-net">here</a></p><p>you can contact me on <a href="https://www.linkedin.com/in/abhishek-mishra-858609169/">LinkedIn</a></p><h4>References</h4><ul><li><a href="https://arxiv.org/abs/1505.04597">U-Net: Convolutional Networks for Biomedical Image Segmentation</a></li><li><a href="https://medium.com/activating-robotic-minds/up-sampling-with-transposed-convolution-9ae4f2df52d0">Up-sampling with Transposed Convolution</a></li><li><a href="https://towardsdatascience.com/metrics-to-evaluate-your-semantic-segmentation-model-6bcb99639aa2">Metrics to Evaluate your Semantic Segmentation Model</a></li><li><a href="https://www.kaggle.com/c/data-science-bowl-2018/discussion">2018 Data Science Bowl</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8212cf69ef0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>