Fall 2023 Midterm Exam

pdf

School

University of California, San Diego *

*We aren’t endorsed by this school

Course

10

Subject

Statistics

Date

Feb 20, 2024

Type

pdf

Pages

13

Uploaded by BaronJackal4036

Report
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 1/13 living_cost living_cost living_cost "family_type" "2a1c" "1a0c" "1a1c" "1a2c" "1a3c" "1a4c" "2a0c" "2a1c" "2a2c" "2a3c" "2a4c" "state" "county" "family_type" "state" "CA" "county" "San Diego" "family_type" "family_type" "2a1c" "state" "CA" "county" "San Diego" "family_type" "1a2c" "state" "county" "family_type" living_cost "is_metro" bool True False "avg_housing_cost" int
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 2/13 "avg_childcare_cost" int "median_income" int import babypandas as bpd import numpy as np "avg_housing_cost" "family_type" result "avg_childcare_cost" "family_type" "avg_housing_cost" "avg_childcare_cost" "family_type" "avg_housing_cost" "avg_housing_cost" "family_type" "avg_childcare_cost" "avg_housing_cost" "family_type" "avg_childcare_cost" families = living_cost.groupby("family_type").median() sorted_families = families.sort_values(by="avg_housing_cost") result = sorted_families.get("avg_childcare_cost").iloc[0]
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 3/13 another_result another_result living_cost.groupby("family_type").min() living_cost.groupby("family_type").sum() living_cost.groupby("family_type").count() three_columns living_cost three_columns "CA San Diego County 1a2c" living_cost "family_type" 10 50 another_result = (living_cost.groupby("state").count() .sort_values(by="median_income", ascending=False) .get("median_income").index[0]) three_columns = (living_cost.get("state") + " " + living_cost.get("county") + " " + living_cost.get("family_type")) (living_cost.assign(geo_family=three_columns) .groupby("geo_family").count() .shape[0])
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 4/13 "family_type" living_cost "family_size" living_cost 500 3143 31430 J = living_cost.get("county") == "Benton County" K = living_cost.get("state") == "IN" L = living_cost.get("family_type") == "1a2c" __(a)__.__(b)__.iloc[0] __(c)__.__(d)__ / 10
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 5/13 num_people "family_size" "midterm"[0] "m" "midterm"[1] "i" living_cost = living_cost.assign( family_size=living_cost.get("family_type").apply(num_people)) # Option 1 def num_people(fam): return int(fam[0]) + int(fam[2]) ------------------------------------ # Option 2 def num_people(fam): return int(fam[0] + fam[2]) ------------------------------------ # Option 3 def num_people(fam): x = int(fam[0] + fam[2]) return int(x / 10) + x % 10 ------------------------------------ # Option 4 def num_people(fam): x = fam.strip("c").split("a") return int(x[0]) + int(x[1]) ------------------------------------ # Option 5 def num_people(fam): x = 0 for i in fam: if i % 2 == 0: x = x + 1 return x ------------------------------------ # Option 6 def num_people(fam): x = 0 for i in np.arange(len(fam)): if i % 2 == 0: x = x + int(fam[i]) return x
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 6/13 expensive living_cost "avg_childcare_cost" "family_type" "avg_childcare_cost" expensive "family_type" "avg_childcare_cost" "is_metro" living_cost expensive "is_metro" "is_metro" True "state" "is_metro" "is_metro" expensive = living_cost[living_cost.get("avg_childcare_cost") >= 20000] (expensive.groupby(____(a)____).max() .reset_index() .groupby(____(b)____).____(c)____)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 7/13 living_cost "family_type" "1a0c" "median_income" [50, 80) [50, 70) [70, 80) h 1 [50, 70) h 2 [70, 80) h 2 [50, 70) r [70, 80) , h 2 h 1 r 1
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 8/13 living_cost "family_type" state_merge "MT" state_merge("MT", "NV") 1050 "NV" "1a4c" "2a1c" "2a3c" "1a1c" r 2 r 3 2 r 3 r 2 r 3 r 31430 3143 def state_merge(A, B): state_A = living_cost[living_cost.get("state") == A] state_B = living_cost[living_cost.get("state") == B] return state_A.merge(state_B, on="family_type").shape[0]
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 9/13 A B A B A B C D C D Y C D p = 4 1 p 5 1 − p 5 1 − (1 − p ) 5 (1 − p ) 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 10/13 p ⋅ (1 − p ) 4 p (1 − 4 p ) p 5 1 − p 5 1 − (1 − p ) 5 (1 − p ) 5 p ⋅ (1 − p ) 4 p (1 − 4 p ) p 5 1 − p 5 1 − (1 − p ) 5 (1 − p ) 5 p ⋅ (1 − p ) 4 p (1 − 4 p )
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 11/13 "2a3c" "oldest" "middle" "youngest" np.count_nonzero(outcomes == "Outcome Q") / repetitions np.count_nonzero(outcomes == "Outcome R") / repetitions np.count_nonzero(outcomes == "Outcome S") / repetitions replace=True replace=False ages = np.array(["oldest", "middle", "youngest"]) outcomes = np.array([]) repetitions = 10000 for i in np.arange(repetitions): fams = np.random.choice(np.arange(1, 11), 5, ____(a)____) if ____(b)____: children = np.random.choice(ages, 2, ____(c)____) if not "middle" in children: outcomes = np.append(outcomes, ____(d)____) else: outcomes = np.append(outcomes, ____(e)____) else: outcomes = np.append(outcomes, ____(f)____)
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 12/13 replace=True replace=False "Outcome Q" "Outcome R" "Outcome S" "Outcome Q" "Outcome R" "Outcome S" "Outcome Q" "Outcome R" "Outcome S"
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
24. 2. 12. 오전 8:16 Fall 2023 Midterm Exam https://practice.dsc10.com/fa23-midterm/index.html 13/13