aNet.ai
Data Science/Lab work
0day streak0XP · Lv 1
← Lab 2 overview and setup
Lab 2 · Section 5 of 8

Boxplots and hidden groups

5A–5D

First · connect to the lecture

The lecture's fences and whiskers become record-level checks. Programme summaries and two equal-mean/SD classes show why the whole shape matters.

Week 2: boxplots and grouped summaries; Week 3 outliers is a later connection

Your task

Calculate a fence, identify a whisker and flagged record, compare programme distributions, then describe the two small classes.

Evidence to include

Cite an ID, minutes, quartiles, a whisker endpoint, and group mean/SD values. Explain a better support plan.

Notebook questions and code

Read here; run in your downloaded notebook. Start with its setup cells and run in order. Use your own ID and outputs where requested.

Download Lab 2 notebook

5 · Boxplots, flags, and hidden groups (15 min)

Box = Q1 to Q3; line = median. Fences = Q1 − 1.5×IQR and Q3 + 1.5×IQR. Whiskers end at the most extreme observed values inside the fences; they are not the fences themselves. Dots are candidates for investigation, not automatic deletion.

Here pandas and the plotting convention use linearly interpolated quartiles. Group summaries use sample SD (ddof=1).

Python · cell 19 — read here, run in your notebook
x = students.weekly_minutes
q1,q3=x.quantile([.25,.75]); iqr=q3-q1
lower,upper=q1-1.5*iqr,q3+1.5*iqr
inside=x[(x>=lower)&(x<=upper)]
flagged=students[(x<lower)|(x>upper)]
display(pd.Series({'Q1':q1,'median':x.median(),'Q3':q3,'IQR':iqr,
    'lower fence':lower,'upper fence':upper,'lower whisker':inside.min(),
    'upper whisker':inside.max(),'flagged count':len(flagged)}))
display(flagged[['record_id','weekly_minutes']].head(6))
fig,axes=plt.subplots(1,2,figsize=(11,4))
axes[0].boxplot(x); axes[0].set(ylabel='Minutes per week',title='Weekly minutes',xticks=[])
axes[1].boxplot([students.loc[students.programme==g,'assessment_score'] for g in ['A','B']])
axes[1].set(xticks=[1,2],xticklabels=['A','B'],ylabel='Score (points)',title='Assessment by programme')
plt.tight_layout(); plt.show()
print('Overall assessment summary:')
display(students.assessment_score.agg(['count','mean','median','std']))
print('Programme summaries:')
display(students.groupby('programme').assessment_score.agg(['count','mean','median','std']))

Your reasoning

5A. Using your Q1/Q3, show one fence calculation. State a whisker endpoint and explain why it differs from the corresponding fence. Describe a flagged record using its ID and minutes.

5B. Propose two checks before changing that record and one reason to retain it. What would you document if it were corrected? Do not delete it simply because it crosses a fence.

5C. Compare the overall assessment mean with both programme means and SDs. Would a single support session at the overall average meet both groups' needs? Give evidence and a better plan. Can these data prove that programme membership caused the difference?

Answer: Replace this text with your explanation.

Same mean and SD, different students

The next two small classes have the same mean and sample SD but different shapes. Values are shifted for your case. Inspect them before answering.

Python · cell 22 — read here, run in your notebook
centre = int(round(small.mean()))
class_a = centre + np.array([-20,0,0,0,0,0,0,20])
class_b = centre + np.array([-10,-10,-10,-10,10,10,10,10])
for name,a in [('Class A',class_a),('Class B',class_b)]:
    print(name, a.tolist(), '| mean:',a.mean(),'| sample SD:',round(a.std(ddof=1),3))

Your reasoning

5D. Sketch or describe each shape. Explain why the same mean and SD can lead to different tutoring plans. What information did the two statistics discard?

Answer: Replace this text with your explanation.

Saved only in this browser. This note doesn’t fill in the downloaded notebook; “reviewed” is a personal checklist, not a grade.

aNet.ai · Data Science Fundamentals · Weeks 1–5 · practice material, not an official examProgress saved in this browser