Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?

image text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions