Question: Simple decision rules in python I have the following pandas data frame and I need to write a python function using if else statements to

Simple decision rules in python

I have the following pandas data frame and I need to write a python function using if else statements to predict cheat if yes (1) or no (0). The decisions rules need to follow the tree in the figure below. The code I have written so far is below as well but it does not populate the output list with the no (0) values. Can you please help me get this corrected?

Simple decision rules in python I have the following pandas data frame

and I need to write a python function using if else statements

to predict cheat if yes (1) or no (0). The decisions rules

1 1 # Function for tree prediction 2. 3 def predict(df, vari, var2, var3): 4. targ = [] 5 for row in df: 6 if varl == 'yes': 7 targ.append(1) 8. else: 9 if var3 == 'no': 10 targ.append() 11 else: 12 if var2 'married': 13 targ.append(0) 14 else: 15 targ.append(1) 16 return targ HN LOON 000 1 1 1 1 1 1 my_targ = predict(data, 'refund', 'marital_status', 'income_above_80k') ' 2 my_targ = [1, 1, 1, 1] refund marital_status income_above_80k cheat 0 yes single yes no 1 no married yes no 2 no single no no 3 yes married yes no 4 no divorced yes yes 5 no married no no 6 6 yes divorced yes no 7 no single yes yes 8 no married no no 9 no single yes yes Refund No Yes Predict No Income above 80k No Yes Predict No Marital Status Married Single or divorced Predict No Predict Yes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!