weltby Ergodic Sign inGet started
All use cases

Which Risk Grade Will the Bank Give This Loan?

From the loan, its guarantee and collateral and the household's finances, which of five risk grades does the bank assign? Predicting the grade helps check that grading is consistent across branches.

Use caseFinancePredictionModel evaluation

The table

Bank loans in China with loan terms, guarantees, collateral and household attributes, and the bank's five-category risk grade. It's in Welt's research catalogue as Credit Risk China, 27,522 rows by 28 columns, licensed CC BY 4.0. The catalogue measures its signal at 0.28. At 27,522 rows and 27 features the table is larger than the model limits allow, so the walkthrough evaluates and fits on a seeded sample of 4,000 rows. TabICLv2 and Kumo Tabular Medium compete.

Walkthrough

  1. Load it from the catalogue

    Find the table, read its recorded target and print the column names.

    import pandas as pd
    from welt import Client
    
    with Client() as client:
        item = client.research_datasets(q="credit risk China", limit=1)["items"][0]
        info = client.research_dataset(item["id"])
        data = client.load_research_dataset(item["id"])
    
    target = info["targets"][0]
    target = target["name"] if isinstance(target, dict) else target
    print([column["name"] for column in info["schema"]], target)
  2. Pick the rows

    Set aside 20 rows to predict at the end. The models learn from a seeded sample of 4,000 of the rest, the most this table's width allows.

    known = data.dropna(subset=[target])
    new_rows = known.sample(20, random_state=1)
    table = known.drop(new_rows.index).sample(4000, random_state=7)
  3. Compare the models and predict

    The models compete on the same folds against a simple guess, then the top-ranked one is fitted on the whole table. ROC AUC runs from 0.5, a coin toss, to 1, a perfect ranking, and a lower Brier score means the probabilities can be trusted more. The last table puts each prediction next to the real answer.

    with Client() as client:
        evaluation = client.evaluate(table, target, task="classification", seed=7,
                                     models=["tabicl-v2", "kumo-medium"])
        model = evaluation.fit()
    
    print(evaluation.summary()[["name", "rank", "roc_auc_mean", "brier_mean"]])
    features = new_rows.drop(columns=target)
    print(pd.DataFrame({"actual": new_rows[target].values, "predicted": model.predict(features),
                        "probability": model.predict_proba(features).max(axis=1)}))

What you get

A grade per loanWith a probability for each grade.
Consistency checksLoans graded far from the prediction stand out.
An honest signalThe catalogue measures a weak signal, so read the baseline comparison.

Try it

Use Open with to run the research datasets notebook in Colab, Kaggle or Jupyter and search for "credit risk China", or run the code above after pip install "welt-client[parquet]".