Start free trial
Trending New Genres Authors
EnglishEnglish
EspañolSpanish
简体中文Chinese
繁體中文Chinese (Traditional)
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Searching...
SoBrief
Python Machine Learning Case Studies

Python Machine Learning Case Studies

Five Case Studies for the Data Scientist
Five Python case studies reveal how to turn messy business data into models worth trusting.
by Danish Haroon 2017 221 pages
2.60
5 ratings
Listen
Immersive
V2.3
Amazon Kindle Audible
Try Full Access for 3 Days
Unlock listening & more!
Continue

Key Takeaways

Choose a model only after the business question and data earn it

Begin with the decision. The book’s five case studies follow a practical sequence: define the business problem, inspect the data, choose an analytical approach, and test whether its results are useful. For a Seattle bike-share service, the question was how to understand riders well enough to improve marketing. Its dataset held 236,065 trips, with dates, duration, stations, and limited rider details. Before choosing a model, the analysts checked what the fields meant, how they were distributed, and what relationships seemed plausible.

Look before modeling. Exploratory data analysis, or EDA, means examining data with summaries and visualizations to find patterns, errors, and limitations. Histograms, bar charts, and scatterplots helped expose trip patterns and the skew in trip duration. The larger lesson is that a model cannot rescue a badly framed question or misunderstood data.

Analysis

What's valuable here is the book's insistence that modeling begins with interpretation, not algorithm shopping. This resembles good experimental design: a clear outcome and a defensible measurement plan matter before statistical machinery is chosen. The business question also determines what counts as success. A marketing team needs actionable segments, while an operations team may need reliable demand estimates. The caution is that visual patterns invite confident stories. EDA is excellent for generating hypotheses, but patterns found in the same data should not be treated as confirmed explanations.

Treat missing demographics as evidence, not an inconvenience

Check who is absent. In the bike-share analysis, birth year and gender were available for members but missing for short-term pass holders. A chart initially seemed to show that younger riders were members, supporting a story about millennial loyalty. Once the analysts checked missing values by user type, they discovered that the short-term riders had no demographic records at all. The comparison could not establish who was more loyal or which age group was more likely to buy a membership.

Missingness has structure. A missing field is not always a random gap. It may reflect how information was collected, which people were asked, or which groups chose to provide it. The book’s broader statistical tools, including correlation and group comparisons, are useful only when the groups being compared are meaningfully observed.

Analysis

This episode captures a central problem in applied data work: the people easiest to measure can become mistaken for the whole population. In modern statistical language, missingness may be related to group membership, so simply dropping incomplete records can distort the picture. The analyst should ask who supplied each field, for what purpose, and whether missingness itself predicts the outcome. The case also shows why a plausible marketing narrative is not evidence. A dataset can support audience description without supporting a claim about loyalty or causation.

Let outliers change the question before they change the model

Averages tell different stories. Bike trips had a mean duration of about 1,203 seconds and a median of about 633 seconds. The gap reflected a long right tail: a small number of very long trips pulled the mean upward. Using the interquartile-range rule, the analysis labeled about 9.5% of durations as outliers. The mean among values inside the rule’s bounds was about 712 seconds, showing how strongly extremes affected the original average.

Choose treatment carefully. The book demonstrates replacing long durations with the mean of non-outlier trips, which reduced skew. But it also explains other options, such as removing extreme values or limiting them to a boundary. Each changes the data differently. For time-based records, deleting observations can break continuity, while replacing them can erase genuine unusual behavior.

Analysis

The example usefully turns outlier handling from routine cleanup into a modeling decision. Robust summaries such as the median and interquartile range help describe skew without letting extremes dominate. But a statistical outlier is not automatically a bad observation: a long bike trip might be a recording error, an unusual customer, or a real event the business needs to understand. A sound analysis therefore compares results with and without treatment, then asks which version matches the decision. Blindly clipping values can make a chart calmer while making the system less truthful.

Reject weak regressions even when the fitted line looks persuasive

Fit is not proof. A construction company wanted to predict concrete compressive strength from ingredient measurements. The dataset contained 1,030 mixtures. Simple linear models explained little of the variation, and a reported single-feature gradient boosting model did better for cement, with an R² near 0.34. Water and coarse aggregate models scored about 0.31 and 0.23. The reported multivariable gradient boosting result was much weaker, with an R² near 0.006.

