Use the Predictive Mannequin Above and Feed It Person Enter and See the Predictions
Lastly, we are going to take EducationLevel, MaritalStatus, AccountType, LoanType, InterestRate, CreditLimit as person enter to see what credit_card_risk_type (excessive, low,medium) the skilled prediction mannequin predicts.
# Outline mappings for categorical enter to integer encoding
education_levels = {"Excessive College": 0, "Bachelor": 1, "Grasp": 2, "PhD": 3}marital_status = {"Single": 0, "Married": 1, "Divorced": 2, "Widowed": 3}
account_types = {"Checking": 0, "Financial savings": 1, "Credit score Card": 2, "Mortgage": 3}
risk_type_options = {0: 'Low', 1: 'Medium', 2: 'Excessive'}
# Operate to get person enter and convert to encoded worth
def get_user_input(immediate, category_dict):
whereas True:
response = enter(immediate)
if response in category_dict:
return category_dict[response]
else:
print("Invalid entry. Please select one in every of:", checklist(category_dict.keys()))
# Operate to get numerical enter and validate it
def get_numerical_input(immediate):
whereas True:
strive:
worth = float(enter(immediate))
return worth
besides ValueError:
print("Invalid entry. Please enter a legitimate quantity.")
# Accumulate inputs
education_level = get_user_input("Enter Schooling Degree (Excessive College, Bachelor, Grasp, PhD): ", education_levels)
marital_status = get_user_input("Enter Marital Standing (Single, Married, Divorced, Widowed): ", marital_status)
account_type = get_user_input("Enter Account Kind (Checking, Financial savings, Credit score Card, Mortgage): ", account_types) "Enter Account Kind (Checking, Financial savings, Credit score Card, Mortgage): ", account_types)
interest_rate = get_numerical_input("Enter Curiosity Charge: ")
credit_limit = get_numerical_input("Enter Credit score Restrict:")
# Put together the enter information for prediction
input_data = pd.DataFrame({'EducationLevel': [education_level],
'MaritalStatus': [marital_status], 'AccountType': [account_type],
'LoanAmount': [loan_amount], 'InterestRate': [interest_rate],
'CreditLimit': [credit_limit]})
# Predict the danger kind
prediction = mannequin.predict(input_data)
print("Predicted Danger Kind:", risk_type_options[prediction[0]])
Upon operating the above Challenge 1, you may be requested to supply the required enter, primarily based on which the predictive mannequin will inform you if the danger is excessive, medium, or low.