Question: Solve the following problem in python: Problem 4 : Decision Trees From a Relation ( or Table ) One of the most successful techniques in
Solve the following problem in python:
Problem : Decision Trees From a Relation or Table
One of the most successful techniques in is building a function : We are given
data in the torm
data
as a relation: where TID is the tuple ID and each row is called a tuple. collectively are known
as the features and the label. In database parlances are known as attributes. Given the
relation or data we build a decision tree that's composed from a series of teatures and values.
The function we'll be bullding in this problem is for is this data:
A Person experienced days past due delinquency or worse as Boolean
B Total balance on credit cards and personal lines of credit except real estate and no install
ment debt like car loans divided by the sum of credit limits as percentage float
C Age of borrower in years as integer
D Number of times borrower has been days past due but no worse in the last years
as integer
E Monthly debt payments, alimony,living costs divided by monthy gross income as percent
age float
F Monthly income as float
G Number of Open loans installment like car loan or mortgage and Lines of credit eg
credit cards as integer
Number of times borrower has been days or more past due integer as
I Number of mortgage and real estate loans including home equity lines of credit as integer
Number of times borrower has been days past due but no worse in the last years
as integer
K Number of dependents in family excluding themselves spouse children etc. as integer
Here are three tuples: So the first tupe indicates the person was delinquent of at least a
month Feature As definition but the other two were not. We want to build a function :
BCDEFGHIJK A so that when we see a person's history:
we can predict if there will be a likely delinquency at least a month. A decision tree will build
a structure that will try to solve this problem. We will have spoken about this in lecture, but
you should visit: bttps:scikitlearn.orgstablerodulestree html and run the example
with the iris data with which you are familiar. The tree can be visualized as shown in Fig. :
The tollowing code:
which means the first person will, according to the data, be deliquent, and the second one will
not. Your function will take a string name of the file and use pandas to do the tollowing:
Clean the data by removing rows that have not a number We covered this in lecture,
but as hint, look for dropna.
Separate the table into two data frames: BK which are the features and A which is the
label or target. You build the tree as shown in the url.
Return the the fitted tree model.
import matplotlib.pyplot as plt
import numpy as np
import sqlite
import random as rn
import matplotlib
import pandas as pd
from sklearn import tree
#problem
#input file name
#output fitted tree model from skicit learn
def buildtreemodelcreditdata:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
