Thursday, August 9, 2018

Reflections on a Life Well-Lived: My Uncle Lamar

It hadn't rained since the middle of June in the Seattle area, with heat above 90 degrees for days on end.  It was unrelenting.  Yet on Thursday August 2, 2018, it rained.  My Uncle Lamar passed away that day.

When I first started writing this, the day after, I did not yet know the full details of what had happened.  Despite this, I felt compelled to write about him.  Writing seemed to me to be the best way to process the loss, to remember him and to share him with others, and to make sure that I did not forget what he had taught me and what he might teach to others still.

I now know that he was biking as he often did.  He was found still alive from what was probably a heart attack, but passed away either on the way to the hospital or soon after.  This was not the first heart attack.  He had had one several years earlier.  Fortunately, that had taken place at a rock climbing gym with a heart defibrillator nearby.  My uncle, despite being in incredibly good shape and active, was dealt a bad biological hand, or more specifically, a bad biological heart, and there was little he could do about it.  Still in his early sixties, he should have had many more years to live.

Biology aside, my Uncle Lamar had a wonderful heart. He was without a doubt one of the best men I have ever known.  I think anyone who knew him would agree.

My earliest memories of him are of our yearly Christmas trip to visit him, my aunt, and my cousins.  I looked forward to cheesy potatoes and French toast casserole made by my aunt, and I couldn't wait to get into my uncle's woodshop in the garage, where we would sometime during our visit turn a bowl on the lathe or work on some other wood project.  While I didn't really know him at the time, I always enjoyed his company.  He was always laughing and making jokes.  He didn't treat me like a child to be dismissed or tolerated.  Instead, he engaged with me and treated me as equally worthy of his time as any adult.  As I got older, I continued to make yearly trips to visit, sometimes with my parents and siblings, but most recently, with my wife and my children.  These trips as an adult were where I really got to know and to admire him, as family, as a man, and as a friend.

Who was my uncle?  Perhaps it is easiest to talk about him in terms of the roles he played and the virtues he displayed.

He was a husband.  One of the ways I admired him most was in how he shared life with my aunt.  I can't imagine them apart. He always looked out for her best interests.  I always noticed how he checked on her needs: did she need any help, did she need a drink, was there anything he could do for her?  He was always making sure she was taken care of.  And I knew that he loved her.  From the affectionate nicknames to the ways they touched and interacted, there was a warmness and "knowingness" between them.  They laughed and joked together.  They were best friends.

He was a father.  As a father myself, I now appreciate this aspect of my uncle even more.  He handled my cousins with love and support, but also firmness and discipline.  He encouraged them in their pursuits and challenged them to be excellent.  He expected their best but did his part to show them how to be their best.  He also took time with them.  In recent years he has gone on numerous adventures and trips with his kids, building treasured memories and experiences that will last a lifetime.  Later this month he was going to go rock climbing with his son and my brother at Devil's Tower.  Both of my cousins are successful, intelligent, ambitious, and mature adults, thanks largely to his firm but loving guidance.

He was a servant.  As he sought my aunt's best interest, he also sought mine and that of anyone who was around.  He noticed when we needed a drink refill.  He'd carry in the luggage.  He always cleaned up after meals.  He'd take a dirty diaper out of my hand and take it outside to the garbage.  No task was too small for him to not do.  He looked for ways to serve others, and upon seeing the opportunities, he did them.

He was generous, with his time and his resources.  He would give you the shirt off his back, which he actually did once.  He had a jacket that he was wearing that didn't quite fit right and thought would fit my younger brother better.  He took it off, had my brother try it on, and as it was a good fit, gave it to him on the spot.  Then considering that he hadn't given me anything, he grabbed a fleece jacket that either he didn't need (or that he knew he could replace) and gave it to me.  One of my favorite memories occurred at my cousin's high school graduation BBQ in their backyard.  My son, who adored Uncle Lamar and was always excited to see him, hadn't yet said hello.  My uncle, who was hosting, watching over a pig being roasted, and talking with the many adults surrounding him, squatted down to eye level to have a chat with my son when he came over, and proceeded to talk with him for several minutes.  This made my son's day.  I also recall all of the many free samples of Proctor and Gamble samples from his work that we would take home with us, as he had plenty to share.  Many of the tools I use in my own home projects were given to me by him.

He loved the outdoors and travel.  Upon "retiring", he got a part-time job at REI partly to get more outdoor equipment.  He volunteered on the Pacific Crest trail maintaining the trail by clearing brush and logs.  He was a regular biker and rock climber.  He went on canoeing trips with his son.  Whenever we would visit, he would always recommend a trail to take a walk or hike on.  His trips around the world always involved visits to mountains, scuba diving, or other outdoor exploration.  He thoroughly enjoyed his hobbies.

He was a worker.  As best as I can recall, he basically took care of himself from the age of 16 onwards.  He worked fulltime and put himself through college, taking classes at night.  Eventually he earned an MBA.  He worked a lot on the road when my cousins were little, but he eventually made his way to a top sales and marketing position at Proctor and Gamble that was more stable and allowed him to be home and to avoid travel.  I never heard him complain about working hard.  Life is hard and working is hard.  He accepted that and made the best of it.

