Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Question 9 1. Balance the dataset 2. Your code should return the input and output variables seperately. The input variables will be saved as
Python
Question 9 1. Balance the dataset 2. Your code should return the input and output variables seperately. The input variables will be saved as a dataframe named X. The output variable will be saved as a dataframe named y. Hints: Imbalanced data refers to a situation where the number of observations is not the same for all the classes in a dataset. For example, the number of churned employees is 4000, while the number of unchurned employees is 40000. This means this dataset is imbalanced. . You need to access the target variable Attrition and increase the number of ones (i.e., Yeses) so that both the number of zeros (i.e., Noes) and the number of ones (i.e., Yeses) will be equal. Check M5g: Encoding Categorical Variables. balancing dataset discussed in this video. ]: * Your code to balance the dataset goes in here X = # dataframe containing the input variables after balancing y = # dataframe containing the output variable Attrition after balancing Do not alter the below cell. It is a test case for Question 9 ]: try: if ((y.Attrition.value_counts ( [0] == 1233) and (y.Attrition.value_counts() [1] == 1233)): score[ 'question 9'] = 'pass else: score question 9'] = 'fail' except: score['question 9'] = 'fail' score 0 C D E F G H 1 . K 1 EmployeeCount EmployeeNumber EnvironmentSatisfaction Gender Hourly Rate Jobinvo 1 1 2 Female 94 2 3 1 2 3 Male 61 4 1 4 4 4 Male 92 1 5 4 Fernale 56 G 1 7 7 1 Male 40 2 1 8 4 Male 79 a 1 10 3 Fernale 81 9 1 11 4 Male 67 10 1 12 4 Male 44 11 1 13 3 Male 94 12 1 14 1 Male 84 13 Age Attrition Business Travel DailyRate Department DistanceFromHome Education Education Field 41 Yes Travel_Parely 1102 Sales 1 2 Life Sciences 2 49 No Travel_Frequently 279 Research & Development B 1 Life Sciences 37 Yes Travel_Rarely 1373 Research & Development 2 2 2 Other 33 No Travel_Frequently 1392 Research & Development 3 4 Life Sciences 27 No Travel_Rarely 591 Research & Development 2 1 Medical 32 No Travel_Frequently 1005 Research & Development 2 2 Life Sciences 59 No Travel_Rarely 1324 Research & Development 3 3 Medical 30 No Travel_Rarely 1358 Research & Development 24 1 Life Sciences 38 No Travel Frequently 216 Research & Development 23 3 Life Sciences 36 No Travel_Rarely 1299 Research & Development 27 3 Medical 35 No Travel Rarely 809 Research & Development 16 3 Medical 29 No Travel Rarely 153 Research & Development 15 2 Life Sciences 31 No Travel Rarely 670 Research & Development 26 1 Life Sciences 1 34 No Travel Rarely 1346 Research & Development 19 2 Medical 28 Yes Travel Rarely 103 Research & Development 24 3 Life Sciences 29 No Travel Rarely 1389 Research & Development 21 4 Life Sciences 32 No Travel_Parely 334 Research & Development 5 2 Life Sciences 22 No Non-Travel 1123 Research & Development 16 2 Medical 53 No Travel_Rarely 1219 Sales 2 4 Life Sciences 38 No Travel_Rarely 371 Research & Development 2 3 Life Sciences 24 No Non-Travel 673 Research & Development 11 2 Other 36 Yes Travel_Rarely 1218 Sales 9 4 Life Sciences 34 No Travel_Rarely 419 Research & Development 7 4 Life Sciences 21 No Travel_Rarely 391 Research & Development 15 2 Life Sciences 1 15 4 Female 49 14 1 16 1 Male 31 15 1 18 2 Male 93 16 1 19 3 Male 50 17 1 20 2 Female 51 1a 1 21 1 Male 80 19 1 22 4 Male 96 1 23 1 Female 78 21 1 1 24 4 Male 45 22 1 25 1 Female 96 1 27 3 Male B2 1 23 1 Female 53 25 1 30 3 Male 96 N P 1 2 JobInvolvement JobLevel JobRole 3 2 Sales Executive 2 2 Research Scientist 2 1 Laboratory Technician 3 4 R S U V Y JobSatisfaction Marital Status MonthlyIncome Monthly Rate NumCompanies Worked Over18 Overtime PercentSalaryHike PerformanceRating Relat 4 Single 5993 19479 Yes 11 3 2 Married 5130 24907 1 Y No 23 4 3 Single 2090 2396 6 Y Yes 15 3 3 Married 2909 23159 1 Y Yes 11 3 2 Married 3468 16632 9 Y No 12 3 4 Single 3068 11864 0 Y No 13 3 1 Married 2670 9964 4 Y Yes 20 4 5 3 1 Research Scientist 6 3 7 3 1 Laboratory Technician 1 Laboratory Technician 1 Laboratory Technician 1 Laboratory Technician 8 4 4 9 9 3 3 Divorced 2693 13335 1 Y No 22 4 10 2 3 Single 9526 8787 0 Y No 21 4 11 3 3 Married 5237 16577 6 Y No 13 3 12 4 2 Married 2426 16479 0 Y No 13 3 13 2 3 Single 4193 12682 O Y Yes 12 3 14 3 3 Divorced 2911 15170 1 Y No 17 3 15 3 4 Divorced 2661 8758 O Y No 11 3 16 2 2028 12947 5 Y Yes 14 3 3 Single 1 Divorced 17 3 Manufacturing Director 2 Healthcare Representative 1 Laboratory Technician 2 Laboratory Technician 1 Research Scientist 1 Laboratory Technician 1 Laboratory Technician 3 Manufacturing Director 1 Research Scientist 1 Laboratory Technician 4 Manager 1 Research Scientist 2 Manufacturing Director 1 Sales Representative 3 Research Director 4 9980 10195 1 Y No 11 3 18 4 2 Divorced 3298 15053 0 Y Yes 12 3 19 4 4 Divorced 2935 7324 1 Y Yes 13 3 20 2 4 Married 15427 22021 2 Y No 16 3 3 21 3 4 Single 3944 4306 5 Y Yes 11 3 22 4 3 Divorced 4011 8232 0 Y No 18 3 23 2 1 Single 3407 6986 7 Y No 23 4 24 3 2 Single 11994 21293 0 Y No 11 3 25 3 4 Single 1232 19281 1 Y No 14 3 1 Research Scientist 1 Research Scientist 26 3 1 Single 2960 17102 2 Y No 11 3 27 3 5 Manager 3 Divorced 19094 10735 4 Y No 11 3 28 1 1 Research Scientist 1 Single 3919 4681 1 Y Yes 22 4 o A 4 AF 1 2 AA AD AF AH AI RelationshipSatisfaction StandardHours StockOptionLevel TotalWorking Years Training Times Last Year WorkLifeBalance Years At Company WorkLifeBalance Years AtCompany YearsinCurrent Role YearsSinceLastPromotion YearsWithCurrManager 1 80 0 0 1 8 4 0 5 4 80 1 10 3 3 10 7 1 7 4 2 80 0 7 3 3 0 0 O 0 5 3 80 0 8 3 3 3 7 3 0 6 4 80 1 6 3 3 2 2 2 2 7 3 80 0 8 2 2 2 7 7 3 6 8 1 80 3 12 3 2 1 0 0 0 9 2 80 1 1 2 3 1 0 0 0 1D 2 80 0 10 2 3 9 7 1 8 11 2 80 2 2 17 3 2 7 7 7 7 12 3 80 1 6 6 5 3 5 4 0 3 13 4 80 10 3 3 5 0 8 14 4 80 1 5 1 1 2 5 2 4 3 15 3 80 1 3 2 3 2 2 1 2 16 2 80 0 6 4 3 4 2 0 3 17 3 80 1 10 1 3 10 9 8 8 18 4 80 2 7 5 2 6 2 O 5 19 2 80 2 1 2 1 0 0 0 2 3 3 20 3 3 80 0 31 3 25 8 3 3 7 21 3 80 0 6 6 3 3 3 2 1 2 22 4 80 1 5 5 2 4 2 1 3 23 2 80 0 4 4 3 5 3 0 3 10 113 3 80 0 4 3 12 6 2 11 25 4 80 0 0 0 6 3 0 0 0 0 20 3 80 0 8 2 3 4 2 1 3 27 4 80 1 26 3 2 14 13 4 8 28 2 80 0 10 5 3 10 2 6 7Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started