1 of 15

CSE 163

Section AX

Week 7

TA 1 & TA 2

STAT

2 of 15

Housekeeping🧹

Important Dates:

  • Programming Practice #5 due today
  • Section Check-In #6 due tomorrow (@ 11:59PM)
    • Resub cycle also closes
  • HW5: Mapping due next Friday, 8/14 @ 11:59PM
  • Project Code & Report due Sunday, 8/16 @ 11:59PM
  • Final Exam is on Friday, 8/21 during lecture
    • Practice exams early next week!

2

3 of 15

Section Plan

🃏🎴

In today’s section, we’ll go over

  • Stats 101
  • Hypothesis testing, p-values, p-hacking
  • Machine learning

3

4 of 15

Statistics 101

4

Examples of Summary Statistics

  • Number of values in our dataset
  • Mean
    • The “average” value
  • Median
    • The value in the middle of our dataset
  • Standard deviation
    • How spread out our values are
  • Min, max, mode, range, etc.

Distributions

  • How our values are distributed
    • Uniform
    • Normal

5 of 15

Hypothesis Tests

Null Hypothesis is the hypothesis that supports the pre-existing expectations or probability

Alternative Hypothesis is the hypothesis that something is different, one that if true, would allow us to reject the null hypothesis

Our p-value is the chance that this situation would happen in a world bound by the null hypothesis

  • If our p-value is lower than a given significance level (usually 0.05), it is significant enough to reject the null hypothesis

6 of 15

P-hacking and HARKing

  • P-hacking: due to the randomness in the experiment, can keep running experiments until we get a decent p-value
  • HARKing: making hypotheses AFTER experimentation

6

7 of 15

ML pipeline for regression tasks

7

# Separate data

features = data.loc[:, data.columns != 'target']

labels = data['target']

# Create and train model

model = DecisionTreeRegressor()

model.fit(features, labels)

# Predict on some data

predictions = model.predict(features)

# Assess accuracy

mean_squared_error(labels, predictions)

  • For tasks whose labels are numeric (e.g. House price prediction)
  • Models: DecisionTreeRegressor(), LinearRegression()

8 of 15

ML pipeline for classification tasks

8

# Separate data

features = data.loc[:, data.columns != 'target']

labels = data['target']

# Create and train model

model = DecisionTreeClassifier()

model.fit(features, labels)

# Predict on some data

predictions = model.predict(features)

# Assess accuracy

accuracy_score(labels, predictions)

  • For tasks whose labels are categorical (e.g. cat vs. dog)
  • Models: DecisionTreeClassifier()

9 of 15

Train-test split

The goal of machine learning is not to memorize the labels of the data we already have, but to learn a model that generalizes to future, unseen data.

  • We need to hold out data our model will never see during training, then test it on that data set (test set)

from sklearn.model_selection import train_test_split

# Breaks data into 80% train and 20% test

X_train, X_test, y_train, y_test =

train_test_split(X, y, test_size=0.2)

10 of 15

Underfitting vs. overfitting

Models won’t always perform well on test data.

Suppose we’re training a classification model…

  • Underfitting occurs when the model is too simple to capture the relationships in the data it’s trained on
    • 68% accuracy on training set, 65% accuracy on test set

  • Overfitting occurs when the model does too good of a job fitting to the specific data it’s trained on (too complex)
    • 98% accuracy on training set, 55% accuracy on test set

We want our models to be somewhere in between the two!

11 of 15

Practice Problems!

11

12 of 15

Project Check In

Discussion Questions:

  • Briefly describe your project or portfolio to your group members. If you’re doing a project, what data and questions are you working with? If you’re doing a portfolio, what work are you revising?
  • What is the current status of your project or portfolio?
  • What was the feedback you got from the TA, and how do you plan to incorporate it into your upcoming work?
  • What is your game plan for the next week?
  • Do you have lingering questions?

After discussing, group members should ask follow-up questions or offer insights!

13 of 15

Section Code:

13

14 of 15

Solutions

14

15 of 15

Solutions

15