But he also knew when to have fun too and the right priority of things.  He retired as soon as he could to spend more time with family and those he loved, more time traveling, and more time enjoying life.  Of course he could have continued on to greater things in a career, but this was of no importance to him.  He devoted the past several years to making memories, and in light of recent events, this was definitely the right choice.  His family will have more loving memories of him than most people will of parents and husbands that lived many more years than he did.

He was a man of laughter and humor.  No matter the conversation or topic, he would inject humor into it.  Life is full of ironies and comical situations, and my uncle also saw these and pointed them out.  One always enjoyed a conversation with him.  Laughter would follow every paragraph.  His odd phrases and words (e.g., "gigundi" = gigantic) always brought a smile.  His other quirks, like always wearing shorts (even in the middle of winter), make me laugh whenever I think about them.

I do not really know what he believed about life after death, God, and so forth.  I think some bad experiences with religion and "religious people"  may have turned him off to faith.  Regardless, he struck me as someone who "loved thy neighbor" in spite of this.  I am reminded of a story in Langdon Gilkey's Shantung Compound.  In this, Gilkey writes about his experiences in an American and British civilian internment camp during WWII located in China and controlled by the Japanese.  He recounts the story of a woman of loose moral character in the camp.  The good "religious" folk in the camp looked down on her for this moral failing.  However, she was the one who took food to the needy.  She was the one who sought out those who were lonely and in need of extra care and attention.  She was the one who worked hard in the kitchen to help prepare meals for the camp members.  Contrast this with the "religious" members who, like the Pharisees, were more interested in the show and pretenses of religion than in actually living out the gospel.  My uncle was like this woman.  He instinctively lived out the values taught and shared by most religions, despite the lack of formal religiosity, and perhaps better than many (or even most) people with formal religious affiliation.

He was a man of peace and joy.  My uncle was at peace with himself and the world.  Perhaps that is why he felt free to serve and love others and why he radiated joy to others.  He knew who he was and what he was about.  He knew what mattered and he focused his efforts on that: loving others and building memories with others.  We would often discuss politics or whatever else was "wrong with the world".  While we often disagreed, it was always a beneficial and mutually affirming discussion.  He sought common ground on every topic and looked to interpret what was said in the best possible light.  He had no need to prove me wrong or to win an argument, as that was not really what mattered.  Instead, what mattered was our relationship, and he used every opportunity to strengthen and deepen that.  This peace and joy made him attractive, and people couldn't help but be drawn to him.

So what can we learn from him and his life?  I suppose it is nothing new or that we have not heard before, but it certainly rings more true to me today than it has before.

  • Love your family and your friends.  Today.  Concretely.  With words and actions.  Engage.
  • Experience life.  Take trips, make memories.  Don't put it off.
  • Work hard, but not too hard.
  • Don't take yourself too seriously.  Laugh!
  • Be generous.  Give.  You have enough to share.
  • Be open to new and different ideas.  Be charitable in your conversations.
  • Know yourself, know what matters, do it, and in that, be free.

I think my uncle would be ok with his passing.  Yes, of course he would have liked to have had 20 more years of life, as we would have liked to have had 20 more years with him.  But he was living every day to the fullest, and he had not put his life and his love on hold until a future unknown and unpromised time.  He was doing exactly what he should have been doing with his life, and consequently, could live and die without regret.

May that be true for all of us.

Rest in peace Uncle Lamar.

---------------------------------------------------