Compare against evidence. The chapter introduces train-test splits, cross-validation, residuals, and metrics such as mean absolute error and R². It also describes Ridge, Lasso, and ElasticNet as ways to constrain coefficients, and grid search as a way to compare parameter settings. The case does not establish that these models can replace strength-testing equipment: the reported predictive scores are too weak to justify that conclusion.

Analysis

The strongest lesson is the distinction between producing a prediction and producing a dependable one. A curved fitted line can look convincing while performing poorly on unseen cases. Regularization and parameter search help manage complexity, but they cannot create signal that the inputs do not contain. In a safety-relevant application such as concrete quality, error costs matter as much as average fit: systematically underestimating strength may be more consequential than a similar-sized overestimate. The reported scores argue for further validation, not for treating a model as a substitute for measurement.

Make a time series stable, then test forecasts on future dates

Separate trend from noise. A time series is a sequence of measurements collected at regular time intervals. The book’s stock example begins with Yahoo price data for 2016, where the training series showed a trend and was judged non-stationary. A stationary series has a relatively stable mean and variance over time, without a changing trend. A log transformation alone did not satisfy the Dickey-Fuller test, but taking first differences of log prices produced a much stronger stationarity result.

Forecast in the original units. The chapter fits ARIMA models, which combine past values, differencing, and past forecast errors. It then reverses the transformations and evaluates a later period. However, a low residual sum of squares or a favorable information criterion on fitted data does not by itself prove future accuracy. The key test is performance on dates withheld from model fitting.

Analysis

The transformation sequence is a useful demonstration of how time-series structure differs from ordinary regression: observations are ordered, and the past can carry information about the next point. Yet stationarity is a modeling condition, not evidence that a market is predictable. Financial prices can change regime, and a model can fit historical movements without offering a durable forecasting advantage. A robust assessment needs a strictly chronological holdout and comparison with a simple baseline, such as carrying forward the latest value. Randomly mixing dates between training and testing would leak future information.

Turn text into features, then make clusters explain themselves

Represent before grouping. To market an AI conference, an analyst examined 398 accepted research papers and wanted a manageable set of topic-based segments. Because clustering algorithms need numerical inputs, he transformed paper group labels into a matrix: each paper became a row, each group a column, and membership was recorded as 1 or 0. This converted text-derived categories into a usable feature representation.

Check both scores and meaning. The analyst compared clustering approaches and used an elbow in within-cluster variation to select nine k-means groups. He then used word clouds of paper keywords to interpret the segments. Gaussian mixture approaches produced three groups that appeared more coherent to him. The book’s practical standard is twofold: clusters should have meaningful statistical separation, and their descriptions should make sense to people who know the domain.

Analysis

The example highlights that an algorithm clusters the representation it receives, not the underlying subject in some objective, representation-free way. Turning group membership into binary columns makes the task possible, but it also gives the chosen labels and distance measure substantial influence over the result. Word clouds help communicate broad themes, though single-word displays can conceal distinctions between phrases such as different kinds of search. Human review is therefore not an optional decoration. It tests whether mathematical groupings correspond to useful categories for the actual campaign.

Use no-show predictions to match clinic capacity to likely demand

Connect predictions to operations. An Ohio clinic case examines 300,000 appointment records after a third of patients appeared not to attend. The analyst inspected distributions, removed six records with negative ages, dropped an ambiguous handicap field, and derived calendar features from appointment dates. Exploratory comparisons suggested that older patients were more likely to attend, longer waits were associated with more missed visits, and SMS reminders were associated with a modest increase in attendance.

Turn estimates into a decision. A no-show classifier could help the clinic anticipate how many patients may arrive and align staffing with expected demand. The chapter compares decision trees, kernel approximation with an SGD classifier, random forests, and gradient boosting. It also emphasizes preparing categorical data and creating training and testing sets. These predictions are intended to inform operational planning, not to establish why any particular patient misses an appointment.

Analysis

This is a strong example of linking a prediction to a concrete organizational choice rather than treating model output as an end in itself. It also invites a careful distinction between prediction and intervention. An association between reminders and attendance does not show that reminders caused the change; patients receiving reminders may differ in other ways. Operational use should also account for uncertainty and avoid treating an individual prediction as a judgment about a patient. At the system level, forecasts can support staffing, while targeted interventions should be evaluated to see whether they actually improve attendance.

Choose classification metrics for the cost of each mistake

Accuracy hides failure modes. The clinic’s default decision tree achieved nearly 100% training accuracy but only about 59% test accuracy, a clear warning of overfitting. Gradient boosting reached about 70% test accuracy, while its reported ROC AUC was about 0.515. The kernel-based SGD model also approached 70% accuracy but had a reported ROC AUC of 0.50. Since roughly two-thirds of appointments were attended, a model predicting attendance for everyone could already look fairly accurate without identifying no-shows well.

