1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Is it possible to obtain feature importance for each predicted row?

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024 às 01:12.

  1. Stack

    Stack Membro Participativo

    I am working on credit risk analysis. I want to predict the risk of each company developing a debt with a fictional company. I obtained the feature importance from the model, but I want to know if it is possible to obtain which indicators influence the risk found for each client company.

    For example, client company X has a 70% risk, and this risk is associated with the variables city, age, and number of employees. Another client company Y may have an 80% risk, and the risk is associated with the variables city, service, and average salary.

    I am conducting a simple initial analysis with the following steps, where the model is trained with 20 indicators of companies that have already incurred a debt (classification 1) and the same amount of other companies that have not incurred a debt (classification 0). The model is fitted, and then predictions are made for new companies without classification.

    #Define the model
    rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42)

    #Train the model using the training data
    rf_classifier.fit(X, y)

    #Predictions using the asset data
    y_pred = rf_classifier.predict_proba(df_companies.iloc[:, 71:])
    Incorporating the data into the dataset
    df_companies['Risk_0'] = y_pred[:, 0] # Probability of being class 0: no debt incurred df_companies['Risk_1'] = y_pred[:, 1] # Probability of being class 1: debt incurred

    Continue reading...

Compartilhe esta Página