“The longer I live, the more I realize the impact of attitude on life. Attitude, to me, is more important than facts. It is more important than the past, than education, than money, than circumstances, than failures, than successes, than what other people think or say or do. It is more important than appearance, giftedness or skill. It will make or break a company...a church....a home. The remarkable thing is we have a choice every day regarding the attitude we will embrace for that day. We cannot change our past...we cannot change the fact that people will act in a certain way. We cannot change the inevitable. The only thing we can do is play on the one string we have, and that is our attitude...I am convinced that life is 10% what happens to me and 90% how I react to it. And so it is with you...we are in charge of our attitudes.” ― Charles Swindoll (and Lamar's favorite quote)

Wednesday, June 27, 2018

Independence of Irrelevant Possibilities and The 2016 US Presidential Election

The multinomial logit model depends on making the assumption of independence of irrelevant alternatives (IIA).  While there are different formulations, the general idea behind this principle is that when comparing two alternatives X and Y with a certain probability of preference in relationship to each other, the addition of an additional alternative Z shouldn't change the original relationship between X and Y.  That is, if X is favorable over Y, then adding Z should not change the fact that X is favorable over Y.  Z is supposed to be an irrelevant alternative to the consideration of X vs. Y.  See the Wikipedia article for more details (https://en.wikipedia.org/wiki/Independence_of_irrelevant_alternatives).

The IIA suffers from several criticisms (e.g., Red Bus - Blue Bus problem), which usually stem from having "alternatives" that are too similar to be considered alternatives.  What most interested me in reading about this principle is its applicability (or inapplicability) to voting.  In reading about various voting strategies, the problem seems to arise when one has 3 (or more) candidates and no candidate is preferred as a majority to all other candidates.  That is, some percentage less than 50% prefers A to B, some percentage less than 50% prefers B to C, and some percentage less than 50% prefers B to C.  This means that, for any candidate elected, there could be a majority that would have preferred a different candidate to be elected (again, see the Wikipedia article for more details).

When reading about this, what immediately came to mind was the 2016 US Presidential election.  It seems that, generally speaking, everyone was dissatisfied with the two main candidates, Trump and Clinton, and that a third candidate (Johnson), while preferred by very few outright, was seen as a legitimate alternative by many as opposed to the possibility of either Trump or Clinton being elected.  The final popular vote percentages were as follows (from http://www.presidency.ucsb.edu/showelection.php?year=2016):
  • Clinton: 48.2%
  • Trump: 46.1%
  • Johnson: 3.3%
Suppose, for the sake of argument, that:
  • 48.2% preferred Clinton to Johnson, and Johnson to Trump
  • 46.1% preferred Trump to Johnson, and Johnson to Clinton
  • 3.3% preferred Johnson to Trump, and Trump to Clinton
Then we have the interesting result that:
  • 51.5% prefer Johnson to Trump, who did in fact win.
Or suppose we change the last line and make it:
  • 3.3% preferred Johnson to Clinton, and Clinton to Trump
Then we get that:
  • 49.4% preferred Johnson to Clinton, which is higher than the popular vote for either Clinton or Trump.
If the above is close to people's actual preferences (that is, people preferred Johnson to the other party's candidate), then one can make the argument that Johnson "should" have been elected as the compromise candidate that most, or even a majority of, people would prefer if their primary candidate wasn't chosen.  Perhaps this isn't actually how people would have ranked the candidates, but it is certainly a reasonable possibility.

To go back to the multinomial model, what this means is that in many cases, perhaps even the most important cases where we want to predict in a multinomial way (i.e., elections), the assumption of IIA which is necessary will almost certainly be violated.  Often, our most important decisions involve choices that are too similar to each other, containing overlapping positives and negatives that are not clearly weighed against each other or decisive in leading to a choice.  We have many conditional choices that in fact do depend on the presence or absence of alternatives that we would not choose.  While there are other models that one can choose that do not rely on IIA (which have their own challenges), this problem certainly presents a challenge to those doing multinomial prediction.

Wednesday, June 20, 2018

Cross Validation: An Experiment

The purpose of a predictive model is NOT to predict existing data well.  Predicting existing data well is the means, not the end, which is instead to predict future unseen data well.  Typically, in order to prevent creating a great fitting model that doesn't perform well on future data (i.e., overfitting), an existing data set is divided into a training set and a test set, where the model is trained on the training set and then tested against the test set to see how well it performs.  However, what if you don't have enough data to have a separate test set?  Or how do you get sense of the variation in your model's performance?  You may have gotten a luck test set...

Cross validation provides a way to test one's model while still using all of the data available to train it, and one can be confident that one didn't get lucky in the test data being used.  In short, the model is created using a subset of the data before being tested against the hold out subset of the data.  This can be done many times.  Typically, with K-folds cross validation, 10 "folds" are created, and a model is trained using 9 of the folds and tested against the hold out fold, before repeating again using the next combination, for a total of 10 different models.  The results are then averaged so one can how well one's model does "on average".

While 5 or 10 folds is typically standard, I wanted to see what would happen across a variety of different values for K.  Using the Boston data set found in the MASS package, I used the caret package to perform the cross validation.

To start, I created a baseline glm model to predict a target variable (whether crime per capita is above or below the median crime rate).  This gave me a model with an accuracy of 0.9249 with a 95% CI of (0.8971, 0.9471).  Next, I found the average accuracy for each model trained using 2 to 250 folds.  The 249 results had an average accuracy of 0.9117 with a 95% CI of (0.9056, 0.9177).

From the below chart one can see that at lower values of K there is a slightly lower accuracy (there is a vertical line at K = 10).  Beyond 50 folds the average seems to be pretty settled around 0.9125 with some variation between 0.900 and 0.925.



So what does this mean?  It suggests that our baseline model was a little too optimistic at an accuracy of 0.925, as this is the upper bound of how the cross validated models performed.  However, this result is still within the CI provided by our baseline model, so that is good to know and reassuring.  In any case, we have a more reliable assessment of how our model will perform on future unknown data.  As expected, it is lower than the training accuracy, but not by so much as to make the model unusable for future predictions.

Also, we notice that our estimated future data accuracy will be impacted by the number of folds we choose.  Too few folds will mean that we have not tested against enough hold out data sets to make sure our model will generalize well, and our future data accuracy may not be trustworthy.  On ther other hand, too many folds may produce wildly different models due to differences in each small sample (plus this may take a lot of computing power).  While I'd need more experience to generalize, I don't see a reason not to use the standard K = 10 as a good middle ground.  In my model, increasing the folds above 50 doesn't move the accuracy at all.  And when viewing the results on a plot with a y-axis of 0 to 1, there is no discernible difference.


To summarize, if you need a way to test your model's ability to generalize to future/test data and would like a sense of how well it does this, consider cross validation to create a more robust, stable, and reliable model. 

Models aside, testing one's hypotheses, beliefs, or claims about the world (i.e., the results from one's model) to see how they perform in the world of facts and experience (i.e., future data) is just good epistemic practice.  If we want our beliefs to be justified and well grounded, shouldn't we want our models to be also?  So just as you should "cross validate" your beliefs, make sure to justify your models as well.  Cross validation is an effective means of doing so.


References:
https://www.r-bloggers.com/cross-validation-for-predictive-analytics-using-r/

Wednesday, June 13, 2018

