Path: blob/main/lectures/lec28/lec28-solutions.ipynb
3058 views
Lecture 28 β Review, Conclusion
DSC 10, Fall 2022
Announcements
The Final Exam is tomorrow from 11:30am to 2:30pm in Center Hall.
See this post on EdStem for details.
Come to WLH 2205 from 5-9pm tonight for the last study session/group office hours. See the calendar for today's other office hours.
If at least 80% of the class fills out both CAPEs and the End of Quarter Survey, then we will add 0.5% of extra credit to everyone's overall grade.
The deadline is tomorrow at 8am!
As of earlier today, we're at 67% on CAPEs and 51% on the End of Quarter Survey.
Agenda
More review.
Working on personal projects.
Demo: Gapminder π.
Some parting thoughts.
Bakeries π§
Let's pick up where we left off last lecture.
Concept Check β β Answer at cc.dsc10.com
Using a single sample of 200 bakeries, how can we estimate the median inspection score of all bakeries in San Francisco with an inspection score? What technique should we use?
A. Standard hypothesis testing
B. Permutation testing
C. Bootstrapping
D. The Central Limit Theorem
Click for the answer after you've entered your guess above. Don't scroll any further.
Bootstrapping. The CLT only applies to sample means (and sums), not to any other statistics.
There is no CLT for sample medians, so instead we'll have to resort to bootstrapping to estimate the distribution of the sample median.
Recall, bootstrapping is the act of sampling from the original sample, with replacement. This is also called resampling.
Let's resample repeatedly.
Note that this distribution is not at all normal.
To compute a 95% confidence interval, we take the middle 95% of the bootstrapped medians.
Discussion Question
Which of the following interpretations of this confidence interval are valid?
95% of SF bakeries have an inspection score between 85 and 88.
95% of the resamples have a median inspection score between 85 and 88.
There is a 95% chance that our sample has a median inspection score between 85 and 88.
There is a 95% chance that the median inspection score of all SF bakeries is between 85 and 88.
If we had taken 100 samples from the same population, about 95 of these samples would have a median inspection score between 85 and 88.
If we had taken 100 samples from the same population, about 95 of the confidence intervals created would contain the median inspection score of all SF bakeries.
Click for the answer after you've entered your guess above. Don't scroll any further.
The correct answers are Option 2 and Option 6.
Physicians π©Ί
The setup
You work as a family physician. You collect data and you find that in 6354 patients, 3115 were children and 3239 were adults.
You want to test the following hypotheses:
Null Hypothesis: Family physicians see an equal number of children and adults.
Alternative Hypothesis: Family physicians see more adults than they see children.
Concept Check β β Answer at cc.dsc10.com
Which test statistic(s) could be used for this hypothesis test? Which values of the test statistic point towards the alternative?
A. Proportion of children seen B. Number of children seen C. Number of children minus number of adults seen D. Absolute value of number of children minus number of adults seen
There may be multiple correct answers; choose one.
Click for the answer after you've entered your guess above. Don't scroll any further.
All of these but the last one would work for this alternative. Small values of these statistics would favor the alternative.
If the alternative was instead "Family physicians see a different number of children and adults", the last option would work while the first three wouldn't.
Let's use option B, the number of children seen, as a test statistic. Small values of this statistic favor the alternative hypothesis.
How do we generate a single value of the test statistic?
As usual, let's simulate the test statistic many, many times.
Recall that you collected data and found that in 6354 patients, 3115 were children and 3239 were adults.
<=Concept Check β β Answer at cc.dsc10.com
What do we do, assuming that we're using a 5% p-value cutoff?
A. Reject the null
B. Fail to reject the null
C. It depends
Note that while we used np.random.multinomial to simulate the test statistic, we could have used np.random.choice, too:
Concept Check β β Answer at cc.dsc10.com
Is this an example of bootstrapping?
A. Yes, because we are sampling with replacement.
B. No, this is not bootstrapping.
Personal projects
Using Jupyter Notebooks after DSC 10
You may be interested in working on data science projects of your own.
In this video, we show you how to make blank notebooks and upload datasets of your own to DataHub.
Depending on the classes you're in, you may not have access to DataHub. Eventually, you'll want to install Jupyter Notebooks on your computer.
Anaconda is a great way to do that, as it also installs many commonly used packages.
You may want to download your work from DataHub so you can refer to it after the course ends.
Remember, all
babypandascode is regularpandascode, too!
Finding data
These sites allow you to search for datasets (in CSV format) from a variety of different domains. Some may require you to sign up for an account; these are generally reputable sources.
Note that all of these links are also available at rampure.org/find-datasets.
Wikipedia. (Use this site to extract and download tables as CSVs.)
Domain-specific sources of data
Sports: Basketball Reference, Baseball Reference, etc.
US Government Sources: census.gov, data.gov, data.ca.gov, data.sfgov.org, FBIβs Crime Data Explorer, Centers for Disease Control and Prevention.
Global Development: data.worldbank.org, databank.worldbank.org, WHO.
Transportation: New York Taxi trips, Bureau of Transportation Statistics, SFO Air Traffic Statistics.
Music: Spotify Charts.
COVID: Johns Hopkins.
Any Google Forms survey youβve administered! (Go to the results spreadsheet, then go to βFile > Download > Comma-separated valuesβ.)
Tip: if a site only allows you to download a file as an Excel file, not a CSV file, you can download it, open it in a spreadsheet viewer (Excel, Numbers, Google Sheets), and export it to a CSV.
Join a DS3 Project Group π€
The Data Science Student Societyβs Projects Committee has opened its applications for the Winter 2023 cohort!
Students have the opportunity to join a team to pursue a unique data science project that will last two quarters.
At the end of the project, teams will have developed a polished, complete personal project which they will showcase to their peers, faculty, and companies in the data science industry.
If you don't have a lot of experience and are looking for that first data science project to get you started or if you're looking to build on your existing portfolio with a new experience, the Projects committee is a great platform.
Apply here by Sunday at 11:59pm (ignore the deadline on the form). Contact [email protected] with questions.
Demo: Gapminder π
plotly
All of the visualizations (scatter plots, histograms, etc.) in this course were created using a library called
matplotlib.This library was called under-the-hood everytime we wrote
df.plot.
plotlyis a different visualization library that allows us to create interactive visualizations.You may learn about it in a future course, but we'll briefly show you some cool visualizations you can make with it.
Gapminder dataset
Gapminder Foundation is a non-profit venture registered in Stockholm, Sweden, that promotes sustainable global development and achievement of the United Nations Millennium Development Goals by increased use and understanding of statistics and other information about social, economic and environmental development at local, national and global levels. - Gapminder Wikipedia
The dataset contains information for each country for several different years.
Let's start by just looking at 2007 data (the most recent year in the dataset).
Scatter plot
We can plot life expectancy vs. GDP per capita. If you hover over a point, you will see the name of the country.
In future courses, you'll learn about transformations. Here, we'll apply a log transformation to the x-axis to make the plot look a little more linear.
Animated scatter plot
We can take things one step further.
Watch this video if you want to see an even-more-animated version of this plot.
Animated histogram
Choropleth
Parting thoughts
From Lecture 1: What is "data science"?
Data science is about drawing useful conclusions from data using computation. Throughout the quarter, we touched on several aspects of data science:
In the first 4 weeks, we used Python to explore data.
Lots of visualization ππ and "data manipulation", using industry-standard tools.
In the next 4 weeks, we used data to infer about a population, given just a sample.
Rely heavily on simulation, rather than formulas.
In the last 2 weeks, we used data from the past to predict what may happen in the future.
A taste of machine learning π€.
In future courses β including DSC 20 and 40A, which you may be taking next quarter β you'll revisit all three of these aspects of data science.
Note on grades
Suraj's freshman year transcript.Don't let your grades define you, they don't tell the full story.
Procrastination
Adjusting to life in college can be challenging, particularly because it can be hard to manage your time wisely.

If you're interested, register to attend this workshop on overcoming procrastination taught by another data science professor next quarter β participants each receive a $50 Amazon gift card!
Thank you!
This course would not have been possible without...
Our graduate TA: Dasha Veraksa.
Our 20 undergraduate tutors: Gabriel Cha, Eric Chen, John Driscoll, Daphne Fabella, Charisse Hao, Dylan Lee, Daniel Li, Anthony Li, Anna Liu, Anastasiya Markova, Yash Potdar, Harshita Saha, Selim Shaalan, Yutian (Skylar) Shi, Tony Ta, Vineet Tallavajhala, Andrew Tan, Jiaxin Ye, Tiffany Yu, and Diego Zavalza.
Learn more about tutoring β it's fun, and you can be a tutor as early as your 3rd quarter at UCSD!
Keep in touch! dsc10.com/staff
After grades are released, we'll make a post on EdStem where you can ask course staff for advice on courses and UCSD more generally.