Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python Data sets can be found: https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=11712&itemId=1119526817&resourceId=46601 Using the training set, build a C5.0 model (Model 2) to predict a loan applicant's Approval using

Using Python

Data sets can be found: https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=11712&itemId=1119526817&resourceId=46601

Using the training set, build a C5.0 model (Model 2) to predict a loan applicant'sApprovalusingDebttoIncome Ratio,FICO Score, andRequest Amount, using the simplified datadriven cost matrix.

Simplified data-driven cost matrix is variable cost_matrix in code

Code so far:

loans_training = pd.read_csv("$/Loans_Training") loans_test = pd.read_csv("$/Loans_Test") y = loans_training[['Approval']] X = pd.concat((loans_training[['Debt-to-Income Ratio']], loans_training[['FICO Score']], loans_training[['Request Amount']]), axis = 1) y_test = loans_test[['Approval']] X_test = pd.concat((loans_test[['Debt-to-Income Ratio']], loans_test[['FICO Score']], loans_test[['Request Amount']]), axis = 1) X_names = ["Debt-to-Income Ratio", "FICO Score", "Request Amount"] y_names = ["Denied", "Approved"] dot_data = export_graphviz(c50_model_01) graph = graphviz.Source(dot_data) graph.render('model1', format='png') predApprovalC50 = c50_model_01.predict(X) c50_model_01_test = DecisionTreeClassifier(criterion = "entropy", min_samples_leaf = 1000).fit(X_test, y_test) predApprovalC50_test = c50_model_01_test.predict(X_test) freq_matrix_test_model01 = confusion_matrix(y_test['Approval'], predApprovalC50_test) TN_test_model01 = freq_matrix_test_model01[0, 0] FP_test_model01 = freq_matrix_test_model01[0, 1] FN_test_model01 = freq_matrix_test_model01[1, 0] TP_test_model01 = freq_matrix_test_model01[1, 1] TAN_test_model01 = TN_test_model01 + FP_test_model01 TAP_test_model01 = FN_test_model01 + TP_test_model01 TPN_test_model01 = TN_test_model01 + FN_test_model01 TPP_test_model01 = FP_test_model01 + TP_test_model01 GT_test_model01 = TN_test_model01 + FP_test_model01 + FN_test_model01 + TP_test_model01 contigency_table_model_01 = pd.DataFrame(freq_matrix_test_model01, columns=pd.MultiIndex.from_tuples([("Predicted Values for Approval","F"), ("Predicted Values for Approval","T")]), index=pd.MultiIndex.from_tuples([("Actual Values for Approval","F"), ("Actual Values for Approval","T")])) total_column_test_model01 = [TAN_test_model01, TAP_test_model01] contigency_table_model_01["Total"] = total_column_test_model01 contigency_table_model_01.loc[len(contigency_table_model_01.index)] = [TPN_test_model01, TPP_test_model01, GT_test_model01] contigency_table_model_01.index = pd.MultiIndex.from_tuples([("Actual Values for Approval","F"), ("Actual Values for Approval","T"), ("Actual Values for Approval","Total")]) contigency_table_model_01 y_train_interest = loans_training[['Interest']] train_interest_total = float(y_train_interest.sum() * -1.0) train_interest_total = round(train_interest_total, 4) train_interest_count = float(y_train_interest.count()) train_interest_count = round(train_interest_count, 4) train_interest_mean = train_interest_total / train_interest_count train_interest_mean = round(train_interest_mean, 4) train_cost_true_positive = train_interest_mean y_train_request = loans_training[['Request Amount']] train_request_total = float(y_train_request.sum()) train_request_total = round(train_request_total, 4) train_request_count = float(y_train_request.count()) train_request_count = round(train_request_count, 4) train_request_mean = train_request_total / train_request_count train_request_mean = round(train_request_mean, 4) train_cost_false_positive = train_request_mean train_cost_false_positive = round(train_cost_false_positive, 4) train_cost_true_positive_simple = train_cost_true_positive / float(train_cost_false_positive) train_cost_true_positive_simple = round(train_cost_true_positive_simple, 4) train_cost_false_positive_simple = train_cost_false_positive / float(train_cost_false_positive) cost_matrix = [[0, train_cost_true_positive_simple], [train_cost_false_positive_simple, 0]] contigency_table_cost_matrix_01 = pd.DataFrame(cost_matrix, columns=pd.MultiIndex.from_tuples([("Predicted Values for Approval","F"), ("Predicted Values for Approval","T")]), index=pd.MultiIndex.from_tuples([("Actual Values for Approval","F"), ("Actual Values for Approval","T")]))

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

The Equation Of Knowledge From Bayes Rule To A Unified Philosophy Of Science

Authors: Lê Nguyên Hoang

1st Edition

1000063275, 9781000063271

More Books

Students also viewed these Mathematics questions

Question

4. When is it appropriate to show grace toward others?

Answered: 1 week ago