The Confusion Matrix, Cost-Benefit Analysis, and Decision Making

The confusion matrix is aptly named.  Even though I have studied and used it many times, I still get confused and turned about in trying to remember the meaning of sensitivity vs. specificity or false negatives vs. false positives.  Despite its confusing nature, understanding what the confusion matrix means and being able to correctly use it is not important only for those in data related fields.  If we abstract the confusion matrix and understand it as being a way to assess trade-offs or cost vs. benefits, then we can see that this skill or way of thinking is important for everyone and can help us make better decisions in our daily lives.

The confusion matrix is typically presented as a four box table comparing predictions vs. actual values for a model.  On the rows, we have the predictions for a class (positive on top, negative on the bottom).  On the columns, we have the actuals for a class (positive on the left, negative on the right).  Consequently, when our model predicts a positive accurately, this is a true positive (top left corner).  Similarly, when our model predicts a negative correctly, this is a true negative (bottom right corner).  However, when our model predicts a positive but this is actually a negative, this is called a false positive (the model falsely predicted positive).  Similarly, when our model predicts a negative but this is actually a positive, this is called a false negative (the model falsely predicted a negative).  See here if you are still confused.

Ideally, we want our predictive models to correctly predict positives when the actuals are positive and negatives when the actuals are negative, and so there would be no false positives or false negatives.  But this isn't reality.  Reality is this: (1) our models, even our best models, get it wrong sometimes (they produce false positives and false negatives); (2) we have competing models that make different predictions and get different right and wrong predictions.

This presents us with a question: in the face of multiple models, which model do we choose and why?  Enter in costs and benefits associated with each kind of correct prediction and incorrect prediction.  But before we can even do that, we have to really understand what problem we are trying to solve.  What are we trying to do?  What is the model supposed to help us do?  What in the end are we trying to optimize?  Once we have a good understanding of this, then we can assign costs and benefits to each kind of prediction and outcome, and then choose the model that offers the best benefits with the fewest costs.

For example, suppose we have medical test A and medical test B for detecting a certain disease.  Perhaps medical test A has more true positives and more true negatives than medical test B.  Then it seems we ought to choose medical test A.  However, suppose that medical test A has way more false negatives than medical test B, and a false negative leads to death of the individual (the disease is present but was missed by the test and immediately led to the death of the individual since it was not treated).  Then maybe medical test B is better.  Suppose the medical test B is prohibitively expensive while medical test A is relatively cheap.  Then maybe we are back to choosing medical test A as the preferred option all things considered.

The point here is that we have to be clear about what we are trying to optimize, and there will be tradeoffs (e.g., cost vs. life-saving) that we will have to assess in order to optimize.  And people may disagree as to how to correctly assign costs and benefits or in what ought to be optimized.  In such a case, some sort of compromise will likely be required (e.g., saving costs while also saving lives).  Still, the very act of thinking critically about what we are trying to optimize, and what the relevant costs and benefits are, is a useful skill that needs to be developed, and is what is required in making effective decisions in all parts of life.  A confusion matrix forces us to think in this way and to develop this skill.

While the confusion matrix can perhaps tell us which model is statistically best, it cannot tell us which model is best from a cost-benefit analysis in the given business, medical, or other context.  We have to supply the criteria for what is a cost and what is a benefit.  But thankfully, once we are clear on that, we can figure out which model to use in order to optimize the cost vs. benefit tradeoff.  And once that model has been chosen, we can confidently use it to guide our decisions on what to do based on its predictions.  We will also have benefited from being forced to deeply understand the nature of the problem we are trying to solve.  This exercise makes us better thinkers and better decision makers, and hopefully, makes the world a little less confusing to us and others.

Wednesday, June 6, 2018

The Median and the Mean

The mean and median are both used to understand what the "center" of a distribution is, or what may be considered "normal" or "typical".  But what are their strengths and weaknesses?  Why prefer one to another, and when should you choose one versus the other?

