Challenge - 5 Problems
Regression Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple regplot
What will be the output of this code snippet that uses seaborn's regplot to plot data points and a regression line?
Data Analysis Python
import seaborn as sns import matplotlib.pyplot as plt import pandas as pd data = pd.DataFrame({'x': [1, 2, 3, 4, 5], 'y': [2, 4, 5, 4, 5]}) sns.regplot(x='x', y='y', data=data) plt.show()
Attempts:
2 left
💡 Hint
Think about what regplot does: it shows points and fits a regression line.
✗ Incorrect
Seaborn's regplot plots scatter points and fits a linear regression line through them. Since y generally increases with x, the line slopes upward.
❓ data_output
intermediate1:30remaining
Number of points plotted by regplot
Given this dataset and regplot code, how many points will be shown on the scatter plot?
Data Analysis Python
import seaborn as sns import pandas as pd data = pd.DataFrame({'x': range(10), 'y': [i**2 for i in range(10)]}) sns.regplot(x='x', y='y', data=data)
Attempts:
2 left
💡 Hint
Count the number of rows in the data.
✗ Incorrect
The data has 10 rows, so regplot will plot 10 points.
🔧 Debug
advanced2:00remaining
Error when using regplot with missing data
What error will this code raise when running regplot with missing values in the data?
Data Analysis Python
import seaborn as sns import pandas as pd import numpy as np data = pd.DataFrame({'x': [1, 2, np.nan, 4], 'y': [2, 3, 4, 5]}) sns.regplot(x='x', y='y', data=data)
Attempts:
2 left
💡 Hint
Think about how regression handles missing values.
✗ Incorrect
Seaborn's regplot automatically drops rows with NaN values in the x or y columns before fitting the regression. No error is raised; it plots the remaining 3 points.
❓ visualization
advanced2:30remaining
Effect of changing order parameter in regplot
What is the visual difference when using order=2 in regplot compared to the default order=1?
Data Analysis Python
import seaborn as sns import matplotlib.pyplot as plt import pandas as pd data = pd.DataFrame({'x': range(6), 'y': [1, 4, 9, 16, 25, 36]}) plt.subplot(1,2,1) sns.regplot(x='x', y='y', data=data, order=1) plt.title('order=1') plt.subplot(1,2,2) sns.regplot(x='x', y='y', data=data, order=2) plt.title('order=2') plt.tight_layout() plt.show()
Attempts:
2 left
💡 Hint
Order controls polynomial degree of regression line.
✗ Incorrect
order=1 fits a linear regression line; order=2 fits a quadratic curve, which better fits the squared y values.
🚀 Application
expert2:30remaining
Interpreting regression line slope from regplot
Given this code plotting a regression line, what is the approximate slope of the regression line?
Data Analysis Python
import seaborn as sns import pandas as pd import matplotlib.pyplot as plt data = pd.DataFrame({'x': [0, 1, 2, 3, 4], 'y': [1, 3, 5, 7, 9]}) sns.regplot(x='x', y='y', data=data) plt.show()
Attempts:
2 left
💡 Hint
Look at how y changes when x increases by 1.
✗ Incorrect
y increases by 2 for every increase of 1 in x, so slope is about 2.