0
0
Data Analysis Pythondata~20 mins

Scatter plots with regression (regplot) in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Regression Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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()
AA scatter plot with points roughly increasing and a regression line fitting the points upward
BA scatter plot with points randomly scattered and a flat horizontal regression line
CA bar chart showing counts of x values
DA line plot connecting the points without any regression line
Attempts:
2 left
💡 Hint
Think about what regplot does: it shows points and fits a regression line.
data_output
intermediate
1: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)
A10
B11
C9
D0
Attempts:
2 left
💡 Hint
Count the number of rows in the data.
🔧 Debug
advanced
2: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)
ATypeError because data is not numeric
BValueError due to NaN values in x
CNo error, plot shows ignoring NaN
DKeyError because 'x' column is missing
Attempts:
2 left
💡 Hint
Think about how regression handles missing values.
visualization
advanced
2: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()
Aorder=1 shows a curved line; order=2 shows a straight line
Border=1 shows a straight line; order=2 shows a curved parabola fitting the data better
CBoth plots show identical straight lines
Dorder=2 plot raises an error because order must be 1
Attempts:
2 left
💡 Hint
Order controls polynomial degree of regression line.
🚀 Application
expert
2: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()
AApproximately -1
BApproximately 1
CApproximately 0.5
DApproximately 2
Attempts:
2 left
💡 Hint
Look at how y changes when x increases by 1.