Summary statistics and visualizations
Databricks Machine Learning Associate · Lesson 8 of 19 · 1:04:43
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Databricks Certified Machine Learning Associate exam. In this lesson: describe and summary in Spark, data summaries in notebooks, charts for one feature (histograms, box plots, and bar charts), and comparing two features with scatter plots and correlation. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Trips that last a day
Before modeling demand, Juniper Rides must understand its ride data: forty million trips, with durations, distances, battery levels, cities, and vehicle types. A data scientist explored a small sample in a spreadsheet, and missed that a few trips last more than a day. This lesson covers summary statistics on Spark DataFrames, the right chart for each kind of feature, and how to compare two features.
Describe and summary
A Spark DataFrame computes its own statistics, on all the data, in parallel. describe returns the count, the mean, the standard deviation, the minimum, and the maximum of each column. summary adds the twenty fifth, fiftieth, and seventy fifth percentiles, and you can pass only the statistics you need, like the count, the minimum, or any percentile. These percentiles are approximate, which keeps them fast on large data. And the mean next to the median shows skew: when the mean is far above the median, a few very large values pull it up.
Data summaries
In a notebook, dbutils dot data dot summarize computes and displays summary statistics of a Spark or a pandas DataFrame, with a chart for each column. Numeric columns get statistics like the count, the missing values, the mean, the standard deviation, the minimum, the median, and the maximum, with a histogram, and categorical columns get their distinct values and their most frequent values. By default, precise is false, so some statistics are approximations, like the number of distinct values and the percentiles, which keeps the run time short. Setting precise to true makes them more exact, for a longer run. And the command reads the whole DataFrame, so it can be very expensive on large data.
Charts for one feature
To look at one feature, choose the chart from its type. A continuous feature, like trip duration, fits a histogram, which shows the shape of the distribution and its skew, and a box plot, which shows the median, the quartiles, and the outliers beyond the whiskers. A categorical feature, like the city or the vehicle type, fits a bar chart of the count of each category, which also reveals rare categories. Notebook results offer these charts directly, from the visualization editor of a displayed result.
Comparing two features
To compare two continuous features, like distance and duration, a scatter plot shows their relationship, and the correlation measures it with one number. In Spark, the corr method of a DataFrame's statistics returns the Pearson correlation of two columns, from minus one to one, and the Correlation class of Spark ML computes a matrix, with Pearson or Spearman. Pearson measures a linear relationship, while Spearman, based on ranks, also catches a monotonic one, and resists outliers better. To compare two categorical features, like the city and the vehicle type, crosstab builds a contingency table of counts, which a stacked bar chart or a heatmap can show. A chi squared test then checks whether the two are independent, and Spark ML offers it as ChiSquareTest. And to compare a continuous feature across categories, like durations per city, box plots side by side work best.
Recap
Let's recap. describe gives the count, mean, standard deviation, minimum, and maximum, and summary adds approximate percentiles, and takes the statistics you choose. dbutils dot data dot summarize shows statistics and charts for each column, approximate by default, and more exact with precise set to true, at a higher cost. A continuous feature fits a histogram or a box plot, and a categorical feature fits a bar chart of counts. Two continuous features compare with a scatter plot and a correlation, Pearson for linear and Spearman for ranks. And two categorical features compare with a crosstab and a chi squared test.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
A data scientist needs the 10th and 90th percentiles of trip duration from a Spark DataFrame, with the count. Which call fits?
- describe("duration_min")
- count() on the DataFrame
- summary("count", "10%", "90%")
- display() on the DataFrame
Show the answer
summary("count", "10%", "90%")
Summary accepts the statistics to compute, including any percentile, like ten and ninety percent. “describe("duration_min")” returns the count, mean, standard deviation, minimum, and maximum, but no percentiles. “count() on the DataFrame” returns only the number of rows. And “display() on the DataFrame” shows rows of data, and computes no statistics.
The team wants to see whether the battery level at unlock, a continuous column, is skewed, and where most of its values lie. Which chart fits best?
- A histogram of the battery level
- A bar chart of ride counts per city
- A pie chart of the vehicle types
- A line chart across the rider IDs
Show the answer
A histogram of the battery level
A histogram shows the distribution of a continuous feature, with its skew and where most values fall. “A bar chart of ride counts per city” counts the rides of each city, a categorical feature, and says nothing about battery levels. “A pie chart of the vehicle types” shows the shares of a categorical feature. And “A line chart across the rider IDs” would draw a line across rider IDs, which have no order that means anything.
A data scientist wants to know whether the payment method and the city are related, across millions of rides. Both columns are categorical. Which method fits?
- The Pearson correlation of the two columns
- A scatter plot of the two columns
- summary() on each of the two columns
- A crosstab, then a chi squared test
Show the answer
A crosstab, then a chi squared test
A contingency table counts each pair of categories, and the chi squared test checks whether the two columns are independent. “The Pearson correlation of the two columns” measures a linear relationship between numbers, not between categories. “A scatter plot of the two columns” would scatter category labels, which shows no relationship. And “summary() on each of the two columns” describes each column alone, and never compares them.