lists of lists & hypothesis testingcs.brown.edu/courses/csci0931/2012/lectures/lec3-2.pdf ·...

26
Lists of Lists & Hypothesis Testing April 5, 2012 CS0931 - Intro. to Comp. for the Humanities and Social Sciences 1

Upload: others

Post on 27-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Lists of Lists & Hypothesis Testing

April 5, 2012

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 1

Page 2: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Determining Authorship

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 2

Define Problem

Find Data

Write a set of instructions

Python

Solution

Discern the Outlier: The one book that is NOT in the series of

the others. 1 Book from Alice in Wonderland 5 Books from Wizard of Oz

Page 3: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Table Representations

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 3

Excel

Rows: Indexed by 1,2,3 Cols: Indexed by A,B

Cell B4 contains 4

Page 4: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Table Representations

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 4

Excel

Rows: Indexed by 1,2,3 Cols: Indexed by A,B

Cell B4 contains 4

Python

myList = [[1,2],[3,4],[5,6]]

Rows: Indexed by ? Cols: Indexed by ?

How do you

index to get 4?

Page 5: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Table Representations

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 5

Excel

Rows: Indexed by 1,2,3 Cols: Indexed by A,B

Cell B4 contains 4

Python

myList = [[1,2],[3,4],[5,6]]

Rows: Indexed by 0,1,2 Cols: Indexed by 0,1

How do you

index to get 4? myList[1][1]

Page 6: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Activity 3-1

• Task 1: build a list of lists

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 6

[[0,1,2],[1,2,3],[2,3,4],[3,4,5],[4,5,6]]

Page 7: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Activity 3-1

• Task 1: build a list of lists

• Task 2: Write list of lists to a CSV file

– Separate columns by commas

– Separate rows by newlines (‘\n’)

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 7

[[0,1,2],[1,2,3],[2,3,4],[3,4,5],[4,5,6]]

Page 8: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Break

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 8

PerpetualOcean

Page 9: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Determining Authorship

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 9

Define Problem

Find Data

Write a set of instructions

Python

Solution

Discern the Outlier: The one book that is NOT in the series of

the others. 1 Book from Alice in Wonderland 5 Books from Wizard of Oz

Page 10: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Determining Authorship

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 10

File Title Series Author

file1.txt

file2.txt

file3.txt

file4.txt

file5.txt

file6.txt

Page 11: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Determining Authorship

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 11

File Title Series Author

file1.txt Wonder Wizard of Oz Oz

file2.txt Alice’s Adventures in Wonderland

Alice in Wonderland

file3.txt Dorothy and the Wizard in Oz Oz

file4.txt Emerald City of Oz Oz

file5.txt Royal Book of Oz Oz

file6.txt Glinda of Oz Oz

Page 12: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

The Wizard of OZ

• About 40 Books, written by 7 different authors

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 12

Lyman Frank Baum (1856-1919)

Ruth Plumly Thompson

http://www.ssc.wisc.edu/~zzeng/soc357/OZ.pdf

#1 #14 #15 #16 #33

… …

Published in 1921

Page 13: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Determining Authorship

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 13

File Title Series Author

file1.txt Wonder Wizard of Oz Oz Lyman Frank Baum

file2.txt Alice’s Adventures in Wonderland

Alice in Wonderland

Lewis Carroll

file3.txt Dorothy and the Wizard in Oz Oz Lyman Frank Baum

file4.txt Emerald City of Oz Oz Lyman Frank Baum

file5.txt Royal Book of Oz Oz Ruth Plumly Thompson

file6.txt Glinda of Oz Oz Lyman Frank Baum

Page 14: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Determining Authorship

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 14

Are these values surprising?

Page 15: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

I flip a coin 25 times.

• I get 12 heads. Is this surprising?

• What if I get 3 heads?

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 15

Page 16: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

I flip a coin 25 times.

• I get 12 heads. Is this surprising?

• What if I get 3 heads?

My Hypothesis: This coin is unfair.

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 16

Page 17: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

I flip a coin 25 times.

• I get 12 heads. Is this surprising?

• What if I get 3 heads?

My Hypothesis: This coin is unfair.

How do I prove this?

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 17

Page 18: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

• What if this penny was a person?

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 18

?

Page 19: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

• What if this penny was a person?

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 19

?

Innocent until proven guilty

Page 20: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

My Hypothesis:

• This coin is unfair.

The “Innocent” Hypothesis:

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 20

Page 21: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

My Hypothesis:

• This coin is unfair.

The “Innocent” Hypothesis:

• The coin is heads with probability 0.5

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 21

Page 22: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Coin Flipping

My Hypothesis:

• This coin is unfair.

The “Innocent” Hypothesis:

• The coin is heads with probability 0.5

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 22

Null hypothesis

Alternate hypothesis

Page 23: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Hypothesis Testing

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 23

Null hypothesis: The coin is heads

with prob. 0.5

Alternate hypothesis: The

coin is unfair.

• We want to reject the null hypothesis by showing that it is unlikely to get only 3 heads with a fair coin.

Page 24: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Hypothesis Testing

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 24

Null hypothesis: The coin is heads

with prob. 0.5

Alternate hypothesis: The

coin is unfair.

• We want to reject the null hypothesis by showing that it is unlikely to get only 3 heads with a fair coin.

Prove that the coin is NOT innocent.

Page 25: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Hypothesis Testing

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 25

Null hypothesis: The coin is heads

with prob. 0.5

Alternate hypothesis: The

coin is unfair.

• We want to reject the null hypothesis by showing that it is unlikely to get only 3 heads with a fair coin.

• Open coinflip.xls

Prove that the coin is NOT innocent.

Page 26: Lists of Lists & Hypothesis Testingcs.brown.edu/courses/csci0931/2012/lectures/LEC3-2.pdf · file1.txt Wonder Wizard of Oz Oz file2.txt Alice’s Adventures in Wonderland Alice in

Project 2 Notes

• Feedback over the weekend

– Not going to be as in-depth as the first project

CS0931 - Intro. to Comp. for the Humanities and Social Sciences 26

Sun Mon Tues Wed Thurs Fri Sat

4/1 4/2 4/3 4/4 4/5 4/6 4/7

Proposal Due

4/8 4/9 4/10 4/11 4/12 4/13 4/14

Project 2 Due (Code)

4/15 4/16 4/17 4/18 4/19 4/20 4/21

Project 2 Due (Website)