<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://anilkumarpanda.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://anilkumarpanda.github.io/" rel="alternate" type="text/html" /><updated>2025-04-04T19:45:45+00:00</updated><id>https://anilkumarpanda.github.io/feed.xml</id><title type="html">Anilkumar Panda</title><subtitle>Data Scientist</subtitle><entry><title type="html">Error Analysis for Tabular Data - Part-2 (Residual Analysis)</title><link href="https://anilkumarpanda.github.io/ResidualAnalysis/" rel="alternate" type="text/html" title="Error Analysis for Tabular Data - Part-2 (Residual Analysis)" /><published>2022-04-15T00:00:00+00:00</published><updated>2022-04-15T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/ResidualAnalysis</id><content type="html" xml:base="https://anilkumarpanda.github.io/ResidualAnalysis/"><![CDATA[<p>Residuals refer to the difference between the recorded value of a dependent variable and the predicted value of a dependent variable for every row in a data set. Plotting the residual values against the predicted values is a time-honoured model assessment technique and a great way to see all your modelling results in two dimensions.</p>
<p>Analysing residuals can provide us with great insights about the model behaviour both on a global level and also on a feature level.It can reveal insights such about the data points for which our model is making mistakes.</p>
<p>I will explore two methods for residual analysis:</p>
<ol>
<li>Residual analysis on global &amp; feature level</li>
<li>Modelling of residuals</li>
</ol>
<p>For demonstration purposes, I will explore the model created on Lending Club data.The data is available on <a href="https://www.kaggle.com/datasets/wordsforthewise/lending-club">Kaggle</a>.The task is to create a binary classification model, to predict loan defaults at the time of loan origination. Such models are also known as Application models/score models.</p>
<p>A lightgbm model was created. The details of the model can be found below.
<img src="../images/ra_lc_model_scorecard.png" alt="lending clun model" />
Now that we have a model, lets start with the residual analysis.</p>
<h3 id="residual-analysis-on-global-level">Residual Analysis on Global Level</h3>
<p>Here I will explore the model behaviour on the global level. The plot shows the model residuals against the actual values(classes) of the dependent variable.</p>
<p><img src="../images/ra_global.png" alt="global residuals" /></p>
<p>We see that indeed the model is making quite a few mistakes(large residuals). Especially for <code>loan_status==1</code>. This raises a few interesting questions :</p>
<ul>
<li>Who are these customers?</li>
<li>Why is the model so wrong about them?</li>
<li>Are they somehow exerting undue influence on other predictions?</li>
</ul>
<p>To answer these questions we can also conduct residual analysis on the feature level.</p>
<h3 id="residual-analysis-on-feature-level">Residual Analysis on Feature Level</h3>
<p>In this method, we will plot the residuals against the predicted values of the dependent variable for each feature(or at-least a few important features).
In our case, let us take the example of the <code>grade</code> feature.</p>
<p>Intuitively ,higher the grade, less chances of default. However on closer analysis we see that the model is making mistakes for the customers who have a grade of <code>A</code> or <code>B</code> i.e providing high residuals.</p>
<p><img src="../images/ra_feature_level.png" alt="ra_grade" /></p>
<p>This is an interesting observation. That means that the model is making more errors if an application has as higher assigned grade.
A similar analysis can also be done for numerical features, where we bin the variable and look at the residuals for each bin.</p>
<p>Residuals analysis on feature level can be used to understand the model behaviour in an univariate way.
Can we identity more such failure modes for the model? A definite pattern in which the model is making mistakes?</p>
<h3 id="modelling-of-residuals">Modelling of Residuals</h3>
<p>Modelling residuals with interpretable models is another great way to learn more about the mistakes your AI system could make. e.g A decision tree model of the example ML model’s residuals for loan_default = 1, or customer’s who default. While it reflects what was discovered before, it does so in a very direct way that exposes the logic of the failures.In fact, it’s even possible to build programmatic rules about when the model is likely to fail the worst.</p>
<p><img src="../images/ra_modeling_residuals.png" alt="residual_modelling" /></p>
<ul>
<li>
<p>model shows high residuals when the loan <code>Grade = A and DTI &lt;= 20</code> essentially when a <code>good looking</code> application fails.</p>
</li>
<li>
<p>this indicates that only the above features are not good enough. We need to create features that deal with deeper customer behaviours.</p>
</li>
</ul>
<p>To summarise, the residual analysis is a great way to understand the model behaviour. These simple plots can help you uncover pockets of data that are likely to be the cause of the model’s failure.
Once you identify these you can either</p>
<ol>
<li>Analyse the default rates in grade A, B, C where the DTI is less than 20.
It could also be that, most of the defaults are of applications of lower grade.
Thus the ML models provides more weightage to those defaults. Providing higher weights to defaults with grade A,B,C could help.
Which indeed is the case, when we provide more weightage to applications from grade A,B,C compared to others. The performance of the model increases slightly from 0.68 to 0.69.</li>
<li>Engineer new features</li>
<li>Collect more data wherever possible</li>
<li>Create business rules at inference time.</li>
</ol>
<h4 id="further-analysis">Further Analysis</h4>
<p>The code to produce the plots can be found in the <a href="https://github.com/anilkumarpanda/blog_series/blob/master/notebooks/02_residual_analysis.ipynb">repo</a></p>
<p>A big shout out to <a href="https://github.com/jphall663">Patrick Hall</a> for the great work on <a href="https://nbviewer.org/github/jphall663/GWU_rml/blob/master/lecture_5.ipynb">model debugging</a>.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Residuals refer to the difference between the recorded value of a dependent variable and the predicted value of a dependent variable for every row in a data set. Plotting the residual values against the predicted values is a time-honoured model assessment technique and a great way to see all your modelling results in two dimensions.]]></summary></entry><entry><title type="html">Monotonic Constraints for Boosting Models.</title><link href="https://anilkumarpanda.github.io/MonotonicConstraints/" rel="alternate" type="text/html" title="Monotonic Constraints for Boosting Models." /><published>2022-03-29T00:00:00+00:00</published><updated>2022-03-29T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/MonotonicConstraints</id><content type="html" xml:base="https://anilkumarpanda.github.io/MonotonicConstraints/"><![CDATA[<p>Boosting models like XGBoost, LightBoost have been some of the go to model for tabular datasets.This is because these models are highly performant and are able to learn various non-linear relationships within the datasets.However sometimes in the real world,creating an high performant model can result in a non-intuitive model. There are also requirements to include domain knowledge into the ML models.</p>
<p>Monotonicity constraints (MC), help us to achive the above objetives. Adding MC constraints helps with :</p>
<ul>
<li>Creating <code>interpretable</code> boosting models.</li>
<li>Incorporating domain knowledge into the ML models.</li>
</ul>
<p>This generally leads to models with less overfitting.
In this blog post, we will compare two models created on the same dataset without and with MC. We will compare the model performances and further improve on them if required.</p>
<p>To be continued...</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Boosting models like XGBoost, LightBoost have been some of the go to model for tabular datasets.This is because these models are highly performant and are able to learn various non-linear relationships within the datasets.However sometimes in the real world,creating an high performant model can result in a non-intuitive model. There are also requirements to include domain knowledge into the ML models.]]></summary></entry><entry><title type="html">ML Model Metric Credibility</title><link href="https://anilkumarpanda.github.io/MetricCredibility/" rel="alternate" type="text/html" title="ML Model Metric Credibility" /><published>2022-03-09T00:00:00+00:00</published><updated>2022-03-09T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/MetricCredibility</id><content type="html" xml:base="https://anilkumarpanda.github.io/MetricCredibility/"><![CDATA[<p>&quot;How confident are you that the model performance (on test data) is not below 0.75 AUC ?&quot;.I came across this question in my work.This inspired me to write this blog.</p>
<p>Generally we calculate the model performance on an holdout test dataset. For example if you are working in the risk domain, you would train your model on historical data and the latest data for which performance can be measured will be used as test set.</p>
<p>We will get a certain model performance on the test data. How confident are we, that the model performance is above a certain threshold on a similar dataset? Assuming the data characteristics have not changed. One way to do that is to calculate the model performance on another test dataset. Why not! The challenge is labelled data is quite hard to obtain in almost all scenarios. <em>If data is oil, good labelled data is gold.</em> So we cannot get another test dataset.</p>
<p>Well then , let's sample the test data and calculate the model performance ? In that case, I assume the model performance will be similar and based on the sampling parameters the results can vary. The assumptions of independence are not satisfied.</p>
<p>Is there a python package for it ?</p>
<p>Generally model KPI's have a lower limit. Businesses would gladly accept a model with higher performance in the real world than reported at the time of development. The inverse would not be true. That is to say model performance below a lower limit will be unacceptable and the model would not be used.</p>
<p>For example, in classification setting roc-auc is a standard KPI. Lets say the minimum KPI for ROC-AUC is 0.75 for your project.If we have roc-auc on the test data of 0.8. What are the chances that given more data, the model performance on the test data would drop below 0.75 ?</p>
<p><a href="https://finraos.github.io/model-validation-toolkit/">Model Validation Toolkit's</a> can help us to calculate that. A detailed explanation can be found in  the <a href="https://finraos.github.io/model-validation-toolkit/docs/html/credibility_user_guide.html">credibility section</a>. TL;DR they use <a href="https://en.wikipedia.org/wiki/Beta_distribution">beta-distribution</a> to do that.</p>
<p>Let's take the example for the <a href="https://anilkumarpanda.github.io/ErrorAnalysis/">model</a> I created for the FICO challenge.
The model test performance is 0.79. After plugging in the required variables,</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">mvtk</span> <span class="kn">import</span> <span class="n">credibility</span>
<span class="c1"># Number of positive samples in the test set
</span><span class="n">positives</span> <span class="o">=</span> <span class="mi">1539</span>
<span class="c1"># Number of negative samples in the test set
</span><span class="n">negatives</span> <span class="o">=</span> <span class="mi">1420</span>
<span class="c1"># ROC-AUC of the model
</span><span class="n">roc_auc</span> <span class="o">=</span> <span class="mf">0.79</span>
<span class="c1"># ROC-AUC cutoff
</span><span class="n">cutoff</span> <span class="o">=</span> <span class="mi">75</span><span class="o">/</span><span class="mi">100</span>
<span class="n">auc_positives</span><span class="p">,</span> <span class="n">auc_negatives</span> <span class="o">=</span> <span class="n">credibility</span><span class="p">.</span><span class="n">roc_auc_preprocess</span><span class="p">(</span><span class="n">positives</span><span class="p">,</span> <span class="n">negatives</span><span class="p">,</span> <span class="n">roc_auc</span><span class="p">)</span>
<span class="n">prob_below</span> <span class="o">=</span> <span class="n">credibility</span><span class="p">.</span><span class="n">prob_below</span><span class="p">(</span><span class="n">auc_positives</span><span class="p">,</span> <span class="n">auc_negatives</span><span class="p">,</span> <span class="n">cutoff</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
<span class="k">print</span><span class="p">(</span><span class="sa">f</span><span class="s">'Probability of ROC-AUC being below </span><span class="si">{</span><span class="n">cutoff</span><span class="si">}</span><span class="s"> is : </span><span class="si">{</span><span class="n">prob_below</span><span class="si">:</span><span class="p">.</span><span class="mi">2</span><span class="n">f</span><span class="si">}</span><span class="s">%'</span><span class="p">)</span>

</code></pre></div></div>
<p>We see that the probability of ROC-AUC being below 0.75 is : 0.00% Sweet !!
So we can be confident that given more data(without drift), our model AUC will most likely not drop below the cut-off.</p>
<p>Similarly, we can also calculate the metric credibility for other performance measures like precision,recall etc.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[&quot;How confident are you that the model performance (on test data) is not below 0.75 AUC ?&quot;.I came across this question in my work.This inspired me to write this blog.]]></summary></entry><entry><title type="html">Error Analysis for Tabular Data - Part 1</title><link href="https://anilkumarpanda.github.io/ErrorAnalysis/" rel="alternate" type="text/html" title="Error Analysis for Tabular Data - Part 1" /><published>2021-09-29T00:00:00+00:00</published><updated>2021-09-29T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/ErrorAnalysis</id><content type="html" xml:base="https://anilkumarpanda.github.io/ErrorAnalysis/"><![CDATA[<p>Error analysis simply means looking the misclassified data points and trying to infer why is the model making error on this subpopulation.
There are some great videos/blogs about how to do error analysis for text/image data. e.g <a href="https://www.youtube.com/watch?v=JoAxZsdw_3w">video by Andrew Ng</a>.</p>
<p>However I could not find anything related to error analysis for tablular data. One of the reason, I can think of is that it is intuitively diffcult to look at tabluar data and see if the model is misclassifying the data.
Sure there many python packages that help you to do that. e.g erroranalysis , mealy etc .However they are limited to showing you how to use the library and not how to use the error analysis methods to improve model performance. We will be using some of these in this blog post.</p>
<p>A model misclassifaction can be due to many reasons :</p>
<ol>
<li>The data point has data quality issue. E.g loan given to a 300 year old person.</li>
<li>The data point is an outlier. E.g a very wealthy person defaulting on a small loan.</li>
<li>There are very few examples for the model to learn. E.g There are only 5 customers with an car loan, thus the model has not learnt much from this dataset.</li>
<li>Model bias : Due to the inherit limitations of the model,the classification hasn't been done correctly. E.g Linear model assumptions.</li>
</ol>
<p>With error analysis we can identify which subset of the dataset the model is making the most mistakes and then try to improve upon it.
Thus we can look inot are the problematic features, and what are the typical values of these features for the mispredicted samples.
This information can later be exploited to support the improvement strategy. Which can one of the following as mentioned on the <a href="https://doc.dataiku.com/dss/latest/machine-learning/supervised/model-error-analysis.html">Dataiku website</a></p>
<ol>
<li>Improve model design: removing a problematic feature, removing samples likely to be mislabeled, ensemble with a model trained on a problematic subpopulation;</li>
<li>Enhance data collection: gather more data regarding the most erroneous or under-represented populations;</li>
<li>Select critical samples for manual inspection thanks to the Error Tree, and avoid primary predictions on them using model assertions.</li>
</ol>
<p>All of these are interesting options in this blog post I will focus on the 1 option. We will explore this via a ML model created on the HELOC dataset provied in the <a href="https://community.fico.com/s/explainable-machine-learning-challenge">FICO Explainability Challenge</a>.
The data and the metadata can be obtained by <a href="https://community.fico.com/s/explainable-machine-learning-challenge?tabset-158d9=3">filling this form</a></p>
<h2 id="problem-statement">Problem Statement</h2>
<p>In this challenge we are tasked to predict the variable <code>RiskPerformance</code>. I will not go into detail about the problem and the predictor variables. You can read the details in the <a href="https://community.fico.com/s/explainable-machine-learning-challenge">FICO Explainability Challenge website</a>.</p>
<p>The dataset is balanced with ~52% postive class and ~48% negative class.</p>
<h2 id="ml-model">ML Model</h2>
<p>Before error analysis,we need a model,so lets go ahead build one. We will make use of many packages to make our life easy.
Main among them are <a href="https://ing-bank.github.io/probatus/index.html">Probatus</a> for feature selection and analysis,<a href="https://www.scikit-yb.org/en/latest/api/classifier/threshold.html">Yellowbrick</a> for decidicng threshold,<a href="https://xgboost.readthedocs.io/en/latest/index.html">XGBoost</a> for classification and <a href="https://erroranalysis.ai/">erroranalysis</a> for erroranalysis and offcourse scikit-learn for all other things.</p>
<h3 id="train-test-selection">Train Test Selection</h3>
<p>The dataset is divided in training and testing set with %30 of the samples in the test set.</p>
<h3 id="feature-selection-amp-hp-tuning">Feature Selection &amp; HP Tuning</h3>
<p>The ShapRFECV - Recursive Feature Elimination using SHAP importance from the Probatus is used for feature selection. As the name suggests it uses Shapley Values to eliminate features in a recurvise manner.</p>
<p><img src="../images/ea_feature_selection.png" alt="feature selection" /></p>
<p>As the plot suggests, we can use only 5 features and achieve the maximum performance(roc-auc) in this case.</p>
<ul>
<li><code>NetFractionRevolvingBurden</code></li>
<li><code>NumSatisfactoryTrades</code></li>
<li><code>AverageMInFile</code></li>
<li><code>MSinceMostRecentInqexcl7days</code></li>
<li><code>ExternalRiskEstimate</code></li>
</ul>
<p>Once the features are selected lets tune the parameters for the XGBClassifier.
The initial parameter grid is used as suggested in the book <a href="https://github.com/abhishekkrthakur/approachingalmost">Approaching (Almost) Any Machine Learning Problem</a></p>
<p>The model has the following performance.</p>
<p><img src="../images/ea_perf_before.png" alt="before performance" /></p>
<p>There is a slight overfit,however this is <code>decent</code> model for the purposes of this blog.</p>
<h3 id="feature-importance">Feature Importance</h3>
<p>If we look at the SHAP feature importances we notice that <code>ExternalRiskEstimate</code> is the most predictive feature.</p>
<p><img src="../images/ea_feature_importance.png" alt="feature importance" /></p>
<p>I have observed that in most cases, the feature impartances follow the Pareto 80:20 rule. That is 20% of the features provide 80% of the performance.
Hence if we can spot and rectify issues in the most important features, that chances of improvement is quite much.</p>
<h2 id="error-analysis">Error Analysis</h2>
<p>So far so good. Now lets begin with error analysis. For this we will use <code>ErrorAnalysisDashboard</code> provided <a href="https://erroranalysis.ai/">Microsoft</a>.
The ouput of the <code>ErrorAnalysisDashboard</code> is a interactive wiget containing the error tree. There are many more functionalaties like the grid view,ability to exclude features from the error tree etc.
However I will skip that and focus on the use case which is improving the model via erroranalyis.
You can see other functionalaties provided by the package in the <a href="https://github.com/microsoft/responsible-ai-widgets/tree/main/notebooks">examples notebooks</a></p>
<p><img src="../images/ea_board_before_filtering.png" alt="ea dashboard" /></p>
<p>To identifty important failure patterns, look for nodes with a stronger <code>dark red</code> (i.e., high error rate) and a higher fill line (i.e., high error coverage)</p>
<ul>
<li>Error coverage shows the percentage of errors that are concentrated in the selection out of all errors present in the dataset.</li>
<li>Error rate represents the percentage of instances in the node for which the system has failed.</li>
</ul>
<p>Ideally it makes sense to start the error analysis process by looking into these leaf nodes first.</p>
<p>For our usecase, we can see that for data points where <code>ExternalRiskEstimate &lt;= 83.50</code> and <code>NetFractionRevolvingBurden &lt;= 59.50</code> and <code>NumSatisfactoryTrades &lt;= 1.50</code> the error rate is 48.11 % and the error coverage is 9.75%.</p>
<p>Next, lets look into these features and see if we can spot something, which look like either data quality or anamolies.</p>
<p>If we look the <code>ExternalRiskEstimate</code> feature, we notice that there are few data points with values &lt; 0.
A <code>ExternalRiskEstimate</code> of less that 0 looks like a data quality issue and can be eliminated.</p>
<p><img src="../images/ea_dep_external_risk.png" alt="External Risk Estimate" /></p>
<p>Similarly if we look at the <code>NumSatisfactoryTrades</code> feature, there are few datapoints with values &lt; 0 .
Number of trades with values &lt; 0 again seems like a data quality issue. We will eliminate these as well.</p>
<p><img src="../images/ea_dep_trades.png" alt="Num Trades" /></p>
<p>Once we remove the datapoints and rerun the model, we get the following model results.</p>
<p><img src="../images/ea_perf_after.png" alt="before performance" /></p>
<p>The model performance has improved!</p>
<p>Similarly one can look at other variable/s and identify datapoints leading to error and treat them.
In this example, we eliminated the data points, however in your own use case these points colud be treated differenlty based on business knowledge.</p>
<p>Apart from the library used above,<a href="https://github.com/dataiku-research/mealy">mealy</a> is another library that can be used for error analysis.</p>
<p>The notebook and code for reproducing the above results can be found in <a href="https://github.com/anilkumarpanda/erroranalysis/blob/main/notebooks/error_analysis.ipynb">my github account</a>.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Error analysis simply means looking the misclassified data points and trying to infer why is the model making error on this subpopulation. There are some great videos/blogs about how to do error analysis for text/image data. e.g video by Andrew Ng.]]></summary></entry><entry><title type="html">Active Learning</title><link href="https://anilkumarpanda.github.io/ActiveLearning/" rel="alternate" type="text/html" title="Active Learning" /><published>2021-09-25T00:00:00+00:00</published><updated>2021-09-25T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/ActiveLearning</id><content type="html" xml:base="https://anilkumarpanda.github.io/ActiveLearning/"><![CDATA[<p>While browsing Twitter , I came across this <a href="https://twitter.com/abhi1thakur/status/1441088040873578500">tweet</a> by Abhishek.</p>
<p><img src="../images/abhi_labelling.png" alt="Labelling data" /></p>
<p>Though it is meant as a joke, there is quite some truth to it. Everybody wants to build a ML model, but many dont want to put effort into obtaining/creating datasets.
Many a times in a company, there exists vast unlablled datasets. Value in these datasets can be unlocked, if they can be labelled efficiently.</p>
<p>The branch of machine learning that deals with labelling data is called Active Learning.
Though it is quite a vast field, I will try to provide a summary of the most frequent(read easy) methods used,some learning and ofcourse links to different resources.</p>
<h2 id="active-learningal-aka-query-learning">Active learning(AL) aka Query Learning</h2>
<p>Active learning (sometimes called “query learning” or “optimal experimental design” in the statistics literature)
is a subfield of machine learning and, more generally, artificial intelligence. The key hypothesis is that if the learning algorithm is allowed to choose the data from which it learns—to be “curious,” if you will—it will perform better with less training.</p>
<p>An AL process typically consists of the following steps:</p>
<ol>
<li>Having access to an pool of unlabeled data.</li>
<li>Labelling either by randomly sampling the data or filtering based on some rules, then labelling the data.</li>
<li>Creating a ML model based on the labelled data.</li>
<li>Scoring the remaining the dataset with the model trained in step 3.</li>
<li>Choosing the <em>best</em> datapoints to label next and continuing stpes 3-5.</li>
<li>Stopping , when a stopping criteria is achieved.</li>
</ol>
<p><img src="../images/active_learning_process.png" alt="Active Learning Process" /></p>
<p>From my experience the crux of AL lies in steps 2. i.e how to bootstrap the process and step 4. how to choose the best samples for labelling.</p>
<h3 id="begin-labelling">Begin Labelling</h3>
<p>Once you have the unlabelled dataset and a defintion of what a class looks like (e.g dog vs cat), the easiest way to start is to randomly select a sample and label them.
However, if the dataset has a high class imbalance, then randomly selections will not yield many samples of the minority class.
In such cases, you should start with simple rules, rules that have a high chances yielding the class of interest.</p>
<p>Unsupervised clustering can also be used. Then you can assign a label to an cluster and move ahead.</p>
<p>Once a decent number of samples have been labelled, you can train any classifier on this labelled set and score the unlabelled set.</p>
<h3 id="chosing-points-for-labelling">Chosing points for labelling:</h3>
<p>Once you have scored the remaining unlabelled datapoints, next step is to label points that :</p>
<ul>
<li>either move the decision boundary of the classifier the most  or</li>
<li>improve the loss metric the most.</li>
</ul>
<p>To achive this you can many methods, however the most simple ones being :</p>
<h4 id="uncertainity-sampling">Uncertainity Sampling:</h4>
<p>Consider a binary classification problem. You have created an intial labelling set and trained a ML model as mentioned in steps 1-3 above.
After scoring the unlabeled set, you choose the data points to label, for which the model is the least confident.
i.e the where the predicted probability is close to 0.5 (or median). Those the data points for which the model is least confident and will gain the most with human labelling/knowledge.
Different variations of this technique are entropy sampling and margin sampling.</p>
<p>The main disadvantages of such methods are that they are prone to get stuck in a localised region of problem space and are also prone to outliers.
The next methods tries to resolve this disadvantages.</p>
<h4 id="query-based-sampling-">Query based sampling :</h4>
<p>In the query based sampling method, you train multiple classifiers from diffrent family of classifiers. They choose the points for human labelling where most of the classifiers disagree.
This is slighly complex methods, but has some advantages over uncertainity sampling.</p>
<h3 id="combination-of-sampling-methods">Combination of sampling methods:</h3>
<p>It is advised to start with random / query-based sampling can usedfor cold start when no classifier is available.
Then one can move to more sophisticated approaches. You can also multiple methods.</p>
<p><img src="../images/al_elbow_method.png" alt="sampling_combinations" /></p>
<h3 id="stopping-criteria">Stopping criteria:</h3>
<p>The AL process can be stopped when :</p>
<ol>
<li>The allocated budget is over, i.e either the time/ resources assigned to for AL are exhausted.</li>
<li>The model KPI is reached.</li>
<li>Despite labelling more data points the final model preformance does not improve.</li>
</ol>
<p>Though there are many libraries that help you to implement AL e.g <a href="https://modal-python.readthedocs.io/en/latest/">modal</a>, <a href="https://github.com/NUAA-AL/ALiPy">ALipy</a>
I found it easiser to create an custom interface in <a href="https://streamlit.io/">streamlit</a> and implement various sampling methods.</p>
<p>I have used AL in a few some projects with good success, main among them are :</p>
<ol>
<li>AL was used to <a href="youtube.com/watch?v=oyMawG0SlPU">solve a cold start problem in NLP</a> for ING.</li>
<li>Dataset used to train the <a href="https://twitter.com/bot_esr">ESR Bot</a> was created using AL.
This twitter bot tweets about the various environment related news to spread awareness.</li>
</ol>
<p>Another package that uses AL is <a href="https://www.deduplipy.com/">Deduplipy</a> created by <a href="https://www.linkedin.com/in/frits-hermans-data-scientist/">Frits Hermans</a>.
It implements deduplication using active learning.</p>
<p>If you interested to use active learning in your project or have any questions/feedback about this blog <a href="../about.html">do reach out</a></p>
<h2 id="references">References</h2>
<ol>
<li><a href="http://burrsettles.com/pub/settles.activelearning.pdf">Survey of Active Learning approaches</a></li>
<li><a href="https://www.youtube.com/watch?v=0efyjq5rWS4">Pycon DE 2018</a></li>
<li><a href="https://learning.oreilly.com/videos/strata-dataconference/9781492050520/9781492050520-video324208">Cold start problem for NLP</a>- paywalled</li>
<li><a href="http://active-learning.net/">Active Learning webiste</a></li>
</ol>]]></content><author><name></name></author><summary type="html"><![CDATA[While browsing Twitter , I came across this tweet by Abhishek.]]></summary></entry><entry><title type="html">Thoughts on Feature Selection</title><link href="https://anilkumarpanda.github.io/FeatureSelection/" rel="alternate" type="text/html" title="Thoughts on Feature Selection" /><published>2020-04-14T00:00:00+00:00</published><updated>2020-04-14T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/FeatureSelection</id><content type="html" xml:base="https://anilkumarpanda.github.io/FeatureSelection/"><![CDATA[<p>All practioners of ML know that feature selection is important and is helpful to reduce the unwanted signal in your dataset.</p>
<p>Feature selection methods can be categorised as follows:</p>
<ol>
<li>Filter methods e.g selection based on co-relation, mutual information.</li>
<li>Wrapper methods e.g recursive feature elimination.</li>
<li>Embedded methods e.g Tree based feature importances.</li>
</ol>
<p>All methods suffer from some advantages and disadvantages.The primary distinguishing factors being speed vs chances of overfitting.
In terms of speed  Filter methods are faster than embedded methods which are faster than wrapper methods.
Wrapper methods have a higher chance of overfitting compared to embedded and filter methods.</p>
<p>To balance out the pros and cons a combined approach can be followed as shown below:</p>
<img src="../images/feature_selection.png" alt="Feature Selection" style="float: left; margin-right: 10px;" />
<p>The main points to take into consideration are :</p>
<ol>
<li>
<p>Feature selection should be done in consultation with the business experts.They have insights into the business problem and can guide in eliminating some features right away e.g some feature which are very unstable or in the case of co-related feature which features to eliminate etc. They can also validate the results of feature selection.</p>
</li>
<li>
<p>Bootstrapped sampling strategy can be used for feature selection, as features which are important in the entire dataset will be important in the sampled data as well.</p>
</li>
</ol>]]></content><author><name></name></author><summary type="html"><![CDATA[All practioners of ML know that feature selection is important and is helpful to reduce the unwanted signal in your dataset.]]></summary></entry><entry><title type="html">MultiObjective Optimisation with Genetic Algorithm</title><link href="https://anilkumarpanda.github.io/MOGA/" rel="alternate" type="text/html" title="MultiObjective Optimisation with Genetic Algorithm" /><published>2019-11-16T00:00:00+00:00</published><updated>2019-11-16T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/MOGA</id><content type="html" xml:base="https://anilkumarpanda.github.io/MOGA/"><![CDATA[<p>For most of the problems in real world, we have to optimise on two or more objective functions .
Eg in the case of machine learning problems we may have to optimise on two or more objective function like  maximise accuracy vs increase interpretability . Almost always these objective functions will be
orthogonal to each other.</p>
<p>There are nulptiple ways to solve Mutliobjective problems, however in this post we will focus a specific
algorithm called NGSA II ( Non Dominatated sorting using Genetic Algorithm) .
There is a excellent lecture series you can follow <a href="https://www.youtube.com/watch?v=Hm2LK4vJzRw">here</a> for the theory and examples. I will focus here on the pratical application and esp in the field of machine learning .</p>
<p>Before we go ahead, let us learn the basic building blocks of Genetic algorithms and Pareto Optimisation .</p>
<ol>
<li>
<p><strong>Genetic algorithm</strong> : It is an optimisation technique, that relies on two major principles.
a.Diversity Preservation
b.Selection pressure
Follow the lectures <a href="https://www.youtube.com/watch?v=Z_8MpZeMdD4&amp;t=6s">here</a> for an amazing introduction .</p>
</li>
<li>
<p><strong>Pareto Solutions</strong> : A set of solutions to an multi objective problem, is said to be a Pareto optimal solution if it is better in atleast one objective without it being worse for the other .</p>
</li>
<li>
<p><strong>Pareto Front</strong> : A set of all Pareto optimal solutions are called as Pareto Front .</p>
</li>
</ol>
<p>NSGA-II approach combines both the above principles to provide solutions to an Multiobjective problem .</p>
<p>Some of the scenarios where MOGA can used inlcude:</p>
<ol>
<li>Reduce complexity of our ML solution but increase/decrease the selected metric (accuracy,roc-auc, precision, recall) etc.</li>
<li><a href="https://medium.com/ing-blog/optimising-knockout-rules-for-lending-69b226e68b42">Optimise knockout rules in the lending process</a>.</li>
</ol>]]></content><author><name></name></author><summary type="html"><![CDATA[For most of the problems in real world, we have to optimise on two or more objective functions . Eg in the case of machine learning problems we may have to optimise on two or more objective function like maximise accuracy vs increase interpretability . Almost always these objective functions will be orthogonal to each other.]]></summary></entry><entry><title type="html">Up and running!</title><link href="https://anilkumarpanda.github.io/HelloWorld/" rel="alternate" type="text/html" title="Up and running!" /><published>2019-11-15T00:00:00+00:00</published><updated>2019-11-15T00:00:00+00:00</updated><id>https://anilkumarpanda.github.io/HelloWorld</id><content type="html" xml:base="https://anilkumarpanda.github.io/HelloWorld/"><![CDATA[<p>Hello there, this is my personal blog to note down my thoughts both personal and professional.
I plan to write about technology, the books I have read, the side project I am working on etc.
I also plan to share my ideas freely here, so that others can discuss it with me and contribute as well .</p>
<p>You too can create your own blog website, following instructions from <a href="https://github.com/barryclark/jekyll-now">Jekyll Now repository</a> on GitHub.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Hello there, this is my personal blog to note down my thoughts both personal and professional. I plan to write about technology, the books I have read, the side project I am working on etc. I also plan to share my ideas freely here, so that others can discuss it with me and contribute as well .]]></summary></entry></feed>