<?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 Anya Tonne on Medium]]></title>
        <description><![CDATA[Stories by Anya Tonne on Medium]]></description>
        <link>https://medium.com/@anya.tonne?source=rss-aea4df9990da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qcyL7eC0LlvBUfJX_x24Yw.jpeg</url>
            <title>Stories by Anya Tonne on Medium</title>
            <link>https://medium.com/@anya.tonne?source=rss-aea4df9990da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:44:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anya.tonne/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[THE CASE OF HIGH CARDINALITY KERFUFFLES]]></title>
            <link>https://medium.com/cmotions/the-case-of-high-cardinality-kerfuffles-d9b7fccc6570?source=rss-aea4df9990da------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9b7fccc6570</guid>
            <category><![CDATA[predictive-analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[categorical-data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[categorical-variable]]></category>
            <dc:creator><![CDATA[Anya Tonne]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 15:29:22 GMT</pubDate>
            <atom:updated>2022-03-04T15:39:49.133Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>NO DATA SCIENTIST IS THE SAME!</em></strong> <strong>— part 6</strong></p><h3>The case of high cardinality kerfuffles</h3><p><em>This article is part of our series about how different types of data scientists build similar models differently. No human is the same and therefore also no data scientist is the same. And the circumstances under which a data challenge needs to be handled change constantly. For these reasons, different approaches can and will be used to complete the task at hand. In our series we will explore the four different approaches of our data scientists — Meta Oric, Aki Razzi, Andy Stand, and Eqaan Librium. They are presented with the task to build a model to predict whether employees of a company — STARDATAPEPS — will look for a new job or not. Based on their distinct profiles discussed in the </em><a href="https://www.theanalyticslab.nl/no-data-scientist-is-the-same-introducing-our-data-science-rock-stars"><em>first blog</em></a><em> you can already imagine that their approaches will be quite different.</em></p><p><em>In this article we will look into how to deal with one of the data preparation steps — categorical variables. We will compare default one-hot-encoding with several alternatives: Label Encoding, Frequency Encoding, Weight of Evidence, Smooth Weight of Evidence, Optimal Binning, Hand-picked Binning and Deletion. Finally, Andy and Eqaan will decide which of the techniques they would prefer in their analysis.</em></p><p>In the previous article, we saw how Meta and Aki built predictive models. Meta focused on minimising the time she spent on this project. She chose a model that is both powerful and requires little to no attention to data preparation. Aki took her model one step further and also tuned hyperparameters to achieve an uplift in the accuracy of the predictions. In this article we will see how Eqaan and Andy will tackle this problem. For explainability and business reasons they prefer to use a logistics model to predict employee churn. This requires a more extensive data preparation than what we saw in the previous articles. But how they will go about it will obviously differ.</p><h3>Andy Stand : ‘Understand is what we do’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*IV2pIwIQKP7knozA.png" /></figure><p>Andy praises himself for being able to explain everything that he does to the business. He never uses black-box techniques and thus will only use methods that can be easily understood by those without a technical background. Thus, some of the more sophisticated techniques that we will look at today, he will not consider for his model.</p><h3>Eqaan Librium: ‘Equilibrium and work-life balance’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*Z6lLpjKYIVjNz4Ug.png" /></figure><p>Eqaan strives to achieve a balance between the predictive power of his model and the explainability of techniques, thus he will not shy away from using a more complicated method if it gives him a better model.</p><p>One of the most common preparation steps is dealing with categorical variables. Various techniques can be used to translate them to a numeric equivalent. These can then be used as features in a predictive model. You saw, that Meta also used encoding in order to prepare all categorical variables. However, she did it in a very rudimental way. She used the same technique on all her variables without taking a second look at what those variables are. Namely, she used one-hot encoding to convert all her categorical variables.</p><p>One-hot encoding is a very popular technique. It is also the one that most encounter the first time they try to build the mother of all predictive models — a simple linear/logistic regression. One-hot encoding is a technique for dealing with nominal variables (or where the ordering can be ignored) where an old variable gets replaced by as many variables as there are categories and each category is represented in a binary manner. However, it is not the only option available when dealing with categorical data, and in some cases not at all useful.</p><p>One particular case where one-hot encoding becomes suboptimal is in dealing with variables that have high cardinality. These are variables that have many different values. Then, creating an individual variable for every single value that exists can lead to a substantial increase in the size of the dataset, problems in estimating parameters or even infinite log values. Result would be a model that is difficult to generalize on a new set. Not to mention, that explaining such results can also prove to be a struggle. In our dataset, the variable <em>city</em> is a perfect example of a high cardinality. It has 123 unique values.</p><pre><em>#importing libraries:</em><br><strong>import</strong> os<br><strong>import</strong> pandas <strong>as</strong> pd<br><strong>import</strong> numpy <strong>as</strong> np<br><strong>from</strong> sklearn.model_selection <strong>import</strong> train_test_split<br><strong>from</strong> sklearn.linear_model <strong>import</strong> LogisticRegression<br><strong>from</strong> sklearn.pipeline <strong>import</strong> Pipeline <br><strong>from</strong> sklearn.impute <strong>import</strong> SimpleImputer<br><strong>from</strong> sklearn.preprocessing <strong>import</strong> StandardScaler, OneHotEncoder, LabelEncoder<br><strong>from</strong> sklearn.compose <strong>import</strong> ColumnTransformer<br><br><strong>import</strong> matplotlib.pyplot <strong>as</strong> plt<br><strong>import</strong> seaborn <strong>as</strong> sns<br><strong>%</strong>matplotlib inline<br><strong>from</strong> sklearn <strong>import</strong> metrics<br><strong>from</strong> sklearn.metrics <strong>import</strong> mean_squared_error<br><strong>from</strong> sklearn.model_selection <strong>import</strong> StratifiedKFold<br><strong>from</strong> sklearn.model_selection <strong>import</strong> cross_val_score<br><strong>from</strong> sklearn.metrics <strong>import</strong> roc_curve<br><br><em># use optimal binning</em><br><strong>from</strong> optbinning <strong>import</strong> OptimalBinning<br><br><strong>import</strong> warnings <br>warnings<strong>.</strong>filterwarnings(action<strong>=</strong> &#39;ignore&#39;)</pre><p>Although, when you look at the spread of values in mode detail, you can notice that some are more frequent than the others. This is of course very normal for a variable like city. While cities can house millions of people small towns will only have a few thousands inhabitants. Thus, larger cities will also be more frequent in our data. As you can see from the graph below, the variable <em>city name</em> has a lot of different categories. One-hot encoding results would be very inconvenient.</p><pre>df_prep <strong>=</strong> pd<strong>.</strong>read_csv(&#39;https://bhciaaablob.blob.core.windows.net/featurenegineeringfiles/df_prepared.csv&#39;)<br>df <strong>=</strong> df_prep<strong>.</strong>drop(columns<strong>=</strong>[&#39;Unnamed: 0&#39;,&#39;city&#39;, &#39;experience&#39;, &#39;enrollee_id&#39;])</pre><pre>plt<strong>.</strong>rcParams[&#39;figure.figsize&#39;] <strong>=</strong> [30, 8]<br>plt<strong>.</strong>bar(df[&#39;city name&#39;]<strong>.</strong>value_counts()<strong>.</strong>index, df[&#39;city name&#39;]<strong>.</strong>value_counts())<br>plt<strong>.</strong>ylabel(&#39;Number of records&#39;)<br>plt<strong>.</strong>xticks(rotation<strong>=</strong>90)<br>plt<strong>.</strong>show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwcU84NbY2NJzI4-CySAJA.png" /></figure><p>Before we can move to building out benchmark model, we will need to pre-process the data for a logit model. Below you can see what the data looks like. We have mix of categorical and numerical variables. These of course should be dealt separately.</p><pre>df<strong>.</strong>head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RHm3PcuT7wFIGYdKHc-oAg.png" /></figure><pre><em># Define the target vector y</em><br>y <strong>=</strong> df[&#39;target&#39;]  <br><br><em># Creating a dataset without the DV and the variable city name:</em><br>X <strong>=</strong> df<strong>.</strong>drop([&#39;target&#39;, &#39;city name&#39;], axis <strong>=</strong> 1)<br><br><br><em># Creating an object with the column labels of only the categorical features and one with only the numeric features:</em><br>categorical_features <strong>=</strong> X<strong>.</strong>select_dtypes(exclude<strong>=</strong>&quot;number&quot;)<strong>.</strong>columns<strong>.</strong>tolist()<br>numeric_features <strong>=</strong> X<strong>.</strong>select_dtypes(include<strong>=</strong>&quot;number&quot;)<strong>.</strong>columns<strong>.</strong>tolist()<br><br><em>#Categorical variables</em><br>X[categorical_features] <strong>=</strong> X[categorical_features]<strong>.</strong>fillna(X<strong>.</strong>mode())<br>one_hot_encode <strong>=</strong> OneHotEncoder(sparse<strong>=False</strong>)<br>one_hot_df <strong>=</strong> pd<strong>.</strong>DataFrame(one_hot_encode<strong>.</strong>fit_transform(X[categorical_features]))<br>one_hot_df<strong>.</strong>columns <strong>=</strong> one_hot_encode<strong>.</strong>get_feature_names(categorical_features)<br>    <br><em>#Numerical variables </em><br>X[numeric_features] <strong>=</strong> X[numeric_features]<strong>.</strong>fillna(X<strong>.</strong>mean())<br>scaler_encode <strong>=</strong> StandardScaler()<br>scaler_encode_df <strong>=</strong> pd<strong>.</strong>DataFrame(scaler_encode<strong>.</strong>fit_transform(X[numeric_features]))<br>scaler_encode_df<strong>.</strong>columns <strong>=</strong> X[numeric_features]<strong>.</strong>columns                                                        <br><br><em>#put X back together and add the city variable</em><br>X_prep <strong>=</strong> scaler_encode_df<strong>.</strong>join(one_hot_df)<br>X_prep[&#39;city name&#39;] <strong>=</strong> df[&#39;city name&#39;]</pre><p>With the code above we treated all categorical variables by imputing missing values with a mode value and then applying a one-hot encoding technique to all variables except the <em>city name</em>. Missingness in a variable can also be interpreted as extra information and thus considered as a category of its own. When it comes to the numeric variables, we firstly imputed all missing values using the mean and then standardized them. You can inspect the resulting data frame below.</p><pre>X_prep<strong>.</strong>head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QIJcUpJOEH2yiw3qSNiHtQ.png" /></figure><h3>One-hot encoding</h3><p>For the base model we decided to use one-hot encoding, since this would be the default option for many data scientists. As we mentioned above, the idea behind it, is that every value in an original variable becomes a variable in it&#39;s own right where a value of 1 would indicate belonging to a category. Here is how you can train and evaluate it.</p><pre><em>#one-hot encoding city: </em><br>enc_city <strong>=</strong> pd<strong>.</strong>get_dummies(df[&#39;city name&#39;])<br><br><em>#Merge the dummmies to the df:</em><br>df_dummy <strong>=</strong> X_prep<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<strong>.</strong>join(enc_city)<br><br><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(df_dummy,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(X_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(X_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(X_test)[::,1]<br><br><em># Evaluate the model with the use of cv:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, X_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output:</p><pre>roc_auc = 0.789883 (0.019211)</pre><p>This approach gave us a very decent roc auc score of 0.7899. Though, maybe we can do better with other methods?</p><p>There are many techniques out there to compete with the one-hot encoding. Thus, both Eqaan and Andy had enough to choose from. In this article we will explore the following:</p><ol><li>Label Encoding</li><li>Frequency Encoding</li><li>Weight of Evidence</li><li>Smooth Weight of Evidence</li><li>Optimal Binning</li><li>Hand-picked Binning</li><li>Deletion</li></ol><p>In the end we will compare these and both Andy and Eqaan will share their thoughts on which ones they will choose for this analysis.</p><h3>Label Encoding</h3><p>Label encoding is a technique where each value is assigned an integer and a resulting variable is used in the analysis. The downside of this approach, is that it gives an illusion of a ranking between the categories. In other words if New York is assigned 1 and Boston 2 than it appear that Boston is lager/bigger/more something than New York, when in reality this relationship does not exist. Thus, it is better suited to ordinal rather than nominal variables. Nevertheless, we will check if this method will provide us with a better model in the end.</p><pre>le <strong>=</strong> LabelEncoder()<br><br><em>#label encoding city: </em><br>enc_city <strong>=</strong> le<strong>.</strong>fit_transform(df[&#39;city name&#39;])<br><br><em>#Merge the dummmies to the df:</em><br>df_label <strong>=</strong> X_prep<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<br>df_label[&#39;city_enc&#39;] <strong>=</strong> enc_city<br><br><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(df_label,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(X_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(X_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(X_test)[::,1]<br><br><em># Evaluate the model with the use of cv on the test dataset:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, X_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output</p><pre>roc_auc = 0.787011 (0.015378)</pre><p>Label encoding performed a little worse than the dummy coding. Although the difference is actually very small, this technique should definitely not be used for encoding our variable, since city name is not an ordinal variable. By encoding it with this method we create an ordering that does not exist in the data.</p><h3>Frequency Encoding</h3><p>Another interesting approach is to use the information about how frequent the value appears in the dataset as information. Thus, we create a frequency count table related to the high cardinality variable and then calculate what percentage of records have a particular value. You can also read about this method <a href="https://towardsdatascience.com/all-about-categorical-variable-encoding-305f3361fd02#:~:text=name%20is%20BinaryEncoder.-,Frequency%20Encoding,the%20nature%20of%20the%20data">here</a>. This approach, obviously results in values between 0 and 1. In the cell below you can see the first 5 rows from such an encoding. Since the technique is very easy to understand Andy was particularly happy to try it in a regression.</p><pre>df_fe <strong>=</strong> X_prep<strong>.</strong>groupby(&#39;city name&#39;)<strong>.</strong>size()<strong>/</strong>len(X_prep)<br>d <strong>=</strong> pd<strong>.</strong>DataFrame()<br>d[&#39;Temp_freq_encode&#39;] <strong>=</strong> X_prep[&#39;city name&#39;]<strong>.</strong>map(df_fe)<br>d[&#39;city name&#39;] <strong>=</strong> X_prep[&#39;city name&#39;]<br>d<strong>.</strong>head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*7IxvUoYdN3rF-uatc0CcXg.png" /></figure><pre><em>#Merge the encoded variable to the df:</em><br>df_fe <strong>=</strong> X_prep<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<br>df_fe[&#39;city_enc&#39;] <strong>=</strong> d[&#39;Temp_freq_encode&#39;]<br><br><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(df_fe,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(X_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(X_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(X_test)[::,1]<br><br><em># Evaluate the model with the use of cv on the test dataset:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, X_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output:</p><pre>roc_auc = 0.793895 (0.016094)</pre><p>Well, isn’t this a nice result! Frequency encoding managed to beat our base model (0.794 vs. 0.7899). Although the difference is not drastic, incorporating information about how frequent the value appears in the data leads to an improved AUC score. This technique is also very easy to explain, thus making it a good contender for Andy’s final solution.</p><h3>Weight of Evidence</h3><p>Weight of Evidence (WOE) measures the “strength” of variable in relation to the target. The weight is evidence of how well the ‘events’ and ‘non-events’ can be separated from each other. For a categorical variable you can calculate the WOE for each categorical value. All WOE’s together form one new numerical variable calculated in the following manner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*4Ez0lqHBXaeUZC3Dz2d_-Q.png" /></figure><p>This value will be positive if the percentage of events is higher than the percentage of non-events and hence negative if the percentage of events is smaller than that of the non-events. In fact the weight of evidence shows how much a value supports or undermined the hypothesis.<br>After calculating the WOE value for each separate group, we map it back to the original data and then use as a variable in our model.</p><p>This approach creates a variable that is already transformed onto a ‘logistic’ scale thus improving the model. More on this approach can be found in <a href="https://www.listendata.com/2015/03/weight-of-evidence-woe-and-information.html">this great overview</a>.</p><pre><strong>def</strong> calcWoes(df, catvar, target):<br>    rho <strong>=</strong> df[target]<strong>.</strong>mean()<br>    c <strong>=</strong> 25<br>    logit <strong>=</strong> np<strong>.</strong>log(rho<strong>/</strong>(1.0<strong>-</strong>rho)) <em># mean logit</em><br>    catvalues <strong>=</strong> df[catvar]<strong>.</strong>unique()<br><br>    <em># initialise my dataframe</em><br>    Woe_frame <strong>=</strong> pd<strong>.</strong>DataFrame()<br><br>    <em># calculate Woes</em><br>    <strong>for</strong> catvalue <strong>in</strong> catvalues:<br>        n <strong>=</strong> df<strong>.</strong>loc[(df[catvar] <strong>==</strong> catvalue)][target]<strong>.</strong>count()<br>        n_nonevents <strong>=</strong> df<strong>.</strong>loc[(df[catvar] <strong>==</strong> catvalue) <strong>&amp;<br></strong>(df[target] <strong>==</strong> 0)][target]<strong>.</strong>count()<br>        n_events    <strong>=</strong> df<strong>.</strong>loc[(df[catvar] <strong>==</strong> catvalue) <strong>&amp;<br></strong>(df[target] <strong>==</strong> 1)][target]<strong>.</strong>count()<br>        Woe <strong>=</strong> np<strong>.</strong>log(np<strong>.</strong>maximum(n_events,0.5)<strong>/</strong>np<strong>.</strong>maximum(n_nonevents,0.5))<br>        Woe_frame <strong>=</strong> Woe_frame<strong>.</strong>append([[catvalue,Woe]])<br><br>    <em># rename columns</em><br>    Woe_frame <strong>=</strong> Woe_frame<strong>.</strong>rename(columns<strong>=</strong>{0:catvar,1:&#39;Woe&#39;})<br>    <strong>return</strong> (Woe_frame, logit)<br><br><strong>def</strong> Woe_enrich(df, Woe_frame, logit, catvar):   <br>    result <strong>=</strong> pd<strong>.</strong>merge(df, Woe_frame, on<strong>=</strong>[catvar], how <strong>=</strong>&#39;left&#39;)<br>    result<strong>.</strong>loc[(result[&#39;Woe&#39;]<strong>.</strong>isnull()),&#39;Woe&#39;] <strong>=</strong> logit<br>    <strong>return</strong> result</pre><pre><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(X_prep,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br>df_woe_train <strong>=</strong> X_train<strong>.</strong>join(y_train)<br><em># calculate Woe&#39;s</em><br>Woe, logit <strong>=</strong> calcWoes(df_woe_train,&#39;city name&#39;, &#39;target&#39;)<br><br><br><em># Add encoded variable</em><br>df_ver_Woe_train <strong>=</strong> Woe_enrich(X_train, Woe, logit, &#39;city name&#39;)<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<br>df_ver_Woe_test <strong>=</strong> Woe_enrich(X_test, Woe, logit, &#39;city name&#39;)<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<br><br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(df_ver_Woe_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(df_ver_Woe_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(df_ver_Woe_test)[::,1]<br><br><br><em># Evaluate the model with the use of cv on the test dataset:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, df_ver_Woe_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output:</p><pre>roc_auc = 0.792368 (0.013413)</pre><p>Not quite as good as the frequency encoding, but a very decent result. Although this technique might not be for Andy, since it is not very interpretable. However, for Eqaan it is a definite contender.</p><h3>Smooth Weight of Evidence</h3><p>As we have just seen WOE is a great technique. However, it has one major drawback when dealing with the high cardinality variable. Namely, when the number of (non)events in the group is zero or close to zero, the value of WOE will be extremely large or even infinite. This creates unstable solutions. The trick is to correct for this. There are two ways to do this:</p><ul><li>You can combine groups with similar WOE. This brings you to optimal binning, which we will look at shorty.</li><li>You can adjust the WOE or log(odds) by adding a small number of (non)events that reflect the average odds, thus smoothing the proportion of rare to common values. This Smoothed Weight of Evidence (SWOE) approach is more robust. We are testing it below.</li></ul><pre><strong>def</strong> calcSwoes(df, catvar, target):<br>    rho <strong>=</strong> df[target]<strong>.</strong>mean()<br>    c <strong>=</strong> 25<br>    logit <strong>=</strong> np<strong>.</strong>log(rho<strong>/</strong>(1.0<strong>-</strong>rho)) <em># mean logit</em><br>    catvalues <strong>=</strong> df[catvar]<strong>.</strong>unique()<br><br>    <em># initialise my dataframe</em><br>    swoe_frame <strong>=</strong> pd<strong>.</strong>DataFrame()<br><br>    <em># calculate swoes</em><br>    <strong>for</strong> catvalue <strong>in</strong> catvalues:<br>        n <strong>=</strong> df<strong>.</strong>loc[(df[catvar] <strong>==</strong> catvalue)][target]<strong>.</strong>count()<br>        <em>#c_sub = np.maximum(0, (c - n))</em><br>        n_nonevents <strong>=</strong> df<strong>.</strong>loc[(df[catvar] <strong>==</strong> catvalue) <strong>&amp;<br></strong> (df[target] <strong>==</strong> 0)][target]<strong>.</strong>count()<br>        n_events    <strong>=</strong> df<strong>.</strong>loc[(df[catvar] <strong>==</strong> catvalue) <strong>&amp;<br></strong> (df[target] <strong>==</strong> 1)][target]<strong>.</strong>count()<br>        swoe <strong>=</strong> np<strong>.</strong>log((n_events <strong>+</strong> (c <strong>*</strong> rho))<strong>/</strong>(n_nonevents <strong>+</strong> (c <strong>*</strong>(1.0<strong>-</strong>rho))))<br>        swoe_frame <strong>=</strong> swoe_frame<strong>.</strong>append([[catvalue,swoe]])<br><br>    <em># rename columns</em><br>    swoe_frame <strong>=</strong> swoe_frame<strong>.</strong>rename(columns<strong>=</strong>{0:catvar,1:&#39;swoe&#39;})<br>    <strong>return</strong> (swoe_frame, logit)<br><br><br><strong>def</strong> swoe_enrich(df, swoe_frame, logit, catvar):   <br>    result <strong>=</strong> pd<strong>.</strong>merge(df, swoe_frame, on<strong>=</strong>[catvar], how <strong>=</strong>&#39;left&#39;)<br>    result<strong>.</strong>loc[(result[&#39;swoe&#39;]<strong>.</strong>isnull()),&#39;swoe&#39;] <strong>=</strong> logit<br>    <strong>return</strong> result</pre><pre><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(X_prep,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br>df_swoe_train <strong>=</strong> X_train<strong>.</strong>join(y_train)<br><em># calculate Woe&#39;s</em><br>Woe, logit <strong>=</strong> calcSwoes(df_swoe_train,&#39;city name&#39;, &#39;target&#39;)<br><br><br><em># Add encoded variable</em><br>df_ver_SWoe_train <strong>=</strong> swoe_enrich(X_train, Woe, logit, &#39;city name&#39;)<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<br>df_ver_SWoe_test <strong>=</strong> swoe_enrich(X_test, Woe, logit, &#39;city name&#39;)<strong>.</strong>drop(&#39;city name&#39;, axis <strong>=</strong> 1)<br><br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(df_ver_SWoe_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(df_ver_SWoe_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(df_ver_SWoe_test)[::,1]<br><br><br><em># Evaluate the model with the use of cv on the test dataset:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, df_ver_SWoe_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output:</p><pre>roc_auc = 0.792714 (0.012734)</pre><p>Surprisingly, the smooth weight of evidence has actually performed a little bit less than the weight of evidence. But the difference is minute, namely just about 0.001. Thus it looks like these two techniques give an almost identical results in our case.</p><h3>Hand-picked Binning</h3><p>One of the most intuitive thing to do, is to try and reduce the cardinality of the variable by hand. The logic behind this approach, is that although individually all the values that appear in the data only once or twice might not carry much information, combining might improve the predictive power. Not to mention this would greatly improve the interpretability, since you no longer have to describe all the individual values. However, the pitfall of this approach is that you will determine yourself exactly where the cut-off is. This can off course make any graph look nice, but the statistical underpinning of such an action is rather vague.</p><pre>keep_values <strong>=</strong> X_prep[&#39;city name&#39;]<strong>.</strong>value_counts()<strong>.</strong>loc[X_prep[&#39;city name&#39;]<strong>.</strong>value_counts()<strong>&gt;</strong>50]<strong>.</strong>index<br><br><em>#all cities that are not in the list, combine</em><br><strong>def</strong> re_code_city(x):<br>  <strong>if</strong> x <strong>not</strong> <strong>in</strong>(keep_values):<br>    <strong>return</strong> &#39;Combined_city&#39;<br>  <strong>else</strong>:<br>    <strong>return</strong> x</pre><pre><em>#recode and attach the new variable</em><br>recoded_city <strong>=</strong> X_prep[&#39;city name&#39;]<strong>.</strong>apply(re_code_city)<br><br><em>#one-hot encoding city: </em><br>enc_city <strong>=</strong> pd<strong>.</strong>get_dummies(recoded_city)<br><br><em>#Merge the dummmies to the df:</em><br>df_label <strong>=</strong> X_prep<strong>.</strong>drop([&#39;city name&#39;], axis <strong>=</strong> 1)<strong>.</strong>join(enc_city)<br><br><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(df_label,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(X_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(X_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(X_test)[::,1]<br><br><em># Evaluate the model with the use of cv:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, X_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Ouput:</p><pre>roc_auc = 0.790029 (0.019287)</pre><p>It’s difficult to argue, this method is very intuitive and Andy will find it very easy to explain others what he did. However, the result still comes short to our model with the frequency encoding. But maybe, if the binning will be done in a more sophisticated way we could achieve a better result?</p><h3>Optimal Binning</h3><p>Optimal binning is the optimal discretization of a variable into bins given a numeric target. It is a process where values of a variable are grouped into bins with similar target behavior. This binning is done in such a way to have an optimal relation between the new variable with the bins and target. You can add constraints like number of bins or bin-size.</p><p>Seeing which values ‘belong together’ could be very helpfull for understanding the relationship between variable and target. Problems like missings values or outliers are eradicated, these are put in one of the bins. The binned variable has a lot less categories, so a lot less dummy variables after hot-encoding.</p><pre><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(X_prep,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br><br><em># 1) Define your feature and target arrays</em><br>X_var <strong>=</strong> X_prep[&#39;city name&#39;]<br><br><em># 2) Instantiate class and fit to train dataset</em><br>optb <strong>=</strong> OptimalBinning(name<strong>=</strong>&#39;city name&#39;, dtype<strong>=</strong>&quot;categorical&quot; ,solver<strong>=</strong>&quot;cp&quot;)<em>#oke, min_prebin_size=0.01,max_n_prebins=50,gamma=0) #min_n_bins=3,max_n_bins=3,min_prebin_size=0.05)</em><br>optb<strong>.</strong>fit(X_train[&#39;city name&#39;], y_train)<br><br><em># 3) Show binning table</em><br>binning_table <strong>=</strong> optb<strong>.</strong>binning_table<br>binning_table <strong>=</strong> binning_table<strong>.</strong>build()<br><br><em># 4) To perform the binning of a dataset</em><br>x_transform_woe <strong>=</strong> optb<strong>.</strong>transform(X_var, metric<strong>=</strong>&quot;woe&quot;)<br>X_with_Woe <strong>=</strong> pd<strong>.</strong>DataFrame({&#39;city name&#39;: X_var, &quot;WoE&quot;: x_transform_woe})<br><em># dropping ALL duplicate values</em><br>X_with_Woe<strong>.</strong>drop_duplicates(inplace <strong>=</strong> <strong>True</strong>)<br><br>X_train_optbin <strong>=</strong> pd<strong>.</strong>merge(X_train, X_with_Woe, on<strong>=</strong>[&#39;city name&#39;], how <strong>=</strong>&#39;left&#39;)<br>X_test_optbin <strong>=</strong> pd<strong>.</strong>merge(X_test, X_with_Woe, on<strong>=</strong>[&#39;city name&#39;], how <strong>=</strong>&#39;left&#39;)<br><br><em># 5) To visualize the results table and plot</em><br>optb<strong>.</strong>binning_table<strong>.</strong>build()<br>optb<strong>.</strong>binning_table<strong>.</strong>plot(metric<strong>=</strong>&quot;woe&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTvU7QkxXtzhedJeuiRAmg.png" /></figure><pre><em># Instantiate the model (using the default parameters)</em><br>logreg_optbin <strong>=</strong> LogisticRegression()<br><br><em># Fit the model with data</em><br><em># logreg_optbin.fit(X_train,y_train)</em><br><br><em># df.loc[:, df.columns != col]</em><br>X_train_optbin2 <strong>=</strong> X_train_optbin<strong>.</strong>drop([&#39;city name&#39;], axis <strong>=</strong> 1)<br>X_test_optbin2 <strong>=</strong> X_test_optbin<strong>.</strong>drop([&#39;city name&#39;], axis <strong>=</strong> 1)<br><br><strong>from</strong> sklearn <strong>import</strong> preprocessing<br>scaler <strong>=</strong> preprocessing<strong>.</strong>StandardScaler()<strong>.</strong>fit(X_train_optbin2)<br>X_train_scaled <strong>=</strong> scaler<strong>.</strong>transform(X_train_optbin2)<br>X_test_scaled <strong>=</strong> scaler<strong>.</strong>transform(X_test_optbin2)<br><br><em># Fit the model with data</em><br>logreg_optbin<strong>.</strong>fit(X_train_scaled,y_train)<br><br><em>#Predict:</em><br>y_pred_optbin <strong>=</strong> logreg_optbin<strong>.</strong>predict(X_test_scaled)<br>y_pred_proba_optbin <strong>=</strong> logreg_optbin<strong>.</strong>predict_proba(X_test_scaled)[::,1]<br><br><em>#Getting its model coefficients:</em><br><em>#df_model_coef_optbin = pd.DataFrame(logreg_optbin.coef_[0,:], X_train_optbin2.columns)</em><br><em>#print(df_model_coef_optbin)</em><br><br><br><em># Evaluate the model with the use of cv on the test dataset:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, X_test_optbin2, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output:</p><pre>roc_auc = 0.792142 (0.012905)</pre><p>As predicted, this did better than binning categories by hand, however this model is not the best overall!</p><h3>Deletion</h3><p>There is also another approach, namely to remove the high cardinality variable altogether. Although this is a very quick solution, we would like to urge you against doing so. The variable could prove to be important for the model that you are trying to build. Removing it would cause you to loose valuable information. However, in our data we already have a variable that carries information regarding a city, namely city development index. So it might be that here it will be an acceptable solution. Obviously, we do not expect to get amazing results using this method.</p><pre><em>#Drop the city name variable altogether</em><br>df_drop <strong>=</strong> X_prep<strong>.</strong>drop([&#39;city name&#39;], axis <strong>=</strong> 1)<br><br><em># split X and y into training and testing sets</em><br>X_train,X_test,y_train,y_test<strong>=</strong>train_test_split(df_drop,y,test_size<strong>=</strong>0.20,random_state<strong>=</strong>42)<br><br><em># Instantiate the model (using the default parameters)</em><br>logreg <strong>=</strong> LogisticRegression()<br> <br><em># Fit the model with data</em><br>logreg<strong>.</strong>fit(X_train,y_train)<br><br><em>#Predict:</em><br>y_pred_dummy<strong>=</strong>logreg<strong>.</strong>predict(X_test)<br>y_pred_proba_dummy <strong>=</strong> logreg<strong>.</strong>predict_proba(X_test)[::,1]<br><br><em># Evaluate the model with the use of cv:</em><br>cv <strong>=</strong> StratifiedKFold(n_splits<strong>=</strong>5, shuffle<strong>=True</strong>, random_state<strong>=</strong>42) <br>scores <strong>=</strong> cross_val_score(logreg, X_test, y_test, cv<strong>=</strong>cv, scoring <strong>=</strong> &#39;roc_auc&#39;)<br>print(&quot;roc_auc = %f (%f)&quot; <strong>%</strong> (scores<strong>.</strong>mean(), scores<strong>.</strong>std()))</pre><p>Output:</p><pre>roc_auc = 0.779074 (0.014153)</pre><p>Unsurprisingly, model fit is worse than that of our baseline. However, the difference is not substantial and if one would have wanted to save some time on data processing, this variable could have been removed</p><p>In this article we took a look at different methods for dealing with categorical variables and how they perform in particularly if the variable has high cardinality. Overall we saw that all methods gave very comparable results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*VL4NBxrOUvS65fFG1FB65Q.png" /></figure><p>Lets now give the microphone to Andy and Eqaan, what did they think about all this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*N12GkdxzQDxM-zCF.png" /></figure><p>‘I personally would use a frequency encoding to deal with the city name variable. It is very easy to explain. I particularly like that you do not only get a very good model, but also get some more insights into the distribution of the variable itself. Maybe we can even think of some new interventions based on the location of our employees? Perhaps some interesting local events?’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*_W-YNjwMRFBRN7bM.png" /></figure><p>‘Frequency encoding was a clear winner. I would say that smooth weight of evidence was also a good approach. It performed just a little bit worse. I would also like to add that we see that — except for frequency encoding — the less interpretable techniques performed better than those that Andy would have preferred’</p><p>This article is of part of our <strong>No Data Scientist Is The Same </strong>series. The full series is written by <a href="https://medium.com/@anya.tonne">Anya Tonne</a>, <a href="https://medium.com/@jurriaan.nagelkerke">Jurriaan Nagelkerke</a>, <a href="https://medium.com/@karingruijs">Karin Gruijs-Vodde</a> and <a href="https://medium.com/@Tom_Blanke">Tom Blanke</a>. The series is also available on <a href="https://www.theanalyticslab.nl/blogs/">theanalyticslab.nl</a>.</p><p>An overview of all articles on Medium within the series:</p><ol><li><a href="https://medium.com/@anya.tonne/introducing-our-data-science-rock-stars-19ef8d9131a6">Introducing our data science rock stars</a></li><li><a href="https://medium.com/@jurriaan.nagelkerke/data-to-predict-which-employees-are-likely-to-leave-4fe1c64b1af4">Data to predict which employees are likely to leave</a></li><li><a href="https://medium.com/@Tom_Blanke/good-model-by-default-using-xgboost-ab14f26f7f6a">Good model by default using XGBoost</a></li><li><a href="https://medium.com/@Tom_Blanke/hyperparameter-tuning-for-hyperaccurate-xgboost-model-d6e6b8650a11">Hyperparameter tuning for hyperaccurate XGBoost model</a></li><li><a href="https://medium.com/@karingruijs/beat-dirty-data-5d9a6254c2f9">Beat dirty data</a></li><li><a href="https://medium.com/@anya.tonne/the-case-of-high-cardinality-kerfuffles-d9b7fccc6570">The case of high cardinality kerfuffles</a></li><li><a href="https://medium.com/@karingruijs/guide-to-manage-missing-data-961bee610ef9">Guide to manage missing data</a></li><li><a href="https://medium.com/@jurriaan.nagelkerke/visualise-the-business-value-of-predictive-models-21c6bc8132c">Visualise the business value of predictive models</a></li><li><a href="https://medium.com/@jurriaan.nagelkerke/no-data-scientist-is-the-same-42a5bfdf7ed6">No data scientist is the same!</a></li></ol><p>Do you want to do this yourself? Please feel free to download the Notebook on our <a href="https://gitlab.com/cmotions/publications/-/tree/master/NoDataScientistIsTheSameNotebooks">gitlab page</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9b7fccc6570" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cmotions/the-case-of-high-cardinality-kerfuffles-d9b7fccc6570">THE CASE OF HIGH CARDINALITY KERFUFFLES</a> was originally published in <a href="https://medium.com/cmotions">Cmotions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[INTRODUCING OUR DATA SCIENCE ROCK STARS]]></title>
            <link>https://medium.com/cmotions/introducing-our-data-science-rock-stars-19ef8d9131a6?source=rss-aea4df9990da------2</link>
            <guid isPermaLink="false">https://medium.com/p/19ef8d9131a6</guid>
            <category><![CDATA[data-scientist]]></category>
            <category><![CDATA[hr-analyst]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[people-analytics]]></category>
            <category><![CDATA[predictive-analytics]]></category>
            <dc:creator><![CDATA[Anya Tonne]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 15:22:49 GMT</pubDate>
            <atom:updated>2022-03-04T15:39:02.189Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>NO DATA SCIENTIST IS THE SAME!</em></strong> <strong>— part 1</strong></p><h3>Introducing our Data Science Rock Stars</h3><p><em>This article is part of our series about how different types of data scientists build similar models differently. No human is the same and therefore also no data scientist is the same. And the circumstances under which a data challenge needs to be handled change constantly. For these reasons, different approaches can and will be used to complete the task at hand. In our series we will explore the four different approaches of our data scientists — Meta Oric, Aki Razzi, Andy Stand, and Eqaan Librium. They are presented with the task to build a model to predict whether employees of a company — STARDATAPEPS — will look for a new job or not. In this blog we get to know our team. From this introduction you can already imagine that their approaches will be quite different.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pk54NrtnJ2tnaY9i.png" /></figure><p>Most people who never work with data don’t actually know what data scientists like us do. My grandma still believes that I fix laptops and hack the government as part of my job. We know that there is not one type of data scientist, we all do what we do with data differently. THe explorer in us wanted to explore how different types of data scientist would deal with the same questions. And of course, we would like to take you with us on this journey! So here they are, welcome to the stage Meta, Aki, Andy, and Eqaan. They work as data scientists in an innovation team of a large company called STARDATAPEPS. The firm loves experimenting with data and staying ahead of data trends. In the articles to follow, we’ll see how they deal with the same challenges in their work, but let’s introduce our rock star team first.</p><h3>Meta Oric: ‘It’s all about Meteoric speed ‘</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*FFlqkuHAf57BVxlx.png" /></figure><p>Meta is always super busy. She has an impressive portfolio consisting of a number of cool sounding projects where she uses the latest top-notch models. She claims to use state of the art models with little to no modifications and implements everything with a relatively short timeframe. She never spends too long on any of her projects and prefers ensemble techniques that do not require a lot of data preparation or model selection. XGBoost and LightGBM are her best friends, even though Meta cannot actually explain what is going on inside her predictive model (to other, non-statisticians). Her scripts are always well written and are ready to be reused in the following project.</p><h3>Aki Razzi: ‘Accuracy is what truly matters’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*eP9SAehEFggLl_7Q.png" /></figure><p>Aki has won multiple Kaggle competitions, since her models achieve the highest possible performance. Time and resources do not matter that much to her. Hail the almighty accuracy, precision and recall. She does not care whether a technique is easy to explain or not. Similarly, she is no stranger to using ensemble models to achieve the near-perfect performance as well as very convoluted feature engineering techniques.</p><h3>Andy Stand : ‘Understand is what we do’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*jNGQNfgt4ZLsfxT3.png" /></figure><p>Andy does not believe that black-box models are the future. He often finds himself in a meeting where he needs to explain to his colleagues how his model works and how the predictions are generated. He is happy to sacrifice a bit of accuracy in order to achieve the most clear and understandable solution. He makes sure that his planning allows for extensive feature engineering. As a result, all of his features can be understood and explained to others. Simple regressions and decision trees are the most utilised tools from his toolbox.</p><h3>Eqaan Librium: ‘Equilibrium and work-life balance’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*UK7qguIFAHIUolKR.png" /></figure><p>Eqaan strikes for balance. He likes to prepare his data himself and to have control over the preparation process, although he does not mind to have some ‘black-box’ elements. He wants to be able to explain his models and data manipulations to others, but seeks to have as accurate of a model as possible. This approach does cost him quite a bit of time.</p><h3>Task at hand: Predict which employees might leave</h3><p>Can you identify with one of our protagonists more than with the others? All of us certainly can. Though we often wonder what it is like to be in the shoes of another data scientist. Well, now is your chance. Meta, Aki, Andy, and Eqaan just heard of a new initiative, and immediately decided to sign up.</p><p>Their company decided to tap into the land of HR analytics. The idea is to predict whether their employees will look for a new job. Since data science is crucial for their day-to-day business, every employee is highly valued and being able to predict who is looking for a job might decrease personnel liquidity and thus the loss of knowledge. Thus, the company acquired an HR analytics dataset to see if they can build a model that would predict if an employee is likely to change jobs or not.</p><h3>The data science journey of Meta, Aki, Andy and Eqaan</h3><p>In the following articles, we’ll first get to know the data we have available a bit better. After that, we’ll see how the approach of our data science rock stars differs from each other. What choices to they make and how does that impact the predictive model they build? Finally, we have a team meeting with our data scientist and briefly discuss strengths and weaknesses of their different approaches. This ‘retrospective’ enables them to learn from each other. We hope you’ll get something from this journey as well, we did!</p><p>This article is of part of our <strong>No Data Scientist Is The Same </strong>series. The full series is written by <a href="https://medium.com/@anya.tonne">Anya Tonne</a>, <a href="https://medium.com/@jurriaan.nagelkerke">Jurriaan Nagelkerke</a>, <a href="https://medium.com/@karingruijs">Karin Gruijs-Vodde</a> and <a href="https://medium.com/@Tom_Blanke">Tom Blanke</a>. The series is also available on <a href="https://www.theanalyticslab.nl/blogs/">theanalyticslab.nl</a>.</p><p>An overview of all articles on Medium within the series:</p><ol><li><a href="https://medium.com/@anya.tonne/introducing-our-data-science-rock-stars-19ef8d9131a6">Introducing our data science rock stars</a></li><li><a href="https://medium.com/@jurriaan.nagelkerke/data-to-predict-which-employees-are-likely-to-leave-4fe1c64b1af4">Data to predict which employees are likely to leave</a></li><li><a href="https://medium.com/@Tom_Blanke/good-model-by-default-using-xgboost-ab14f26f7f6a">Good model by default using XGBoost</a></li><li><a href="https://medium.com/@Tom_Blanke/hyperparameter-tuning-for-hyperaccurate-xgboost-model-d6e6b8650a11">Hyperparameter tuning for hyperaccurate XGBoost model</a></li><li><a href="https://medium.com/@karingruijs/beat-dirty-data-5d9a6254c2f9">Beat dirty data</a></li><li><a href="https://medium.com/@anya.tonne/the-case-of-high-cardinality-kerfuffles-d9b7fccc6570">The case of high cardinality kerfuffles</a></li><li><a href="https://medium.com/@karingruijs/guide-to-manage-missing-data-961bee610ef9">Guide to manage missing data</a></li><li><a href="https://medium.com/@jurriaan.nagelkerke/visualise-the-business-value-of-predictive-models-21c6bc8132c">Visualise the business value of predictive models</a></li><li><a href="https://medium.com/@jurriaan.nagelkerke/no-data-scientist-is-the-same-42a5bfdf7ed6">No data scientist is the same!</a></li></ol><p>Do you want to do this yourself? Please feel free to download the Notebook on our <a href="https://gitlab.com/cmotions/publications/-/tree/master/NoDataScientistIsTheSameNotebooks">gitlab page</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19ef8d9131a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cmotions/introducing-our-data-science-rock-stars-19ef8d9131a6">INTRODUCING OUR DATA SCIENCE ROCK STARS</a> was originally published in <a href="https://medium.com/cmotions">Cmotions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>