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 is 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 {'question 1': 'pass', 'question 2': 'pass', 'question 3': 'pass', 'question 4': 'pass', 'question 5': 'pass', 'question 6': 'pass', 'question 7': 'pass', 'question 8': 'pass', 'question 9': 'pass'}
Added by Madeline T.
Close
Step 1
Balance the dataset Show more…
Show all steps
Your feedback will help us improve your experience
Supreeta N and 52 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Problem 1 - Using R-studio Consider the data set OJ from the ISLR package. a) Set up a seed. Set up a training and testing set. The test set should have 800 observations. Use the table command on the test set Purchase variable to document your work. Then document the factor levels of purchase. b) Fit a tree to the training data with Purchase as the response variable. How many terminal nodes does the tree have? Document with the summary commands. Compute and document the test error rate using the testing set. Plot the tree. c) Use the cv.tree command on the training set to determine the optimal tree size. d) Plot the tree size versus the cross-validated error rate. e) Choose a tree size based on the cross-validated error rate. If the cross-validated error rate does not result in a pruned tree, choose 5 terminal nodes. Produce a pruned tree using this number of terminal nodes. Compute the test error rate for your pruned tree. f) Using the training and testing set, fit a support vector classifier to the training data using cost=0.01, with Purchase as the response and the other variables as predictors. Use the summary function and describe your results. g) What are the training and test error rates? h) Use the tune() function to select an optimal cost. Consider values from 0.01 to 10. i) Compute the test and training error rates for this new cost.
Karan D.
The following data are for 30 observations involving two categorical variables, x and y. The categories for x are A, B, and C; the categories for y are 1 and 2. Observation x y 1 B 1 2 C 2 3 C 2 4 C 2 5 B 1 6 C 2 7 B 1 8 C 1 9 A 1 10 B 2 11 A 1 12 C 1 13 B 1 14 C 2 15 B 1 Observation x y 16 B 2 17 B 1 18 B 1 19 A 1 20 B 1 21 A 1 22 C 2 23 B 1 24 C 2 25 B 1 26 C 2 27 C 2 28 A 1 29 C 2 30 B 1 (a) Develop a crosstabulation for the data, with x as the row variable and y as the column variable. y Total 1 2 x A B C Total (b) Compute the row percentages. (Round your answers to one decimal place.) y Total 1 2 x A B C (c) Compute the column percentages. (Round your answers to one decimal place.) y 1 2 x A B C Total (d) What is the relationship, if any, between x and y? Category A values for x are ---Select--- always associated with category 1 values always associated with category 2 values not associated with values in either category for y. Category B values for x are ---Select--- usually associated with category 1 values usually associated with category 2 values not associated with values in either category for y. Category C values for x are ---Select--- usually associated with category 1 values usually associated with category 2 values not associated with values in either category for y.
Rachel G.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD