How to avoid the “clean data, clean model” trap when teaching statistics and data science

Parthsarthi Joshi writes:

There is a stark problem that I have observed with how data science is taught in most books and tutorials – the concepts are taught on an individual level but fail to give a complete idea. The so-called “real-world” projects are carefully orchestrated like an “act” already setup by the instructor. The students are not given the taste of the real world – where data is messy, models do not continuously improve, and assumptions are almost always broken. We teach them the concepts of statistics and ML but not the art of data science, which includes curiosity and hit-and-trial experiments.

I am writing a one-of-its-kind book on Data Science that would be completely based on projects. The data will be messy, not everything we do will improve the performance. The aim is to give a feel of uncertainty and challenges that promotes learning from failure and develops an analytical bent of mind.

I agree with Joshi’s concerns, and it’s something that’s bothered me for a long time. Textbooks and research articles are full of examples that work, they’re full of estimates that are a bit more than 2 standard errors from zero, everything’s a bit too clean.

I’ve tried to push against this in my own teaching and writing. Here are some examples:

1. Decision analysis textbooks often use examples that are trivial and artificial (a college student is trying to choose an apartment or dorm room, balancing the factors of cost, amenities, and commute time) or important but vague (a company is deciding where or whether to build a new plant, it’s an interesting problem of decision making under uncertainty but the details are not given). A bit reason I wanted to do the full decision analysis with Phil for the home radon problem was that I wanted a real problem, with real data, going from beginning to end.

2. A few years ago there was a heart-stent study reported in the news. The experiment yielded results that were not statistically significant (the p-value was 0.20) and it was inappropriately reported as a null effect. We looked at the paper carefully, and a more reasonable analysis gave a p-value of 0.09–still not reaching conventional levels of significance. We wrote this up, and it’s a good example where the result is not clean. Again, something you don’t usually see much discussion of in textbooks, applied research papers, or articles on research methods.

3. Our book Active Statistics is full of stories with real-world complexity.

4. Appendix A of Regression and Other Stories, on computing in R, has examples where you have to download and clean the data. One problem with a lot of computer-friendly textbooks is that they’ll have clean data already loaded into packages so you can just click and do the analysis. I like there to be a bit of a struggle, to give a sense of what data analysis really feels like.

We try also to convey a sense of real-world complexity in the worked examples and homework problems in our textbooks.

The flip side of this is that, when you’re using live problems in your teaching, it’s good to come to class prepared! It’s fine to show students the steps of data cleaning and the frustration of messy data and models that don’t fit–but it’s best for you, the teacher, to encounter and resolve those problems on your own first, so that you don’t confuse the students even further. In class it’s good to have a sense of what’s coming next, so that when something doesn’t work, you’re not surprised and you can contextualize it for the students right away.