The mean is the average value, and is found by adding up all values and then dividing that sum by the total number of values in the calculation.  For example, the mean of 2, 3, 4 is (2 + 3 + 4)/3 = 3. The median is the middle value, found by arranging all values in order and then selecting the middle value (or using the average between the two middle values if there isn't a single middle value).  For example, if we have 3, 6, 1, 8, 9, then the median is 6 since 6 is the middle value (1, 3, 6, 8, 9).

In a normal distribution, uniform distribution, or any other distribution of values that has symmetry around the middle (same number of values on either side of the "middle", same standard deviation of values on either side of the "middle"), the mean and median should be roughly the same.  However, when the values are skewed in some way (more values on one side of the "middle" than the other, differing standard deviations on either side of the "middle"), then these can be radically different.  A single value like an outlier can greatly change the mean while leaving the median untouched.

So why wouldn't we always use the median if it is always going to give us a better "middle" value?  Because it may not actually give us a better "middle" value. For example, suppose you have the values 1,2,2,3,98,99,100.  The mean is 43.5.  While there is no actual value of 43.5, we intuitively believe this to be the center of the distribution of values.  However, if you find the median, you get 3, which does not adequately describe the middle value of the distribution.  So, if the values are in two separated groups, the median will not find the center between those two groups, but will be in one group or the other, whereas the mean will find a non-actual value that is in between the two groups and does more accurately represent the "middle" value.

Also, suppose that we have this set of values: 1,1,1,1,1,1,1,50,50,50,50,50,75,100.  The mean is about 30 while the median is 25.5 (halfway between 1 and 50).  This is similar to the above situation in that the mean seems to do a better job at getting at the "middle" value than the median.  In this case, both the mean and the median are values that do not actually exist in the data.  We might also say that the best value to use here as being the "typical" value is the mode, which is 1.

We could contrive other sets of  values that make the mean, median, or mode the "best" or most intuitive single representative of the "typical" or "normal" or "middle" value in the data set.  The main point here is that the above shows the need to look at the data to understand which value makes the most sense for our given purpose.  Neither the mean nor the median will be the "right" value representation of the "middle" or the "typical" value for every situation.

One other consideration.  The mean is typically faster to find or calculate than the median.  Why?  For the mean, the order of the variables does not matter: you add them up and divide by their count.  For the median, the values have to be sorted first before the middle value can be found.  This takes longer.  I ran a couple experiments on my computer in R to test this.  Here are the results:

#1: 100,000 simulations of finding the mean and the median for a uniformly randomly generated list of 1,000 numbers from 0 to 1,000.
  • Total Time:
    • Mean:    2.07 seconds
    • Median: 7.76 seconds
  • Mean Time:
    • Mean:    0.00002070 seconds
    • Median: 0.00007765 seconds
  • Median Time:
    • Mean:    0 seconds
    • Median: 0 seconds
  • Max Time:
    • Mean:    0.00250 seconds
    • Median: 0.17618 seconds

#2: 100,000 simulations of finding the mean and the median for a uniformly randomly generated list of 10,000 numbers from 0 to 1,000.
  • Total Time:
    • Mean:    4.11 seconds
    • Median: 29.50 seconds
  • Mean Time:
    • Mean:    0.0000411 seconds
    • Median: 0.0002950 seconds
  • Median Time:
    • Mean:    0.000000 seconds
    • Median: 0.000489 seconds
  • Max Time:
    • Mean:    0.0035 seconds
    • Median: 0.1822 seconds
#3: 100,000 simulations of finding the mean and the median for a uniformly randomly generated list of 100,000 numbers from 0 to 10,000.
  • Total Time:
    • Mean:      23.38 seconds
    • Median: 243.73 seconds
  • Mean Time:
    • Mean:    0.000233 seconds
    • Median: 0.002437seconds
  • Median Time:
    • Mean:    0.000000 seconds
    • Median: 0.002001 seconds
  • Max Time:
    • Mean:     0.031 seconds
    • Median:  0.193 seconds
The median calculation takes 3 to 7 to 10 times as long on average as the mean calculation.  I am sure that if I continued to increase the complexity of the task, this disparity would also increase.

To conclude, think critically about which value (mean, median, or even the mode) best represents the data set for your particular purposes.  If either the mean or the median will suffice and especially if the repeated technical work you are doing is time consuming (e.g., data transformations, modeling), perhaps the mean will work better for performance purposes.

Thursday, May 31, 2018

The Under Appreciated Single-Variable Linear Model

Introduction

I was surprised, and sort of shocked.  How could this be?  In 2018, within a successful company, within no less the reporting department, there was no awareness of the importance, much less how to even do, a simple linear model.  Horrifying, I know. 

The question was simple: how did increases/decreases in the frequency of a business process relate to call volume?  I received an Excel file which showed data for both call volume and the business process frequency over time, plotted in a single chart.  I was left to correlate the rising and falling of both visually.  As one might suspect, there did appear to be a pattern.  But what was its exact nature?  How could it be quantified?

Fortunately, I knew that I could change the chart type, plot business process frequency vs. call volume, add a trend line, display the trend line equation and R^2 value, and presto: I had a mathematical model of the relationship and a measure for how strong that relationship was.  And it only took a minute or two.  And it was all done in Excel with absolutely no coding.  Easy.

Compare this experience with a more typical experience of mine at the other extreme:
  • Potential Client: "Do you have production experience building deep learning models from scratch?"
  • Me: "No, but I do have production experience in other kinds of machine learning models and have built deep learning models in practice.  Could you tell me more about why you believe deep learning relates to and could solve your business problem?"
  • Potential Client: "Thanks for your time."
Ok, I exaggerate a little, but you get the point.  It seems like everyone wants a deep neural network without even knowing what it is or how it might help them solve any of their business problems.  It is the latest hammer, for which every problem is a nail.  Once the deep learning fad has passed, we will all realize that it is one of many machine learning methods.  Like any tool, it has specific useful applications (e.g., natural language processing, image classification), but it shouldn't be applied to everything, due to implementation challenges, inapplicability, or just the fact that it is overkill.

 

Keep It Simple: Single Variable Linear Models

My point is that there is a large space in between no use of statistical/machine learning models (the first story) and the use of the most complicated kinds of machine learning models for everything (the second story). In that space, at each level of sophistication, there are uses that make that kind of model the ideal solution in comparison to other kinds of models.  I would further conjecture that the need for increasing sophistication in models decreases as the sophistication increases.  Said differently, the majority of business problems as they exist today that require statistical or machine learning models to solve could use relatively simple linear regression or other kinds of simple classification models (e.g., decision tree) to a satisfactory degree.

Let's just focus on the under appreciated single-variable linear model (SVLM).  If you want to understand how one numerical variable relates to another numerical variable, start here.  The benefits of using a SVLM include:
  • quick to train (nearly instantaneous)
  • easy to visualize
  • clear and simple mathematical relationship
  • easy measure to understand strength of the relationship (R^2)
  • no coding required as it is implemented in every reporting tool I know of that is worth your time (e.g., Excel, Tableau, PowerBI).
What can you do with it?  As stated before, you can
  • gain an initial understanding of how one numerical variable relates to another numerical variable
  • compare how different variables (X1, X2, X3,...) relate to a single numerical variable (Y) in order to determine which is most important in predicting that variable (i.e., most correlated)
  • determine how the dependent variable (Y) changes on average with every unit change in the independent variable (X).
  • and more!

Does It Apply to My Life?

Consider three real daily life applications:
  • Car MPG
    • How do my miles driven relate to my gallons of gas used?  Keep track of how many gallons you fill up each time along with the change in miles per fill up.  Not only will you know how many miles per gallon your car averages, but you will be able to create a simple model: GallonsUsed = InitialGallons + Coefficient * Miles.  For example, the model could state that your car always uses 2 gallons of gas (regardless of miles driven), but for every 20 miles you drive, you use an additional gallon of gas (20 MPG).  Then your model would be: GallonsUsed = 2 + (1/20)*Miles.  Looking at the summary of the linear model or by looking at the plot, you could get a sense for how much variation is normal.  If your MPG were to ever drop below what is in this normal variation (i.e., you use lots of gallons for few miles), then you would know that something is likely wrong with the car.
  • Weight Loss Methods Effectiveness
    • Is exercising or calorie intake more important in determining how much weight is lost?  I know this is a much more complicated question than I am suggesting here, but one could compare the effectiveness of exercising versus reduced calorie intake in losing weight.  In so doing, one could determine not only which is more effective, but how much more effective it is.  Suppose for a year you tracked how many hours per week you went for a walk or exercised, how many calories you took in, and your average weight for the week.  Then you would have 52 weeks of exercise, calories intake, and average weight.  By running a SVLM predicting weight loss (difference from week to week) from exercise time and another SVLM predicting weight loss from calorie intake, one could determine which is more important for changing the weight (assuming all else is equal, which is a big assumption).
  • Bills and Budget planning
    • You get a high electricity bill in January.  Didn't see that coming, right?  Why is it so high?  A major factor is the outside temperature, especially if your heat comes from electricity usage.  Suppose you want to budget for future months so you have the right amount of money set aside.  What could you do?  Gather the average monthly temperatures for each month, match these to your electricity bills for the same month, and create a SVLM.  The model will look something like this: MonthlyBill = InitialAmount + Coefficient*AverageTemperature. 
    • I just did this and it took about 5 minutes to copy the monthly billing $$ by month for the past 15 months from my account and then gather the monthly average temperatures by month for my area.  The initial model predicting monthly bill was: MonthlyBill = $403 - $5.16*AverageTemperature.  It had an R^2 of  0.81, so not bad.  The way this is modeled is a little hard to understand, but essentially, start at $403 (what I would pay if the temperature was 0 degrees) and subtract $5.16 for every degree increase in temperature.  But the temperature is never 0 degrees, and it is hard to know what I need to set aside each month from this...
    • An easier model to understand uses the difference between the maximum yearly average temperature and the monthly average temperature for a given month.  That model is MonthlyBill = $62.25 + $5.16*MaxMinusAverageTemperature.  It still has an R^2 of 0.81.  So I know immediately that I need to set aside $62.25 a month for my electricity bill at the very least, as this is the lowest my bill is ever going to be (when the outside temperature is highest).  As the temperature decreases (and the difference between the max temperature and the average temperature increases) I pay an additional $5.16 for each decrease in average temperature.  So in cold months that are on average about 25 degrees cooler than the hottest month, I know that my bill should roughly be about $62.25 + $5.16 * 25 = $191.25 for that month (which is about right), and so I should budget accordingly.

Conclusion

You have access to data from your real daily life that you can use a single variable linear model to understand, predict, and guide your actions.  You don't need to be an expert in neural networks to do so, and you don't even need to know anything much beyond Excel.  All you need is a little creativity to understand how to use simple tools like the SVLM to gain valuable insights that can help you make better decisions and consequently, improve your life.

Monday, April 23, 2018

Married to My Work

The phrase "married to my work" is supposed to carry a negative connotation.  It means something like: one's work comes first and foremost in priority, consumes most of one's time (even supposedly free time), that one can never get away from work, it distracts or takes away from family and friend time, and so forth.  The above would be more accurately described as being a "slave to my work," and is obviously not a healthy situation.  On the contrary, an appropriate level of being "married to my work" is a good thing.  But to understand this, we must first reflect on our understanding of marriage itself.


Dating vs. Marriage

What typically is the purpose of dating?  To paraphrase Tom Hanks in Sleepless in Seattle, it is to "try others on" to see how they fit with you.  Do you like the same things?  Do you enjoy talking and spending time together?  Do you have shared values and dreams?  Can you support each other?  It is very much self-focused: what can I or am I getting out of this?  This need not be selfish or self-centered, as it is important if one's ultimate aim is to find a partner for marriage that one finds a good match.  But there is a tendency to focus on having fun, and if things get rough, it might be easier to bail on the relationship instead using the opportunity to grow.

Marriage is different.  Read any marriage book or talk to any marriage counselor.  Once you say "I do", if your marriage is to be successful, you must now begin to focus on the other.  How can you support your spouse's dreams, goals, and pursuits, especially if they are different from your own? The idea behind marriage is that you achieve more and become more having committed to one person.  For better or worse, in sickness and in health, this person is supposed to help you fully realize your potential (and you are supposed to do the same).  You trade short-term, low-commitment advantages for a long-term investment that you can only get from sticking it out with one person for a lifetime.  You get to go deep with someone, knowing that they have committed to you and you have committed to them, and so you can be vulnerable and share yourself with them.

Traditionally, marriage has been about the mutual support of the spouses and the procreation of children.  It is best for you in the long term, and it is fruitful as children are brought into the world and reared.  It is supposed to provide a stable and loving environment for all members to live and grow in.  Yes, it is hard, yes, there are bad times, but in theory, when one looks back on one's life, one will be able to see that one has grown, matured, and gained far more than one has lost in being married as opposed to maintaining a single or frequent dating lifestyle.  The commitment is what allows one, indeed, forces one, to grow and be fruitful, as this is often born out of the challenges of marriage.

No, I am not saying that single people cannot grow and mature without being married or that they will have unfulfilling lives.  Any relationship that is a sustained commitment, an investment, through thick and thin, for the long haul, will encourage and require us to grow, but will also provide life-long enjoyment.  Think of your best friends, your siblings, your parents even.  These are our meaningful relationships.  These are the kinds of relationships that prove to be the most fulfilling.  These relationships are what we are made for.


Application to Work

With the above in mind, what is our approach to our work?  Now I am not advocating placing work above family or other legitimately higher priorities.  But what really is our attitude towards and commitment to work?  Are we dating our work, or married to it (in a healthy way)?  Work is important, and it can be very satisfying, dignifying, and developing in our personal growth and flourishing as a human being.

I have been consulting for the past six years.  The life of a consultant (in my experience, granted, your experience may be different), is that one goes from project to project, company to company, 3, 6, 12 months at a time.  You get in, get what you want out of it (or what your client wants out of it), and then you move on.  It is much like dating.  Either you break up with your client or your client breaks up with you after the work has been accomplished, the relationship has soured, or something else better comes along.  You always have one foot out the door.

Consequently, one's attitude towards work shifts to "what can I get out of this?" for every new project: will it advance my career, will I learn new skills, will I broaden my experience?  The client is asking the same thing: will this consultant advance my work, my project, and my career?  Now some of this is fine and good and healthy, as we do need to think about what is best for us (in a healthy way).  But it is interesting to notice how this can prioritize short term gain over the long term benefits of really committing to a role for the long haul, and encourages breadth of experience at the cost of depth of experience and knowledge.

I recently had the opportunity to go full time and leave consulting behind.  In thinking about whether to accept that opportunity, the analogy to dating and marriage came to mind.  Going full time is much more like marriage.  I would be trading a broad range of experiences for the depth of a single experience.  Instead of having relatively shallow knowledge of a wide variety subject areas, I would become an expert in a relatively narrow field.  Instead of hopping from project to project after my work has been completed, I would get to enjoy the "fruits of my labor" along with the challenges of building and maintaining a long term solution.  I would be committed, knowing that I cannot just walk away if the work gets challenging or coworkers get unpleasant.  I'd be in it, for better, and for worse.  And the role would definitely require more of me both in time and effort.  But hopefully, I'd get to reap the rewards of that long term commitment: greater satisfaction, deep knowledge, something I can point to as having accomplished, deeper friendships with coworkers, and personal and professional growth.


Conclusion

Yes, there is a time for dating your work.  And there are outside work commitments and other considerations that may make a lesser commitment to your work the right decision.  Yes, you should prioritize your family and perhaps other commitments over work. Yes, you shouldn't be overly committed to your work in an unhealthy environment, and you should maintain appropriate boundaries.  Yes, yes, yes, all of that needs to be considered. 

But after considering all of the caveats and addendums and factors in your life, honestly reflect: are you dating your work?  Why?  Is there a good reason?  Are you satisfied with your work?  If not, maybe its because you have never really committed and invested in your work in the ways that are necessary for satisfaction, fruitfulness, growth, and fulfillment in the long term.

If you want to be happy in your work, maybe it's time to get married.

Monday, February 5, 2018

2017 NFL Game Predictions: Best Team and Season Recap

Welcome!  I intend this to be an ongoing project of predicting NFL game outcomes, point spreads, and final scores.  My hope is that my models will improve over time as they become more sophisticated and use better data.  I will try to regularly publish predictions to keep myself accountable, and will make observations along the way about what is working and what isn't.  See below for latest updates.  Enjoy!



 _________________________________________________________________________________

Congrats to the Eagles for winning the Superbowl.  Even though they won, were they the "best" team of the season?

Best Team of 2017

If each team played every other team, who would come out on top?  According to my model with the final data, if measured by total probability of wins, the Patriots, Saints, and Vikings take 1, 2, and 3 with about 24 wins out of 32 games.  The Eagles are down in 8th. The Giants, Browns and Buccaneers, take 32,31, and 30.  If measured by total games won, then the Vikings, Eagles, and Saints take 1, 2, and 3, while the Giants, Browns, and Buccaneers take 32,31, and 30. The Patriots take number 4.
  • The Patriots have the highest total probability of winning each game when they are predicted to win.  11 of their 32 games have a 90% or greater predicted probability of winning.  However, they are predicted to win fewer times than other teams (i.e., Vikings, Saints, and Eagles).  As such, they are less consistent, prone to have a high probability of winning one week but then losing the next week by a narrow probability.
  • The Vikings are predicted to win 8 of their 32 games with a 90% probability or more, and are predicted to win every game.  They appear in both top 3 lists.
  • The Saints are predicted to win 9 of their 32 games with a 90% probability or more, and are predicted to only lose to the Eagles and Vikings.  They appear in both top 3 lists.
  • The Eagles are only predicted to win 5 of their games with a probability of 90% or more, but are predicted to only lose to the Vikings.  They win a lot, but by narrow margins.
So what can we conclude?  My model relies heavily on win ratio, but also factors in injuries, and given that the Eagles lost their starting QB, I think my model ranked them lower as this usually is detrimental to a team's future success in the season.  Without injuries, my model gave the top spot to the Eagles, and they did win the Superbowl.  Nick Foles was amazing and my model definitely does not give him enough credit as the replacement QB.  The Eagles had the best record until losing Carson Wentz, and probably would have had the best record if Carson Wentz had finished the season.

I think there is a case for any of these four teams to be considered to be the "best" team of the season, but given the foregoing, and even though my model does not quite show it, I think the title is definitely appropriate for the Eagles, all things considered.  The Eagles were the "best" team of the season.  Well done!
Total Probability:

Rank
Team
Expected Value
1
Patriots
24.463
2
Saints
24.045
3
Vikings
24.019
4
Steelers
23.841
5
Panthers
23.441
6
Jaguars
22.743
7
Rams
22.306
8
Eagles
22.135
9
Titans
21.638
10
Chargers
20.112
11
Falcons
19.714
12
49ers
19.393
13
Chiefs
19.081
14
Bills
19.011
15
Seahawks
18.374
16
Lions
17.773
17
Bengals
16.529
18
Cardinals
16.405
19
Ravens
16.299
20
Cowboys
15.162
21
Packers
13.94
22
Bears
12.294
23
Redskins
11.858
24
Dolphins
10.469
25
Jets
9.765
26
Broncos
8.734
27
Colts
7.953
28
Raiders
6.973
29
Texans
6.744
30
Buccaneers
6.282
31
Browns
5.64
32
Giants
4.864
 Total Games:
Rank
Team
Total Wins
1
Vikings
32
2
Eagles
31
3
Saints
30
4
Patriots
29
5
Steelers
28
6
Panthers
27
7
Jaguars
26
8
Rams
25
9
Titans
24
10
Chargers
23
11
49ers
22
12
Falcons
21
13
Bills
20
14
Chiefs
19
15
Seahawks
18
16
Lions
17
17
Bengals
16
18
Ravens
15
19
Cardinals
14
20
Cowboys
13
21
Packers
12
22
Bears
10
22
Dolphins
10
22
Redskins
10
25
Jets
8
26
Broncos
7
27
Colts
6
28
Raiders
5
29
Texans
4
30
Buccaneers
3
31
Browns
2
32
Giants
1
  
 Average Rank:

Rank
Team
AverageRank
1
Vikings
2
2
Saints
2.5
2
Patriots
2.5
4
Steelers
4.5
5
Eagles
5
6
Panthers
5.5
7
Jaguars
6.5
8
Rams
7.5
9
Titans
9
10
Chargers
10
11
49ers
11.5
11
Falcons
11.5
13
Bills
13.5
13
Chiefs
13.5
15
Seahawks
15
16
Lions
16
17
Bengals
17
18
Ravens
18.5
18
Cardinals
18.5
20
Cowboys
20
21
Packers
21
22
Bears
22
23
Redskins
22.5
24
Dolphins
23
25
Jets
25
26
Broncos
26
27
Colts
27
28
Raiders
28
29
Texans
29
30
Buccaneers
30
31
Browns
31
32
Giants
32

Season Recap

 Here are some summary statistics (granted, I only predicted from week 16 onwards):
  • Correct Prediction %:
    • Whole season (regular and playoffs): 63%
    • Regular season: 66%
    • Playoffs: 55%
  • Statistical significance two-tailed binomial test (95% CI):
    • Whole season: 
      • p-value:  0.1263
      • CI: (0.467,0.770)
    •  Regular season:
      • p-value: 0.1102
      • CI: (0.468,0.814)
    • Playoffs:
      • p-value: 1
      • CI: (0.233,0.832)
My predictions were accurate about 63% of the time.  Given the small number of predictions, this was NOT statistically significant (although in previous seasons with more predictions it was).  Similarly to past seasons, I didn't do so well in the playoffs, but I am not surprised.  The playoffs are much harder to predict as the teams are better, more evenly matched, and there are fewer games to predict so each one counts for more in the percentages.

Conclusion

I wasn't able to do predictions for the whole season given time constraints and other responsibilities.  I don't know what next season will bring, so no promises.  But hopefully I can make predictions for the entire 2018 season and make a few improvements to the model.  We'll see...  Thanks!