Inspect the errors. A confusion matrix separates correct attendance predictions, missed no-shows, and false alarms. ROC curves examine the tradeoff between detecting positive cases and raising false alarms across thresholds. In practice, the threshold should reflect consequences: unnecessary staffing has a cost, but failing to prepare for arriving patients does too. Accuracy alone cannot decide that balance.

Analysis

The case makes a valuable point about metric choice, and the reported scores deserve restraint: a result near 70% accuracy is only a modest improvement over the approximate majority-class baseline. There is also a technical caveat: ROC AUC is most informative when calculated from continuous scores or probabilities, while the chapter’s evaluation code passes predicted class labels. A single threshold discards ranking information. Before deployment, the clinic would need class-specific error rates, calibrated probabilities, and a threshold chosen around real staffing costs, then a prospective check that the model remains useful.

Analysis

This book is best read as a guided tour of the analytical workflow, not as a catalogue of algorithms. Its recurring argument is that machine learning is a chain of decisions: translating a business concern into a measurable target, discovering what the dataset actually records, representing that information appropriately, selecting a model, and evaluating it against evidence. The five cases make that chain concrete across descriptive statistics, regression, forecasting, clustering, and classification.

The book’s most durable contribution is its emphasis on inspection and interpretation. In the bike-share example, missing demographics invalidate an appealing marketing conclusion. In the clinic case, an ambiguous field is removed rather than assigned a convenient meaning. In the conference example, keyword-based clusters are interpreted by people rather than accepted solely because software produced them. These episodes show that data preparation is substantive reasoning, not clerical prelude.

The cases also reveal a gap between demonstrating a technique and validating a dependable product. Some reported regression scores are poor, and the classification results offer only modest improvement over a majority-class guess. The stock example illustrates transformations and ARIMA fitting, but in-sample fit and model criteria are not substitutes for chronological out-of-sample evidence. These limitations do not undermine the instructional value. They sharpen it: successful code execution is not the same as successful decision support.

A modern reader should treat the book’s code as a conceptual starting point, not production guidance. Its examples use Python 2.7 and older library interfaces, and their results depend on particular splits and implementation choices. The lasting value lies in the questions it teaches readers to ask: What is the target? Who is missing? What does the error cost? Does the pattern survive on genuinely unseen data? Those questions travel better than any specific model.

Summary in 30 Seconds
Machine learning starts with a decision and a clear target, not an algorithm. Inspect how data was collected: missing demographics can invalidate comparisons, while outliers can distort averages. Compare models with held-out data, cross-validation, and error measures, since a fitted line or strong training score can mislead. Test forecasts on later dates, interpret clusters with domain knowledge, and weigh classification errors by their real-world costs.
Contains spoilers

Last updated:

Report Issue
Want to read the full book?

Glossary

Exploratory Data Analysis

Initial data inspection

Exploratory Data Analysis, or EDA, is the examination of a dataset through summaries, plots, and comparisons before selecting or fitting a model. It helps reveal distributions, unusual values, missing information, and possible relationships. In the book, EDA guides decisions such as which features to investigate and whether a pattern warrants further testing.

Lurking Variable

Unmeasured influencing factor

A lurking variable is a factor not included among the chosen explanatory or outcome variables that may nevertheless affect how their relationship is interpreted. The book’s example is predicting college admission from gender alone: the department an applicant seeks may also influence admission patterns. Ignoring such a factor can make an association appear more direct than it is.

Central Limit Theorem

Sample means approach normality

The Central Limit Theorem describes how the distribution of sample means tends toward a normal distribution as sample size increases, provided the underlying observations have a well-defined mean and variance. The book illustrates the idea with daily bike-trip counts sampled at increasing sizes. It presents the theorem as a reason sampling can support inference, not as a guarantee that every dataset is normally distributed.

Multicollinearity

Predictors overlap strongly

Multicollinearity occurs when explanatory variables in a regression are strongly related to one another. This overlap can make it difficult to estimate each variable’s independent contribution and can make coefficients unstable. The book discusses examining pairwise correlations and using tolerance as a diagnostic. Ridge regression is presented as one approach for reducing the impact of correlated predictors.

Stationarity

Stable time-series behavior

