1 of 47

CSE 519: Data Science

Steven Skiena

Stony Brook University

Lecture 13: Building and Validating Models

2 of 47

The Data Science Analysis Pipeline

Modeling is the process of encapsulating information into a tool which can make forecasts/predictions.

The key steps are building, fitting, and validating the model.

3 of 47

Which is Best?

There are many ways to model any given data set.

How can we decide which approach is better?

4 of 47

Philosophies of Modeling

We need to think in some fundamental ways about modeling to build them in sensible ways.

  • Occam’s Razor
  • Bias-Variance trade offs
  • Nate Silver: The Signal and Noise

5 of 47

Occam’s Razor

This philosophical principle states that “the simplest explanation is best”.

With respect to modeling, this often means minimizing the parameter count in a model.

Machine learning methods like LASSO/ridge regression employ penalty functions to minimize features, but also do a “sniff test”.

6 of 47

Bias-Variance Tradeoffs

“All models are wrong, but some models are useful.”

– George Box (1919-2013)

  • Bias is error from erroneous assumptions in the model, like making it linear. (underfitting)
  • Variance is error from sensitivity to small fluctuations in the training set. (overfitting)

First-principle models likely to suffer from bias, with data-driven models in greater danger of overfitting.

7 of 47

What would Nate Silver do?

8 of 47

Principles of Nate Silver

  • Think probabilistically
  • Change your forecast in response to new information.
  • Look for consensus
  • Employ Bayesian reasoning

9 of 47

Live Models

A model is live if it continually updating predictions in response to new information.

  • Does the forecast ultimately converge on the right answer?
  • Does it display past forecasts so the user can judge the consistency of the model?
  • Does the model retrain on fresher data?

10 of 47

Presidential Election Forecast, 2016

11 of 47

Look for Consensus

  • Are there competing forecasts you can compare to, e.g. prediction markets?
  • What do your baseline models say?
  • Do you have multiple models which use different approaches to making the forecast?

Boosting is a machine learning technique which explicitly combines an ensemble of classifier.

12 of 47

Google Flu Trends

Predicted flu outbreaks using query frequency of illness terms.

The model failed after Google added search suggestions

13 of 47

Modeling Methodologies

  • First principle models: based on a theoretical explanation of how the system works (like simulations, scientific formulae)
  • Data-driven models: based on observed data correlations between input parameters and outcome variables.

Good models are typically a mixture of both.

14 of 47

Baseline Models

“A broken clock is right twice a day.”

The first step to assess whether your model is any good is to build baselines: the simplest reasonable models to compare against.

Only after you decisively beat your baselines can your models be deemed effective.

15 of 47

Representative Baseline Models

  • Uniform or random selection among labels.
  • The most common label in the training data.
  • The best performing single-variable model.
  • Same label as the previous point in time.
  • Rule of thumb heuristics.

Baseline models must be fair: they should be simple but not stupid.

16 of 47

How Good is Your Model?

After you train a model, you need to evaluate it on your testing data.

What statistics are most meaningful for:

  • Classification models (which produce labels)
  • Regression models (which produce numerical value predictions)

17 of 47

Evaluating Classifiers

There are four possible outcomes for a binary classifier:

  • True positives (TP) where + is labeled +
  • True negative (TN) where - is labeled -
  • False positives (FP) where - is labeled +
  • False negatives (FN) where + is labeled -

18 of 47

Threshold Classifiers

Identifying the best threshold requires deciding on an appropriate evaluation metric.

19 of 47

Accuracy

The accuracy is the ratio of correct predictions over total predictions:

The monkey would randomly guess positive with p=0.5, with accuracy 50%.

Picking the biggest class yields >=50%.

20 of 47

Precision

When |P|<<|N|, accuracy is a silly measure.

If only 5% of tests say cancer, are we happy with a 50% accurate monkey?

The monkey would achieve 5% precision, as would a sharp always saying cancer.

21 of 47

Recall

In the cancer case, we would tolerate some false positive (scares) to identify real cases:

Recall measures being right on positive instances.

Saying everyone has cancer gives perfect recall!

22 of 47

F-Score

To get a meaningful single score balancing precision and recall use F-score:

The harmonic mean is always less than/equal to the arithmetic mean, making it tough to get a high F-score.

23 of 47

Take Away Lessons

  • Accuracy is misleading when the class sizes are substantially different.
  • High precision is very hard to achieve in unbalanced class sizes.
  • F-score does the best job of any single statistic, but all four work together to describe the performance of a classifier.

24 of 47

Receiver-Operator (ROC) Curves

Varying the threshold changes recall/precision.

Area under ROC is a measure of accuracy.

25 of 47

Evaluating Multiclass Systems

Classification gets harder with more classes.

The confusion matrix shows where the mistakes are being made: 5->3, 8->2

26 of 47

