<?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 Raveena on Medium]]></title>
        <description><![CDATA[Stories by Raveena on Medium]]></description>
        <link>https://medium.com/@noorhanbo?source=rss-118e9d759119------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*orhIjKPQ9zguB4mwem0DpA.jpeg</url>
            <title>Stories by Raveena on Medium</title>
            <link>https://medium.com/@noorhanbo?source=rss-118e9d759119------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 04:35:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@noorhanbo/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[Help! How do I Feature Select?]]></title>
            <link>https://medium.com/data-science/help-how-do-i-feature-select-eaf37e58fdaf?source=rss-118e9d759119------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaf37e58fdaf</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[feature-selection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Raveena]]></dc:creator>
            <pubDate>Wed, 05 Aug 2020 16:21:51 GMT</pubDate>
            <atom:updated>2020-08-06T02:01:27.457Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Often times, we’re not sure how to choose our features. This is just a small guide to help choose. (Disclaimer: For now I’ll talk about binary classification.)</em></p><p>Many times, when we are super-excited to predict using a fancy machine-learning algorithm, and we’re almost ready to apply our models to analyze and make classifications on the test data-set–– we don’t exactly know what features to pick. Often times, the # of features can range from tens to thousands, and it’s not exactly clear how to pick <em>relevant</em> features, and how <em>many</em> features we should select. Sometimes it’s a not a bad idea to <em>combine</em> features together, also known as feature engineering. A common example of this, you’ve probably heard in machine-learning –– is <em>principal components analysis (PCA)</em>, where the data matrix X is factorized into its singular-value-decomposition (SVD) <em>U*∑*V</em>, where ∑ is a diagonal matrix with singular values, and the # of singular values you choose determines how <em>many </em>principal components. You can think of principal-components as a way to <em>reduce the dimensions</em> of your data-set. The awesome thing about PCA is that the new engineered features, or “principal-components”, are linear combinations of the original features. And that’s great! We love linear combinations, because it only involves addition and scalar-multiplication, and they’re not too hard to interpret. For example, if you did PCA on a dataset about house-price regression, and say you only selected 2 principal components. Then the first component, PC1, could be: <em>c1*</em>(# of bedrooms)+<em>c2*</em>(# sq.ft.). And PC2 could be something similar.</p><p>The limitation with principal components is, that the new<em> </em>features you make are *only* linear-combinations of some of the old ones. That means you can’t take advantage of making non-linear combinations of features. This is something neural networks are awesome at; they can create TONS of non-linear combinations/functions of features. But they have an even bigger problem: <em>interpretability</em> of the new features. The engineered features are basically hidden inside the weight-matrix multiplications between different layers of the network (which is just a composition of non-linear functions). And neural networks, with that extra non-linearity, can often be brittle and break under adversarial attacks, such as few-pixel attacks on convolutional neural networks, or <a href="https://codewords.recurse.com/issues/five/why-do-neural-networks-think-a-panda-is-a-vulture">tricking a neural network into mis-classifying a panda and a black square as a vulture</a> –– weird, nonsense stuff like that.</p><p>So, what to do about features?? Well, if the ways we engineer new features are kinda limited, we could always just select a subset of the features we already have! But you need to be careful. There are many ways to do this, but not all of the are robust and consistent. For example, take random forests. It’s true that at the end of using the classifier, Python will output the relevant features with the <em>feature_importances</em> method of a random forest. But let’s think for a second: random forests work by training a bunch of decision trees, each one on a random subset of the training data. So if you kept repeating the RF model, you might get different feature-importances each time, and this is not robust or consistent. Wouldn’t it be confusing as a data scientist or ML engineer to see a different set of relevant features pop up each time? You clearly didn’t change the data set! So why should you trust different sets of “importance” features? The problem with this is that the “importance” features you’re picking, are dependent on the random-forest model itself––and even if RF’s have high accuracy, it also makes more sense to choose features based on the dataset <em>alone, </em>rather than including a heavy-duty model first.</p><p>The key to selecting features that are consistent, not confusing, and robust might be this: select features <em>independently</em> of your model. The relevant features you select should be relevant <em>whether or not</em> you use a neural network, an RF, logistic regression, or any other supervised learning model. This way, you don’t have to worry about the predictive power of your machine learning model while you’re trying to pick features at the same time, which be un-reliable.</p><p>So, how do you pick features that are independent of your model? Scikit-Learn has a few options. One of them which is my favorite is called <em>mutual-information</em>. It’s a important concept from probability-theory. Basically, it computes the dependence between your features-variables and your label-variable <em>relative</em> to the assumption that they’re independent. An easier way of saying that is it measure <em>how much</em> your class-labels <em>depend</em> on a specific feature.</p><p>So for example, say you’re predicting if someone has a tumor by looking at a bunch of feature columns in your dataset, like geometric-area, location, color-hue, etc. If you’re trying to choose relevant features to your prediction, you can use mutual-information to talk about how <em>much</em> each class-label depends on the geometric-area, location, and color-hue of the tumor. And this is a measurement gotten <em>directly</em> from the data; it never involved using a predictive model in the first place.</p><p>You can also use Sci-kit Learn’s <em>chi-2</em>, or “chi-squared”, to determine feature importance. What this does, is use a Chi-Squared test between the features and the label to determine which features are relevant to the label and which ones are independent of the label. You can think of this method as testing a “null hypothesis” H0: are the features independent of the classification label?To do this, you’d calculate a chi-squared statistic based on the data-table, get a p-value, and determine which features are independent or not. You then throw away the independent features (why? because they’re independent <em>of the label</em> according to your test, so they give no information) and keep the dependent ones.</p><p>This test is actually based on similar principles to the mutual-information calculation talked about above. However, <em>chi2</em> does make the important assumptions that features in your dataset taking continuous values (say, 5.3, pi, sqrt(2), stuff like that) are normally distributed. Usually for big training-data sets this isn’t a problem, but for <em>small training-data</em> this assumption might be <em>violated</em>, so calculating mutual-information might be more reliable in those cases.</p><p>The basic point is this: mutual-information and chi-squared ways of feature-selecting are <em>robust</em> against the predictive model. Your predictive model might be wildly inaccurate, but the data you’ve collected is static in a table which never changes, so calculating your features without the model is more consistent.</p><p>Other ways of feature selecting include Recursive Feature Elimination (RFE), which uses a pre-fixed model (say, logistic/linear regression, or random forest) and tests almost all the subsets of features <em>using</em> the pre-fixed model, and decides which features are the best by seeing which subset of features gives the lowest accuracy error. (Technically, random forests use an additional method in Scikit Learn called <em>feature_importance</em>, but I won’t be getting into that here.) However, RFE does take a lot of time, because there are about 2-to-the-K subsets of features if you have K features, so it takes a long time to compute the model for each subset and get a score.</p><p>Another big reason I have against RFE and similar techniques is that it is fundamentally a feature-selection technique which is <em>model-dependent</em>. If your model is inaccurate, or overfits heavily, or does both and isn’t that interpretable by the user –– then the features you selected weren’t actually chosen by you, but by the model. So. the feature importance might not be an accurate representation of which features actually are predictive based <em>just</em> on the dataset.</p><p>So what can we take away from all this? Well, in the end, feature-selecting is extremely important if you don’t know how to interpret your engineered features using, say principal-component-analysis. However, when you do feature selection it’s just as important to take note about <em>how </em>you’re selecting your features, as well as computational time. Is your method taking too much time on the computer? Is your feature-selection based on using a particular model first? Ideally, you would want to feature-select <em>regardless</em> of what model you use, so in your Jupyter Notebook, you would ideally want to make a cell for feature-selection <em>before</em> the model –– something like this:</p><pre>from sklearn.feature_selection import SelectKBest<br>from sklearn.feature_selection import mutual_info_classif<br># &quot;mutual_info_classif&quot; is the mutual-information way of selecting<br># the K most dependent features based on the class-label</pre><pre>K = 3<br>selector = SelectKBest(mutual_info_classif, K)<br>X = new_df.iloc[:, :-1]<br>y = new_df.iloc[:, -1]<br>X_reduced = selector.fit_transform(X,y) <br>                                   <br>features_selected = selector.get_support()</pre><p>First, I did the feature selection (above).</p><pre>from sklearn.model_selection import train_test_split</pre><pre>X_train, X_test, y_train, y_test = train_test_split(X_reduced, y, <br>train_size=0.7)<br># use logistic regression as a model<br>logreg = LogisticRegression(C=0.1, max_iter=1000, solver=&#39;lbfgs&#39;)<br>logreg.fit(X_train, y_train)</pre><p>And then I trained the model (above)! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaf37e58fdaf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/help-how-do-i-feature-select-eaf37e58fdaf">Help! How do I Feature Select?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t Forget what ‘Deep’ & ‘Learning’ Actually Mean]]></title>
            <link>https://medium.com/data-science/dont-forget-what-deep-learning-actually-mean-2ab801bdbe31?source=rss-118e9d759119------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ab801bdbe31</guid>
            <category><![CDATA[bias-in-ai]]></category>
            <category><![CDATA[critical-thinking]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai-startups]]></category>
            <dc:creator><![CDATA[Raveena]]></dc:creator>
            <pubDate>Sat, 01 Aug 2020 18:15:02 GMT</pubDate>
            <atom:updated>2020-08-02T23:33:25.081Z</atom:updated>
            <content:encoded><![CDATA[<h3>Don’t Forget what the ‘Deep’ in Deep-Learning’ Means</h3><p><em>Think critically about whether you actually need deep-learning in your pipeline.</em></p><h4><em>Before you apply deep-learning to your customer data as an AI startup, think critically on the basic statistics of your customer data first–note down biases in the set–and ask yourself if deep-learning is really necessary to use on that set, or if you can use other statistics/ML methods.</em></h4><p>Deep Learning, one of the “hottest” things in AI, has a way of seeping into popular culture as this mysterious, software that can make seemingly amazing classifications at human-level accuracy in Computer Vision, speech recognition, or play games like Go, recommend our favorite movies, and the like.</p><p>But deep learning has crucial pitfalls, when it drives cars that sadly, more than once, have injured or killed their drivers or pedestrians because of silly image-recognition mistakes. Or, when deep learning is used for face-recognition ––something that clearly has adverse effects on people of color, LGBT, and other marginalized groups –– and if deep learning’s face-prediction is used by institutions of power with a history of racism, LGBT-phobia, and <a href="https://www.theverge.com/2018/10/23/18013376/amazon-ice-facial-recognition-aws-rekognition">tossed back and forth between private companies and governments</a> –– deep-learning’s pitfalls become frighteningly magnified. <a href="https://www.theguardian.com/technology/2017/oct/24/facebook-palestine-israel-translates-good-morning-attack-them-arrest">Another example is when Facebook’s deep-learning neural translation machine led to the illegal arrest of a Palestinian man because of a post he made, at the end of 2017.</a> If you think that these are “just unavoidable errors” made by an “intelligent system”, you’re clearly missing the point. Deep learning is really <a href="https://people.orie.cornell.edu/davidr/or474/nn_sas.pdf">just a statistical correlation tool</a>, and this connects to the title of this piece.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/0*ssLIQ0IlPBoF_CsL.png" /><figcaption>See how there’s only 1 hidden layer colored blue in the middle? There has to be 2 or more for “deep” learning.</figcaption></figure><p>In the picture above of a artificial neural network, since there’s only 1 hidden layer, this neural network is considered <em>shallow</em>. If you insert at least <em>two</em> hidden layers or more, it’s considered a “deep” neural network. That’s all there is to it about the “deep” part of deep-learning.</p><h4>The “deep” in deep-learning does not stand for deep, abstract understanding. It does not understand abstract concepts as humans do.</h4><p>The “deep” simply means that the <em>networks</em> are deep in terms of length. <a href="https://www.theatlantic.com/technology/archive/2018/01/the-shallowness-of-google-translate/551570/">Here’s an article from <em>The Atlantic: Technology</em></a><em> </em>showing that while Google Translate uses deep-learning it its neural-translation, the AI system, again makes <em>silly</em> translation mistakes compared with human standards.</p><p>Now, how about the <em>“</em>learning” part of deep-learning? Surely it has to imitate human learning capabilities because the structure is designed like neurons in the brain!</p><p>NOPE. Think about it: if deep learning imitated human learning so well that it could pass the Turing test (a human would be fooled by a deep-learning system), there wouldn’t be an <a href="https://www.nature.com/articles/d41586-019-03013-5"><strong>article in <em>Nature</em></strong> detailing how deep-learning systems have made silly mistakes</a> by human standards. And remember, if deep-learning is supposed to be like human learning, we should judge it by human standards. And one of the pioneers of deep-learning, <a href="https://www.axios.com/artificial-intelligence-pioneer-says-we-need-to-start-over-1513305524-f619efbd-9db0-4947-a9b2-7a4c310a28fe.html">Geoffrey Hinton, states he’s ‘deeply suspicious’ of neural nets</a> as a way to explain human or Artificial General intelligence.</p><p>Here’s what deep-learning does: it approximates a function, a mapping. For example: if you had a database of patient health records, and you had to predict if the patient should receive treatment A or treatment B based on some training-set, you could train a deep-learning net on the set. What it would do, is approximate a <em>direct</em> mapping from patient record x to the treatment. Bear with me, I’m gonna borrow some math notation for a sec.</p><p>Say that <em>X = patient records</em>, and <em>Y = {treatment A, treatment B}</em>. Usually, the way labels are coded in machine learning is 0&#39;s and 1’s so <em>Y = {1, 0}.</em></p><p>Now, what does a deep-learning network do? It just approximates a function <em>f</em> mapping <em>X</em> to <em>Y</em>. So it tries very hard, sometimes using thousands to millions of parameters — knobs and dials, to approximate a smooth function <em>f(X) = Y</em>.</p><p>How does it do this approximation though? Well, since <em>f </em>is often very complicated, it has to use an iterative algorithm. Neural networks use something called a “cost function” to find <em>f(x)</em>. By minimizing the errors between what it predicts and the actual value, neural networks can approximate the mapping through an algorithm called “back-propagation”. (For folks who know the <em>chain-rule</em> for derivatives from calculus, <a href="https://twitter.com/fchollet/status/951906139632840704">back-propagation in neural nets is literally just the chain-rule applied to a big composition</a> of smaller linear and nonlinear activation functions.) Don’t believe me? Check out this <a href="https://www.youtube.com/watch?v=aircAruvnKk&amp;list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi">amazing visual video by Grant Sanderson</a> (Youtube Channel 3b1b) explaining neural networks with the math included.</p><p>So that’s it! “Learning” in a neural network is simply an algorithm called back-propagation, used to minimize a cost function, which is used to approximate some complicated function between inputs and outputs. Is this what <em>human </em>learning and intelligence is? I hardly think so.</p><p>Why is this important? Well, a large number of startups that use AI in their software products love to use deep-learning as part of their toolkit to show how awesome the predictive power of their app-products (or other products are). And for sure, the idea of deep-learning <em>sells hard</em>. Of course it does! If a startup could claim to re-create human intelligence in a certain area (speech-recognition, computer vision) or at least claim to get on par with human-recognition in those areas, they would have unimaginable influence in the tech area. AI after all, is the golden treasure everyone in tech is seeking.</p><p>But beneath the icing of deep-learning, exists huge amounts of data collected in order to power that software. Function approximation is a very hard problem, and it often works only when you have a ton of data points. That’s one fundamental reason why companies like Google, Facebook, and Amazon can use deep learning: they’re basically <em>oceans</em> of data collecting data points like raindrops collecting into a basin. And since they are tech titans, they have power to use complex deep-learning models which could be wildly inaccurate in the real world –– and power to sell them as government contracts, or contracts with other companies that control the products we buy, the surveillance we live under, and the constant oppression through technology that marginalized people live through.</p><p>I’m not saying that if you’re thinking of starting an AI business that you can’t use deep-learning. Of course you can; there are hundreds of pre-trained deep neural network models downloadable from the Web. <a href="https://arxiv.org/pdf/1801.00631.pdf">But you should use them <em>critically</em></a>. Think about the <em>overall statistics</em> of the data you’ve collected <em>before</em> you apply deep-learning to them. Don’t simply apply deep-learning, thinking that it’s going to unveil complex relationships between the variables you’re collecting data on. Deep-learning is a black-box, but you <em>don’t have to use it like that</em>. Understand the biases in your dataset; understand and note down social inequities that exist in your dataset; chances are, they exist already. Why? Because your dataset is like a (biased) random sample from the population of the world, and so it will reflect systems of discrimination and bias in our current society.</p><p>Think of deep learning as a screwdriver in a toolkit. Maybe it might work for some tasks, but for many, <em>many</em> tasks, it simply won’t work by itself, and trying to brute force it into problems it can’t solve fast enough as an efficient <em>interpretable</em> tool, might as well be a waste of time,<em> </em>money and could potentially risk <em>actual human lives</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ab801bdbe31" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/dont-forget-what-deep-learning-actually-mean-2ab801bdbe31">Don’t Forget what ‘Deep’ &amp; ‘Learning’ Actually Mean</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explainable-AI: Use-Case #1]]></title>
            <link>https://medium.com/data-science/explainable-ai-use-case-1-bc2abd7b197a?source=rss-118e9d759119------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc2abd7b197a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[bayesian-statistics]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[generative-model]]></category>
            <dc:creator><![CDATA[Raveena]]></dc:creator>
            <pubDate>Fri, 31 Jul 2020 04:49:14 GMT</pubDate>
            <atom:updated>2020-08-01T18:41:10.240Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/0*coEQTHMrgAqN2Vva.jpg" /><figcaption>Image credit: Research @ Infosys Labs (Infosys Blogs)</figcaption></figure><h3>Interpretable-AI: Use-Case with Health Data</h3><p><em>Disclaimer: to best understand the context for this article, it would be helpful to read my </em><a href="https://medium.com/swlh/explainable-ai-where-supervised-learning-can-falter-edf2b562845a"><em>previous article</em></a><em> on Interpretable-AI. It would also be helpful if you’ve coded Logistic Regression in Python before, since I mention it in my code.</em></p><p>In my previous article on Interpretable AI, I mentioned that advanced supervised learning algorithms such as Logistic Regression and Neural Networks (and its variants, such as Convolutional Neural Networks and Recurrent Neural Nets, for instance) are hard to interpret. Neural networks especially, part of <em>deep learning</em>, can produce amazing accuracies, but exactly <em>how</em> the algorithm produces its classification is poorly understood to the programmer and the users. Part of the reason why is that neural nets and logistic regression work hard to create a direct relationship to their predictions, but that comes at a expense: <em>interpretability</em>.</p><p>I mentioned previously that another way to understand the problem of classification is with Bayes’ Theorem for inference between two hypotheses we have — H1 (class label 1) and H2 (class label 0). For reference here’s the equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*Em9og6sBA6hJ5qPq-_5Uzw.jpeg" /><figcaption>Bayesian Inference for 2 hypotheses</figcaption></figure><p>In today’s use-case, I’ll be applying this inference framework to the <a href="http://archive.ics.uci.edu/ml/datasets/HCC+Survival">Hepatocellular Carcinoma Dataset</a> on UC Irvine’s Machine Learning Repository. The dataset consists of 165 patients treated at the University of Madrid, and almost 50 individual features/measurements on each patient. The category labels indicate if the patient survived the carcinoma (1) or if they sadly couldn’t (0).</p><p>Let’s get started! First, we need to import the relevant packages. We’ll be importing more libraries as the code goes along. Since the dataset and code is long, this is <a href="https://github.com/galaxyenby/bayesian-inference/blob/master/Carcinoma%20Prediction%20with%20Generative%20Modeling.ipynb">my GitHub repo with the full code</a>. I’ll be posting snippets here.</p><pre># First, we read in the file and import packages<br>import numpy as np<br>import pandas as pd<br>from sklearn.linear_model import LogisticRegression<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>from sklearn.metrics import confusion_matrix as cmatrix </pre><pre>hcc_data = pd.read_csv(&#39;/Users/rabeya/Carcinoma_Classification_data/hcc.csv&#39;)</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07aaad5666a7dd5a51c289eec2d12ad1/href">https://medium.com/media/07aaad5666a7dd5a51c289eec2d12ad1/href</a></iframe><p>Next, after we load in the data, we use an algorithm from Miriam Santos’ original paper on the HCC dataset utilizing “HEOM-distance” to fill in all the missing values labeled with a “?”. This “HEOM-distance” algorithm takes each patient record and fills in the missing value based on the patient-records “closest” to it; the notion of “close”, as you guessed, is based on the HEOM-distance. Since this algorithm has many lines I direct you to my Github repo for that. The filled-in dataset was named <em>new_df</em>.</p><p>Once I finished filling in the missing values, I needed to balance the labels. Label imbalance is a huge problem in machine-learning, due to bias in collection or missing values, the ratio of records with label 1 vs. label 2 might not be 50%:50%. In fact, in the HCC dataset, the ratio of patient-life to patient-death records is 62%:38%, so we need to balance the records. One way of doing this is called “artificial oversampling”, where we create artificially new data records for the smaller-class that are <em>close</em> to the original records. This over-sampling method is called “SMOTE” and the code is below.</p><pre><strong>from</strong> <strong>imblearn.over_sampling</strong> <strong>import</strong> SMOTE<br>sme = SMOTE(random_state=10)<br><br><em>#features</em><br>features = new_df.columns<br><em># transform the dataset</em><br>X_matrix = new_df[features[:-1]].values<br>y_matrix = new_df[features[-1]].values<br>X_trans, y_trans = sme.fit_resample(X_matrix, y_matrix)</pre><pre>transformed_df = pd.DataFrame(X_trans, columns=features[:-1])<br>transformed_df[&#39;Class&#39;] = y_trans</pre><p>Now that we’ve transformed the dataset and balanced the classes (there are 102 patient-life and patient-death samples), we’re ready to build our generative classifier! (Our balanced HCC data-set is called <em>transformed_df</em> in the next sections.)</p><p>Before creating any models, we cut down the # of features in our dataset. The original one has 49 individual features/for each patient and that’s too much to think about! So instead, we’re cutting it down to the “best” 10 features using something in statistics called <a href="https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.mutual_info_classif.html#r50b872b699c4-1"><em>mutual-information</em></a>.</p><p>First I fit a logistic-regression as a test model case to the training and test data. I split the training and test set into: 65% to training set, and 35% to test-set. This isn’t standard, but I did this since our entire set has only 200 records, so data must be used sparingly.</p><pre><strong>from</strong> <strong>sklearn.feature_selection</strong> <strong>import</strong> SelectKBest<br><strong>from</strong> <strong>sklearn.feature_selection</strong> <strong>import</strong> mutual_info_classif</pre><pre>K = 10<br>selector = SelectKBest(mutual_info_classif, k=K)<br>X = transformed_df.iloc[:, :-1]<br>y = transformed_df.iloc[:, -1]<br>X_reduced = selector.fit_transform(X,y)</pre><pre><em># use logistic regression as a test case model</em><br>logreg = LogisticRegression(C=1.5, max_iter=1000, solver=&#39;lbfgs&#39;)<br>logreg.fit(X_train, y_train)</pre><p>Using logistic regression on unseen data, the prediction accuracies were: true-positives— 36%; true-negatives— 30%; false-positives — 22%; false-negatives — 12%. Logistic regression doesn’t do great at prediction with this small of a dataset, and the FPR at 22% is dangerous to use for future predictions since 1 out of 5 future new HCC-patients would be <em>predicted</em> to survive, while their <em>actual</em> chance of surviving would be low. This poor predictive power isn’t surprising, because we only gave ~130 records for the model to train on.</p><p>There are many solutions to take from here: 1) to collect more data and dump it in, but HCC data doesn’t come by easily. 2) to use more parameters/weights, such as a neural network model for small-data. But as we discussed earlier, neural networks are hardly interpretable. The solution I took was to change the perspective of the prediction entirely, and to use generative models instead. As I mentioned, a generative model can help us calculate how <em>probable</em> data points under the assumption that they belong to different categories, and this <em>probabilistic perspective</em> is especially useful for small data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F0bFBS-ZFmusicoE.png" /><figcaption>Density Estimation model. Image Credit: <a href="https://machinelearningmastery.com/probability-density-estimation/">machinelearningmastery.com</a></figcaption></figure><p>Finally, we can create our generative models. The first type is called <a href="https://www.youtube.com/watch?v=W0XECm4-3LI"><em>Gaussian Mixture Model</em></a><em> </em>(GMM), where a bunch of separate Gaussian models (called “components”) are tied together to create one big generative model. We separate our training data based on whether the patient survived or died from the carcinoma –– and then fit the models. In order to fit the models, we can’t just choose one # of components. Instead, I trained 64 models (the computer can perform this faster than you think) and the models are optimized using the <em>Expectation-Maximization</em> (EM) algorithm. The EM algorithm is a few decades old but is used frequently to find Gaussian mixtures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*Sj3oa4MiTls_SF41.gif" /><figcaption>Gaussian Mixture (EM) at work. Image Credit: <a href="https://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm">Wikipedia</a></figcaption></figure><p>I then picked the optimal numbers 22 and 21 based on a statistical measurement called the <a href="https://en.wikipedia.org/wiki/Akaike_information_criterion"><em>Akaike Information Criteria </em>(AIC)</a>. It basically compares how accurate the density model is vs. how complex it is, and tries to walk the balance between overfitting and underfitting the model.</p><pre><strong>from</strong> <strong>sklearn.mixture</strong> <strong>import</strong> GaussianMixture <strong>as</strong> GMM<br>M = 64<br><em># so M models to train</em><br>n_components = np.arange(2, M, 1)<br><em> </em><br>life_models = [GMM(n, covariance_type=&#39;full&#39;, random_state=5) <strong>for</strong> n <strong>in</strong> n_components]</pre><pre>death_models = [GMM(n, covariance_type=&#39;full&#39;, random_state=7) <strong>for</strong> n <strong>in</strong> n_components]</pre><pre>life_aics = [model.fit(X_train_life).aic(X_train_life) <strong>for</strong> model <strong>in</strong> life_models]</pre><pre>death_aics = [model.fit(X_train_death).aic(X_train_death) <strong>for</strong> model <strong>in</strong> death_models]</pre><pre>gmm_life = GMM(22, covariance_type=&#39;tied&#39;,tol=1e-4, random_state=5)<br>gmm_life.fit(X_train_life)</pre><pre>gmm_death = GMM(21, covariance_type=&#39;tied&#39;,tol=1e-4, random_state=7)<br>gmm_death.fit(X_train_death)</pre><p>And the accuracies on using the Gaussian Mixture models on unseen data were: 35% true-negative, 12% false-positive, 15% false-negative, and 37% true-positive. What an improvement in the false-positive rate over logistic regression! We can actually do even better on the false-positive rate by using a variant of the Gaussian Mixture model on steroids: <a href="https://www.youtube.com/watch?v=W0XECm4-3LI"><em>Kernel Density Estimation </em>(KDE)</a>. It definitely sounds like something out of AI sci-fi, but it works on the same principles!</p><pre><strong>from</strong> <strong>sklearn.neighbors</strong> <strong>import</strong> KernelDensity</pre><pre>kde_life = KernelDensity(bandwidth=0.1).fit(X_train_life)<br>kde_death = KernelDensity(bandwidth=0.1).fit(X_train_death)<br><br>log_density_life = kde_life.score_samples(X_test)<br>log_density_death = kde_death.score_samples(X_test)</pre><p>And when we use the KDE method on unseen data, our prediction accuracies are: 44% true-negative, 8% false-positive, 2% false-negative, and 46% true-positive. Having been trained on <em>only 130 records</em>, KDE did an amazing job on its predictive power. (Something to keep in mind for GMM and KDE by the way, is overfitting the density model to the training data. I’ll explore this in a future article.)</p><p>OK, so this is all well and good, but how do we <em>interpret</em> the density model? Explainability is important. Well, if a new data-point patient Y from the test set came in, the machine could explain its prediction like this: “Since the class-labels (1=Survival, 0=Death) are balanced, my prior-ratio is equal to 1. Therefore, I base my decision only on the density likelihood models I calculated from training on the previous ~130 training records. From my survival-likelihood model, the log-likelihood of Y if I assume it belongs to class 1 is p1. And from my death-likelihood model, the log-likelihood of Y if I assume it belongs to class 0 is p2. Since I calculated that, say, (p1-p2) &gt;0, this means that the probability patient-Y’s data record could’ve been generated — assuming it belongs to Class 1–– is greater than that of Class 0. Therefore, I classify patient Y survives carcinoma based on their 10 ‘best’ calculated features.” And this is what that code actually looks like:</p><pre>delta = np.subtract(log_density_life, log_density_death)<br># this is the difference in likelihoods under the hypothesis  assumptions (H1: label=1, H2: label=0)</pre><pre>kde_predictions = np.asarray([1 <strong>if</strong> x &gt; 0 <strong>else</strong> 0 <strong>for</strong> x <strong>in</strong> delta])</pre><p>Of course, the machine can’t talk to us, but I believe that is how we can understand the machine-learning model’s decisions. See how much more interpretable that was than say, using neural networks or logistic regression?</p><p>But not just that. Say that we had a larger dataset like this that wasn’t balanced. We could factor in the proportions of survival and death labels in the <em>prior-ratio </em>of Bayes’ Inference formula. And if we calculated the sam likelihood density models, and found that the prediction for a new test point was wrong, we could <em>potentially</em> <em>revise the model</em>. Either we could revise our prior probabilities of the class labels, or we could revise the likelihood models. How? By using a Bayesian framework on the <em>likelihood models themselves.</em> This could be done dynamically in a probabilistic-programming language such as PYMC3, for instance.</p><p>I hope that these results used on healthcare data provide an avenue toward using density estimation not just for clustering customer patterns, but deploying them for predictive power as we did in this project. I will point out that one feature the experimenters didn’t factor in was race/ethnicity. I can understand that since the dataset was collected in Spain, race would be pretty homogeneous. But ignoring race in data-collection, and not critically thinking about what other factors could be connected to that such as socio-economic class and access to healthcare, is a <em>very risky </em>and dangerous thing to do. But hopefully I’ll be able to find more HCC-datasets (or similar ones) that <em>do</em> take those factors into account as well.</p><p>See you all soon! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc2abd7b197a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/explainable-ai-use-case-1-bc2abd7b197a">Explainable-AI: Use-Case #1</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explainable-AI: Where Supervised Learning Can Falter]]></title>
            <link>https://medium.com/swlh/explainable-ai-where-supervised-learning-can-falter-edf2b562845a?source=rss-118e9d759119------2</link>
            <guid isPermaLink="false">https://medium.com/p/edf2b562845a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[bayesian-inference]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Raveena]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 09:49:11 GMT</pubDate>
            <atom:updated>2020-08-01T09:19:49.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/0*CDivXykxxsP7XQSz.jpg" /><figcaption>Image credit: InfoSys Blogs (Research @ Infosys Labs)</figcaption></figure><h3>Interpretable-AI: Where Supervised Learning Might Fail</h3><p><em>Disclaimer: I’ll be briefly mentioning logistic-regression and basic feed-forward neural networks, so its helpful to have programmed with those 2 models before reading this piece.</em></p><p>OK — before machine learning folks come running after me after reading the title, I’m not talking about linear regression, for example. Yes, in linear regression, you can use the R-squared (or adjusted R-squared statistic) to talk about explained variance, and since linear regression only involves addition between independent variables (or predictors), they’re pretty interpretable. If you were doing a linear regression to predict, say the price of a car <em>Car_Price</em>, based on the number of seats, mileage, maximum-speed, and battery life, your linear model could be –– say <em>Car_Price</em> = c1*<em>Seats </em>+ c2*<em>Mileage</em> + c3*<em>Speed </em>+ c4*<em>Battery_Power –– </em>the fact that variables are only added makes it pretty interpretable. But when it comes to more complex prediction models like Logistic Regression and neural networks, everything about the predictors (or called “features” in ML) becomes more confusing. And logistic-regression &amp; neural networks fall under <em>supervised learning</em>, because they basically just estimate a complicated black-box function from data -&gt; labels.</p><p>People use logistic regression to predict whether something is true or not; for example, if patient X has a disease or not. It’s an example of a <em>nonlinear</em> classifier, because instead of just adding the features together, the features are mapped through the <em>nonlinear sigmoid</em> function, which squishes all inputs into the range between 0 and 1, since logistic regression is supposed to represent a probability. (Technically, if you search logistic-regression on Wikipedia, the “decision boundary” is linear, but that’s not the point.) TO me at least, logistic-regression already seems a bit less interpretable than linear-regression because of the nonlinear part. And neural networks are logistic regression chained together! (It’s a rough analogy, but it helps explain a point.) Neural nets, are by definition, made to be nonlinear so it would find non-linear connections between features and be a better predictor for say, image recognition –– why? Because the pixels are considered features, and the pixels making up a recognizable image are related in a non-linear way since images are complex.</p><p>But <a href="https://arxiv.org/pdf/1801.00631.pdf">neural networks are often described as an unexplainable black box</a>, and you do NOT want a neural network making important decisions about employment, loans, health-data, and so on if you can’t explain the reasons for the model’s decision. And <a href="https://www.aitrends.com/ai-insider/accidents-contagion-and-ai-self-driving-cars/">given at least a. few self-driving fatal car accidents</a> whose software runs on deep learning, a neural network’s decisions that led to a injury or death can’t even be explained in a principled way!</p><p>Neural networks are based on the idea of approximating functions, or mappings, between data and its label (example: image of a cat, cat-label). But in the <a href="https://web.njit.edu/~usman/courses/cs675_fall18/10.1.1.441.7873.pdf">1989 <em>original</em> paper </a>proving that neural networks can do this, the author, Cybenko, stated at the end: “<em>At this point, we can only say that the majority of [mapping/function] approximation problems will require astronomical numbers of terms [neural nodes]</em>.” So while neural networks can create any function mapping between, say images (or predicting the next-word, with recurrent nets), they often have to have <em>hundreds-of-thousand</em>s to <em>millions</em> of parameters (also called “weights”, same as “terms” that Cybenko says), with no principled way of interpreting and explaining the nonlinear connections. And human brains don’t need to see thousands of examples to generalize as neural nets do. For example, AlexNet, a famous neural network trained to classify cats, houses, cars, and real-life objects, has <em>60 million</em> parameters, and had to be trained on 15 <em>million</em> images with almost 700 images for each label. And it sucked up an immense computational energy with <em>multiple</em> GPUs –– technologies that mostly large companies and research groups with tons of money have access to.</p><p>Personally, I believe that AI could use a dose of two things to make itself interpretable: <em>inference</em>, and <em>unsupervised learning</em>. Why? Well, I believe it comes down to the following equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*Em9og6sBA6hJ5qPq-_5Uzw.jpeg" /></figure><p>This is Bayes’ Theorem, but with 2 hypothesis. Basically it says that the belief we give to hypothesis 1 over hypothesis 2 after seeing data, is just the product of how likely the data is assuming our hypotheses, times what we thought about the hypotheses <em>before</em> seeing the data. There’s evidence <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5543692/">our brain computes probabilistic inference subconsciously in a similar way</a>. But where does <em>unsupervised learning</em> play in, you say? Well, precisely in the “<em>likelihood” </em>piece of the equation. If you’ve heard of unsupervised learning related to “clustering”, or “finding patters in data without labels” –– that’s all true. But unsupervised learning is fundamentally about <em>density-estimation</em>, a fancy of way of saying “data description”. Density estimation gives us more power than just clustering. It can <em>generate</em> new data all on its own! And crucially, if we can use it to generate new data, then assuming either hypothesis, we can compare the distribution of generated data, to what we see in our test data. And if the test data is <em>more</em> likely to be generated with our <em>estimated density</em> by assuming Hypothesis 1 over 2, we can <em>decide</em> to choose one over the other. That kind of decision, I believe at least, is explainable and understandable because human brains are <em>already wired to understand likelihood and reason with uncertainty.</em> Generating new data in our mind is an important part of human intelligence –– so it should definitely be a key part of Interpretable-AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BKIhN-1Wl-HKUEha.png" /><figcaption>Density estimation to model a histogram (“data description”). Image Credit: <a href="https://machinelearningmastery.com/probability-density-estimation/">machinelearningmastery.com</a></figcaption></figure><p>In my next article, I’ll be going over a use case of this. I’ll be analyzing the <a href="http://archive.ics.uci.edu/ml/datasets/HCC+Survival">“Hepatocellular Carcinoma” dataset</a> from the free online UCI Learning Repository , and show the code and results for classifying whether a patient with certain medical features survives or dies from the carcinoma. We’ll get to see differences in interpretability using 1) logistic-regression model to predict survival, and 2) a unsupervised, generative model, like above, to predict survival. See you then!</p><p><strong>EDIT:</strong> My follow-up article, “<a href="https://towardsdatascience.com/explainable-ai-use-case-1-bc2abd7b197a">Interpretable-AI: Use-Case with Health Data</a>” is out on my Medium profile now! Any readers here who finished this piece, feel free to check it out!</p><p>Feel free to contact me at <a href="https://www.linkedin.com/in/raveena-k-3a71661a0/"><strong>my LinkedIn</strong></a>!</p><p>References:</p><ol><li>G, Sybenko, (1989). <em>Approximation by Superpositions of a Sigmoidal Function</em></li><li>G. Marcus, (2017). <em>Deep Learning: A Critical Appraisal</em></li><li>Pitkow, X., &amp; Angelaki, D. E. (2017). Inference in the Brain: Statistics Flowing in Redundant Population Codes. <em>Neuron</em>, <em>94</em>(5), 943–953.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edf2b562845a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/explainable-ai-where-supervised-learning-can-falter-edf2b562845a">Explainable-AI: Where Supervised Learning Can Falter</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>