## IMPORTING LIBS import pandas as pd import plotly.express as px from sklearn.metrics import f1_score, precision_score, recall_score, confusion_matrix import pickle import gradio as gr ## CREATING FUNCTION def predict_credit_worthiness(name, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22): path = 'german_credit_risk/model/model.pickle' greet = 'Hey, ' + name + '!' with open(path, 'rb') as file: model = pickle.load(file) inputs = {'Account Balance_1': int(x1), 'Account Balance_2': int(x2), 'Account Balance_3': int(x3), 'Payment Status of Previous Credit_1': int(x4), 'Payment Status of Previous Credit_3': int(x5), 'Purpose_1': int(x6), 'Purpose_4': int(x7), 'Value Savings/Stocks_1': int(x8), 'Value Savings/Stocks_3': int(x9), 'Value Savings/Stocks_5': int(x10), 'Length of current employment_1': int(x11), 'Length of current employment_4': int(x12), 'Instalment per cent_4': int(x13), 'Guarantors_1': int(x14), 'Duration in Current address_1': int(x15), 'Duration in Current address_2': int(x16), 'Most valuable available asset_1': int(x17), 'Most valuable available asset_4': int(x18), 'Concurrent Credits_3': int(x19), 'Type of apartment_1': int(x20), 'No of Credits at this Bank_1': int(x21), 'Occupation_1': int(x22) } prediction = model.predict([list(inputs.values())]) y_test = pd.read_parquet('german_credit_risk/data/processed/y_test.parquet') y_test = y_test.squeeze() yhat = pd.read_parquet('german_credit_risk/data/processed/yhat.parquet') yhat = yhat.squeeze() precision = precision_score(y_test, yhat).round(2) recall = recall_score(y_test, yhat).round(2) f1 = f1_score(y_test, yhat).round(2) features_names = ['No account', 'No balance', 'Some balance', 'No credit problems', 'Some credit problems', 'New car', 'Other purpose', 'No savings', 'DM betwenn [100, 1000]', 'DM >= 1000', 'Employment: <1 year (or unemployed)', 'Employment: 4