Confusion Matrix: Dating Documents

What periods are most often confused with each other?

The main diagonal is not exactly where the heaviest weight always is.

27 of 47

Summary Statistics: Numerical Error

For numerical values, error is a function of the delta between forecast f and observation o:

  • Absolute error: (f - o)
  • Relative error: (f - o) / o (typically better)

These can be aggregated over many tests:

  • Mean or median squared error
  • Root mean squared error

28 of 47

Evaluation Data

The best way to assess models involve out-of-sample predictions, results on data you never saw (or even better did not exist) when you built the model.

Partitioning the input into training (60%), testing (20%) and evaluation (20%) data works only if you never open evaluation data until the end.

29 of 47

Sins in Evaluation

Formal evaluation metrics reduce models to a few summary statistics.

But many problems can be hidden by statistics:

  • Did I mix training and evaluation data?
  • Do I have bugs in my implementation?

Revealing such errors requires understanding the types of errors your model makes.

30 of 47

Building an Evaluation Environment

You need a single-command program to run your model on the evaluation data, and produce plots/reports on its effectiveness.

Input: evaluation data with outcome variables.

Embedded: function coding current model

Output: summary statistics and distributions of predictions on data vs. outcome variables.

31 of 47

Evaluation Environment Architecture

32 of 47

Designing Good Evaluation Systems

  • Produce error distributions in addition to binary outcomes (how close was your prediction, not just right or wrong).
  • Produce a report with multiple plots / distributions automatically, to read carefully.
  • Output relevant summary statistics about performance to quickly gauge quality.

33 of 47

Error Histograms: Dating Documents

Performance of Random vs. Naive Bayes models

34 of 47

Evaluation Environment: Results Table

Stratifying cases by topic and difficulty (length)

35 of 47

The Veil of Ignorance

A joke is not funny the second time because you already know the punchline.

Good performance on data you trained models on is very suspect, because models can easily be overfit.

Out of sample predictions are the key to being honest, if you have enough data/time for them.

36 of 47

Cross-Validation

Often we do not have enough data to separate training and evaluation data.

Train on (k-1)/k th of the data, evaluate on rest, then repeat, and average.

The win here is that you get a variance as to the accuracy of your model!

The limiting case is leave one out validation.

37 of 47

Amplifying Small Evaluation Sets

  • Create Negative Examples: when positive examples are rare, all others are likely negative.
  • Perturb Real Examples: This creates similar but synthetic ones by adding noise.
  • Give Partial Credit: score by how far they are from the boundary, not just which side.

38 of 47

Scoring Hard Problems Easier

Too low a classification rate is discouraging and often misleading with multiple classes.

The top-k success rate gives you credit if the right label would have been one of your first k guesses.

It is important to pick k so that real improvements can be recognized.

39 of 47

Probability Similarity Measures

There are several measures of distance between probability distributions

The KL-Divergence or information gain measures information lost replacing P with Q:

Entropy is a measure of the information in a distribution.

40 of 47

Evaluation Statistics (Projects)

  • Miss Universe?
  • Movie gross?
  • Baby weight?
  • Art auction price?
  • Snow on Christmas?
  • Super Bowl / College Champion?
  • Ghoul Pool?
  • Future Gold / Oil Price?

41 of 47

Blackbox vs. Descriptive Models

Ideally models are descriptive, meaning they explain why they are making their decisions.

Linear regression models are descriptive, because one can see which variables are weighed heaviest.

Neural network models are generally opaque.

Lesson: “Distinguishing cars from trucks.”

42 of 47

Deep Learning Models are Blackbox

Deep learning models for computer vision are highly-effective, but opaque as to how they make decisions.

They can be badly fooled by images which would never confuse human observers.

43 of 47

Correlation Does Not Imply Causation

44 of 47

Levels of Modeling

Interesting problems usually exist on several different levels, each of which require independent submodels.

Predicting the future price for a stock should involve submodels for analyzing (a) the general state of the economy, (b) its balance sheet, (c) the performance of its industrial sector, ...

45 of 47

Hierarchical Decomposition

Imposing a hierarchical structure on the model permits it to be built and evaluated in a logical and transparent way, instead of as a black box.

Often subproblems lend themselves to theory-based, first-principle models, which can then be used as features in a data-driven general model.

46 of 47

Simulation Models

“What I cannot create, I do not understand” (Feynman)

Monte Carlo simulation is the key to modeling systems of discrete events.

Our jai-alai betting system simulated games using

  • Models of player skill
  • Models of scoring system bias
  • Models of bettor preferences

47 of 47

Levels of Modeling (Projects)

  • Miss Universe?
  • Movie gross?
  • Baby weight?
  • Art auction price?
  • Snow on Christmas?
  • Super Bowl / College Champion?
  • Ghoul Pool?
  • Future Gold / Oil Price?