A stationary time series has statistical properties that remain broadly stable over time. The book describes a series as stationary when it lacks a changing trend and has a relatively constant mean and variance, with autocorrelation also considered. Transformations, detrending, differencing, and decomposition can make a non-stationary series closer to this condition before forecasting.

Dickey-Fuller Test

Test for non-stationarity

The Dickey-Fuller test is a statistical test used in the book to assess whether a time series is stationary. Its null hypothesis treats the series as non-stationary. The test statistic is compared with critical values, and the p-value provides related evidence. The book uses it alongside rolling-mean and rolling-variance plots rather than treating visual inspection as sufficient.

ARIMA

Autoregressive integrated moving average

ARIMA is a time-series forecasting model specified by three parameters: p, d, and q. The p parameter represents autoregressive terms based on past series values, d is the order of differencing, and q represents moving-average terms based on past forecast errors. The book applies ARIMA after transforming and differencing stock-price data, then reverses those changes to interpret forecasts in the original scale.

Silhouette Score

Cluster separation measure

The Silhouette Score compares how close an observation is to others in its assigned cluster with how close it is to the nearest competing cluster. Scores near 1 indicate clearer separation, values around 0 indicate overlapping groups, and negative values suggest possible misassignment. In the book’s conference-paper case, the score rose as more clusters were added, so practical interpretability also shaped the final choice.

Principle Component Analysis

Reduce feature dimensions

Principle Component Analysis, abbreviated PCA in the book, transforms correlated features into a smaller set of orthogonal components. The first component captures the greatest possible variance, and subsequent components capture progressively less while remaining orthogonal to earlier ones. The book uses PCA to project high-dimensional paper-group features into two dimensions so clusters can be visualized.

Receiver Operating Characteristic

Threshold-based classifier assessment

A Receiver Operating Characteristic, or ROC, curve plots the true positive rate against the false positive rate as a classifier’s decision threshold changes. Its area under the curve summarizes how well the model separates two classes across thresholds. The book introduces ROC alongside confusion matrices, which show counts of true positives, true negatives, false positives, and false negatives.

Gradient Boosting

Sequentially improve weak models

Gradient Boosting builds an ensemble of predictive models, commonly decision trees, in sequence. Each new model is fitted to address errors left by the current ensemble, and the combined predictions are intended to improve performance. The book applies gradient boosting to both regression and clinic no-show classification, while emphasizing that the model still requires parameter tuning and validation on unseen data.

Download PDF

To save this Python Machine Learning Case Studies summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.36 MB     Pages: 14

Download EPUB

To read this Python Machine Learning Case Studies summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 1.47 MB     Pages: 19
Want to read the full book?
Follow
Listen
Home
Swipe
Library
Get App
Try Full Access for 3 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
Read unlimited summaries. Free users get 3 per month
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
—
❤️ Unlimited Bookmarks
Free users are limited to 4
—
📜 Unlimited History
Free users are limited to 4
—
📥 Unlimited Downloads
Free users are limited to 1
—
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 26,000+ books. That's 12,000+ hours of audio!
Day 2: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 3: Your subscription begins
You'll be charged on Nov 24,
cancel anytime before.
Consume 2.8× More Books
2.8× more books Listening Reading
Our users love us
1M+ readers
Trustpilot Rating
TrustPilot
4.6 Excellent
This site is a total game-changer. I've been flying through book summaries like never before. Highly, highly recommend.
— Dave G
Worth my money and time, and really well made. I've never seen this quality of summaries on other websites. Very helpful!
— Em
Highly recommended!! Fantastic service. Perfect for those that want a little more than a teaser but not all the intricate details of a full audio book.
— Greg M
Save 62%
Yearly
$119.88 $44.99/year/yr
$3.75/mo
Monthly
$9.99/mo
Start a 3-Day Free Trial
3 days free, then $44.99/year. Cancel anytime.
Unlock a world of fiction & nonfiction books
26,000+ books for the price of 2 books
Read any book in 10 minutes
Discover new books like Tinder
Request any book if it's not summarized
Read more books than anyone you know
#1 app for book lovers
Lifelike & immersive summaries
30-day money-back guarantee
Download summaries in EPUBs or PDFs
Cancel anytime in a few clicks

Why one summary?

Scanner
Find a barcode to scan

⭐
⭐
⭐
We have a special gift for you
Open
38% off
DISCOUNT FOR YOU
⭐
⭐
⭐
$79.99
$49.99/year
Only $4.16 per month
Continue
2 taps to start, super easy to cancel
Settings
General
Widget
Loading...