14 thoughts on “How to avoid the “clean data, clean model” trap when teaching statistics and data science”

  1. A great post by Andrew as always. Especially, his last comment about being prepared when dealing with messy data or other challenges. For our final exam this year, I wanted to come up with a good DPM problem for Poisson data. However, it took me a week to figure it out myself. So, I had to give lots of hints.

  2. I think this all depends on the target audience for the book/course.

    When I taught my children to drive, I did not start them out on commercial streets and freeways. I started them out in the parking lot of a business that was closed at the time. That enabled them to learn the mechanics of controlling the vehicle without being distracted by obstacles, other drivers, pedestrians, etc. Once they had that down, we began driving on streets with low volumes of pedestrians and traffic, and then gradually took on more complex driving situations until they were ready to take the road test.

    I think the same is true for data science. Beginners need to learn the most fundamental procedures for data management and analysis, and that is best learned in clean data. Once they have mastered those, the difficulties faced in practice can be added gradually, and over time they will become able to wrestle with real world data on their own.

    • Of course there are time constraints in a course, too, and the instructor may not get to choose to do both the parking lot and freeway.

      If you knew your child was going to take their learning into the real world imminently, you might get them out into traffic more quickly to ensure they have that experience before you aren’t available at all for guidance.

  3. While Clyde’s point is always good to remember – it always depends on the audience – I think the cases where “first learn on clean data” are few and getting fewer all the time. I always use messy data interspersed with some cleaner examples. My students are generally MBA students although occasionally business undergrads. For these students, I don’t see the point in using cleaned and prepared data. Not only does it emphasize the wrong set of skills, it gives them the incorrect idea that they should expect data to behave like that. AI is quickly making a mockery of using cleaned data. Not only does it make cheating a much bigger problem, but it focuses on exactly what AI can do better than humans, leaving the humans to wonder what role they play. I am also in the process of writing a book (like Joshi) and there are no clean examples. They are all messy. If it is not messy, then it can be automated. It is precisely the cleaning and preparing data that I don’t think AI can do, and that I don’t expect it to do any time soon. Admittedly, I have an extreme view and I admit that there will be some audiences that make a more stepped approach make sense. But I’m not sure what those audiences are, and I don’t find myself in their company.

  4. Andrew wrote, “A bit reason I wanted to do the full decision analysis with Phil for the home radon problem was that I wanted a real problem, with real data, going from beginning to end.”

    Are some words left out? Should it be
    “A bit of the reason I wanted to do the full decision analysis with Phil for the home radon problem was that I wanted a real problem, with real data, going from beginning to end.”

  5. This is really great advice, Andrew, and I’d like to extend it beyond data analysis. In teaching economics, I was always dismayed by the just-so nature of the examples given in textbooks. The skill students most need is not connecting situation A with theory X, but dealing with messy situations that don’t fit perfectly with any particular theory. So, like you suggested, I would give students real world problems to grapple with. “OK, here are the data the Fed had at a particular point in time. Some suggest a rate hike, others a rate cut. What would you have done and why?”

    One way to prepare students for this is to work through messy examples with them first. Model what you’d like them to be able to do.

    • Here is an example. In a textbook I coauthored (for Managerial Economics) I spent a long time looking for a good example of Cournot capacity competition. Virtually every text has such an example, but they are all examples of duopolies not of Cournot competition. They could be modeled that way, but the examples they choose were simply examples of two firms in competition where they pretty much occupy the whole market. After a long time searching, I found the example of Las Vegas casinos. At the time there were two major chains and they had occupancy rates of 90% or above – and each time one added a new hotel, the other did as well. I thought it was a good example of competing on capacity. I’ve not seen another book that bothered to find a pertinent example. I think economists are very sloppy that way, and it reflects a disciplinary inclination to not want to be bothered with the real world getting in the way of theory.

  6. Hadley Wickham observed that messy datasets are like Tolstoy’s unhappy families, they are all messy in their own way.

    Clyde’s point is important that students should have some knowledge already. A feeling for numbers, what could be called numerical nous, is necessary too. Andrew’s advice that you have to be well prepared includes knowing what the data mean and the provenance of the data. That can be a lot of work, going back to original sources, but the web makes it easier than it used to be and it is often entertaining as well as instructive.

    You can find a collection of real examples of varying degrees and types of messiness in my book “Getting (more out of) Graphics” (the data are available in R packages).

  7. I just reread the last paragraph of Andrew’s post and want to comment on it. I can’t argue with the idea of coming to class prepared. But I also think that it is sometimes beneficial for students to see what happens when I am surprised by something and not quite sure what to do about it. Those situations are always uncomfortable in class – and I used to get dinged by students (always the unmotivated ones) who felt that I should have all the answers. But how are students supposed to learn to deal with unforeseen issues that arise when looking at data? Watching a teacher struggle with a problem is uncomfortable, particularly if there is the expectation that they have all the answers. But the reality is that we will all encounter problems that we aren’t sure what to do about, sometimes ending with us having to admit we aren’t sure how to handle an issue. If students never see these things, then we are failing in part. (I wouldn’t advise this to young academics – your teaching evaluations are not likely to react positively)

    • Dale:

      Yeah, it’s a tradeoff. Sometimes students benefit from seeing me come to a problem cold.

      Sometimes the way I do this is I’ll get an email from someone on campus asking for help on their statistical problem, and I’ll say: Sure, but, instead of coming to my office, come to my classroom and you can explain the problem to the students and me, and then we can work together to help in real time.

      I can usually tell from the initial email what the statistical topic is about and how I will be able to link the discussion to whatever we are covering that week in class.

  8. Does anyone know a good case study to teach instrumental variables?

    The paper that is always used to teach this is the sorter of birth IV for returns to education; unfortunately, I have never seen this replicate for any country on which we have recent data.

    My feeling is that teaching IV is mostly about teaching the idea of natural experiment, rather than proper interest in IV

  9. I like this perspective a lot. I think, ideally, students should learn how to work with and clean data prior to taking any kind of modeling/methods course so that they don’t come in thinking that data is always clean and beautiful. I have taught modeling classes for education and psychology PhD students and one of the things I think is essential is having them learn, through working with data, what happens when the model you are using makes unrealistic assumptions.

    For example, in teaching structural equation modeling (SEM) last spring, I focused on the topic of measurement, which is incredibly tricky in these fields. There are so many ways that real world data does not match the simple model structures and estimation techniques that are taught in these classes. So my goal was to teach them how to identify when data is inconsistent with the traditional SEM analytic techniques, how to diagnose, appropriately model, and compare results between the more appropriate and inappropriate models.

    The challenge is that because the modeling is so complicated in and of itself, it can be overwhelming for students to have to deal with that complexity combined with the complexities of real-world data. But I feel like we do a disservice to students by focusing exclusively on the former in most methods courses to the exclusion of the latter.

Leave a Reply

Your email address will not be published. Required fields are marked *