Close Menu
    Trending
    • The Math That’s Killing Your AI Agent
    • Building Robust Credit Scoring Models (Part 3)
    • How to Measure AI Value
    • What’s the right path for AI? | MIT News
    • MIT and Hasso Plattner Institute establish collaborative hub for AI and creativity | MIT News
    • OpenAI is throwing everything into building a fully automated researcher
    • Agentic RAG Failure Modes: Retrieval Thrash, Tool Storms, and Context Bloat (and How to Spot Them Early)
    • The Basics of Vibe Engineering
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Building Robust Credit Scoring Models (Part 3)
    Artificial Intelligence

    Building Robust Credit Scoring Models (Part 3)

    ProfitlyAIBy ProfitlyAIMarch 20, 2026No Comments20 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    This text is the third a part of a sequence I made a decision to put in writing on how you can construct a strong and secure credit score scoring mannequin over time.

    The primary article targeted on how to construct a credit scoring dataset, whereas the second explored exploratory data analysis (EDA) and how you can higher perceive borrower and mortgage traits earlier than modeling.

    , my closing 12 months at an engineering college. As a part of a credit score scoring challenge, a financial institution offered us with information about particular person clients. In a earlier article, I defined how the sort of dataset is normally constructed.

    The objective of the challenge was to develop a scoring mannequin that might predict a borrower’s credit score danger over a one-month horizon. As quickly as we acquired the info, step one was to carry out an exploratory information evaluation. In my earlier article, I briefly defined why exploratory information evaluation is crucial for understanding the construction and high quality of a dataset.

    The dataset offered by the financial institution contained greater than 300 variables and over a million observations, masking two years of historic information. The variables have been each steady and categorical. As is frequent with real-world datasets, some variables contained lacking values, some had outliers, and others confirmed strongly imbalanced distributions.

    Since we had little expertise with modeling on the time, a number of methodological questions shortly got here up.

    The primary query was in regards to the information preparation course of. Ought to we apply preprocessing steps to the whole dataset first after which cut up it into coaching, take a look at, and OOT (out-of-time) units? Or ought to we cut up the info first after which apply all preprocessing steps individually?

    This query is necessary. A scoring mannequin is constructed for prediction, which suggests it should be capable to generalize to new observations, reminiscent of new financial institution clients. In consequence, each step within the information preparation pipeline, together with variable preselection, should be designed with this goal in thoughts.

    One other query was in regards to the position of area specialists. At what stage ought to they be concerned within the course of? Ought to they take part early throughout information preparation, or solely later when deciphering the outcomes? We additionally confronted extra technical questions. For instance, ought to lacking values be imputed earlier than treating outliers, or the opposite manner round?

    On this article, we concentrate on a key step within the modeling course of: dealing with excessive values (outliers) and lacking values. This step can generally additionally contribute to decreasing the dimensionality of the issue, particularly when variables with poor information high quality are eliminated or simplified throughout preprocessing.

    I beforehand described a associated course of in one other article on variable preprocessing for linear regression. In apply, the best way variables are processed typically depends upon the kind of mannequin used for coaching. Some strategies, reminiscent of regression fashions, are delicate to outliers and customarily require specific remedy of lacking values. Different approaches can deal with these points extra naturally.

    As an instance the steps introduced right here, we use the identical dataset launched within the earlier article on exploratory data analysis. This dataset is an open-source dataset accessible on Kaggle: the Credit score Scoring Dataset. It incorporates 32,581 observations and 12 variables describing loans issued by a financial institution to particular person debtors.

    Though this instance includes a comparatively small variety of variables, the preprocessing strategy described right here can simply be utilized to a lot bigger datasets, together with these with a number of hundred variables.

    Lastly, you will need to keep in mind that the sort of evaluation solely is sensible if the dataset is top quality and consultant of the issue being studied. In apply, information high quality is among the most important components for constructing strong and dependable credit score scoring fashions.

    This publish is a part of a sequence devoted to understanding how you can construct strong and secure credit score scoring fashions. The primary article targeted on how credit score scoring datasets are constructed. The second article explored exploratory information evaluation for credit score information. Within the following part, we flip to a sensible and important step: dealing with outliers and lacking values utilizing an actual credit score scoring dataset.

    Making a Time Variable

    Our dataset doesn’t comprise a variable that straight captures the time dimension of the observations. That is problematic as a result of the objective is to construct a prediction mannequin that may estimate whether or not new debtors will default. With no time variable, it turns into troublesome to obviously illustrate how you can cut up the info into coaching, take a look at, and out-of-time (OOT) samples. As well as, we can not simply assess the soundness or monotonic habits of variables over time.

    To deal with this limitation, we create a synthetic time variable, which we name 12 months.

    We assemble this variable utilizing cb_person_cred_hist_length, which represents the size of a borrower’s credit score historical past. This variable has 29 distinct values, starting from 2 to 30 years. Within the earlier article, after we discretized it into quartiles, we noticed that the default price remained comparatively secure throughout intervals, round 21%.

    That is precisely the habits we wish for our 12 months variable: a comparatively stationary default price, that means that the default price stays secure throughout totally different time durations.

    To assemble this variable, we make the next assumption. We arbitrarily suppose that debtors with a 2-year credit score historical past entered the portfolio in 2022, these with 3 years of historical past in 2021, and so forth. For instance, a worth of 10 years corresponds to an entry in 2014. Lastly, all debtors with a credit score historical past larger than or equal to 11 years are grouped right into a single class comparable to an entry in 2013.

    This strategy provides us a dataset masking an approximate historic interval from 2013 to 2022, offering about ten years of historic information. This reconstructed timeline permits extra significant prepare, take a look at, and out-of-time splits when growing the scoring mannequin. And likewise to check the soundness of the chance driver distribution over time.

    Coaching and Validation Datasets

    This part addresses an necessary methodological query: ought to we cut up the info earlier than performing information remedy and variable preselection, or after?

    In apply, machine studying strategies are generally used to develop credit score scoring fashions, particularly when a sufficiently giant dataset is offered and covers the total scope of the portfolio. The methodology used to estimate mannequin parameters should be statistically justified and primarily based on sound analysis standards. Particularly, we should account for potential estimation biases brought on by overfitting or underfitting, and choose an applicable degree of mannequin complexity.

    Mannequin estimation ought to finally depend on its means to generalize, that means its capability to appropriately rating new debtors who weren’t a part of the coaching information. To correctly consider this means, the dataset used to measure mannequin efficiency should be impartial from the dataset used to coach the mannequin.

    In statistical modeling, three sorts of datasets are usually used to attain this goal:

    • Coaching (or growth) dataset used to estimate and match the parameters of the mannequin.
    • Validation / Take a look at dataset (in-time) used to guage the standard of the mannequin match on information that weren’t used throughout coaching.
    • Out-of-time (OOT) validation dataset used to evaluate the mannequin’s efficiency on information from a totally different time interval, which helps consider whether or not the mannequin stays secure over time.

    Different validation methods are additionally generally utilized in apply, reminiscent of k-fold cross-validation or leave-one-out validation.

    Dataset Definition

    On this part, we current an instance of how you can create the datasets utilized in our evaluation: prepare, take a look at, and OOT.

    The event dataset (prepare + take a look at) covers the interval from 2013 to 2021. Inside this dataset:

    • 70% of the observations are assigned to the coaching set
    • 30% are assigned to the take a look at set

    The OOT dataset corresponds to 2022.

    train_test_df = df[df["year"] <= 2021].copy()
    oot_df = df[df["year"] == 2022].copy()  
    train_test_df.to_csv("train_test_data.csv", index=False)
    oot_df.to_csv("oot_data.csv", index=False)

    Preserving Mannequin Generalization

    To protect the mannequin’s means to generalize, as soon as the dataset has been cut up into prepare, take a look at, and OOT, the take a look at and OOT datasets should stay fully untouched throughout mannequin growth.

    In apply, they need to be handled as in the event that they have been locked away and solely used after the modeling technique has been outlined and the candidate fashions have been skilled. These datasets will later permit us to match mannequin efficiency and choose the ultimate mannequin.

    One necessary level to bear in mind is that each one preprocessing steps utilized to the coaching dataset should be replicated precisely on the take a look at and OOT datasets. This consists of:

    • dealing with outliers
    • imputing lacking values
    • discretizing variables
    • and making use of every other preprocessing transformations.

    Splitting the Improvement Dataset into Practice and Take a look at

    To coach and consider the totally different fashions, we cut up the event dataset (2013–2021) into two elements:

    • a coaching set (70%)
    • a take a look at set (30%)

    To make sure that the distributions stay comparable throughout these two datasets, we carry out a stratified cut up. The stratification variable combines the default indicator and the 12 months variable:

    def_year = def + 12 months

    This variable permits us to protect each the default price and the temporal construction of the info when splitting the dataset.

    Earlier than performing the stratified cut up, you will need to first look at the distribution of the brand new variable def_year to confirm that stratification is possible. If some teams comprise too few observations, stratification might not be potential or might require changes.

    In our case, the smallest group outlined by def_year incorporates greater than 300 observations, which signifies that stratification is completely possible. We will subsequently cut up the dataset into prepare and take a look at units, save them, and proceed the preprocessing steps utilizing solely the coaching dataset. The identical transformations will later be replicated on the take a look at and OOT datasets.

    from sklearn.model_selection import train_test_split
    
    train_test_df["def_year"] = train_test_df["def"].astype(str) + "_" + train_test_df["year"].astype(str)
    
    train_df, test_df = train_test_split(train_test_df, test_size=0.2, random_state=42, stratify=train_test_df["def_year"])
    
    # sauvegarde des bases
    train_df.to_csv("train_data.csv", index=False)
    test_df.to_csv("test_data.csv", index=False)
    oot_df.to_csv("oot_data.csv", index=False)

    Within the following sections, all analyses are carried out utilizing the coaching information.

    Outlier Remedy

    We start by figuring out and treating outliers, and we validate these remedies with area specialists. In apply, this step is simpler for specialists to evaluate than lacking worth imputation. Consultants typically know the believable ranges of variables, however they could not all the time know why a worth is lacking. Performing this step first additionally helps scale back the bias that excessive values may introduce through the imputation course of.

    To deal with excessive values, we use the IQR methodology (Interquartile Vary methodology). This methodology is often used for variables that roughly observe a traditional distribution. Earlier than making use of any remedy, you will need to visualize the distributions utilizing boxplots and density plots.

    In our dataset, we have now six steady variables. Their boxplots and density plots are proven under.

    The desk under presents, for every variable, the decrease certain and higher certain, outlined as:

    Decrease Sure = Q1 – 1.5 x IQR

    Higher Sure = Q3 + 1.5 x IQR

    the place IQR = Q3 – Q1 and (Q1) and (Q3) correspond to the first and third quartiles, respectively.

    On this research, this remedy methodology is affordable as a result of it doesn’t considerably alter the central tendency of the variables. To additional validate this strategy, we are able to discuss with the earlier article and look at which quantile ranges the decrease and higher bounds fall into, and analyze the default price of debtors inside these intervals.

    When treating outliers, you will need to proceed rigorously. The target is to scale back the affect of maximum values with out altering the scope of the research.

    From the desk above, we observe that the IQR methodology would cap the age of debtors at 51 years. This result’s acceptable provided that the research inhabitants was initially outlined with a most age of 51. If this restriction was not a part of the preliminary scope, the edge ought to be mentioned with area specialists to find out an inexpensive higher certain for the variable.

    Suppose, for instance, that debtors as much as 60 years outdated are thought-about a part of the portfolio. In that case, the IQR methodology would not be applicable for treating outliers within the person_age variable, as a result of it will artificially truncate legitimate observations.

    Two options can then be thought-about. First, area specialists might specify a most believable age, reminiscent of 100 years, which might outline the appropriate vary of the variable. One other strategy is to make use of a way known as winsorization.

    Winsorization follows the same concept to the IQR methodology: it limits the vary of a steady variable, however the bounds are usually outlined utilizing excessive quantiles or expert-defined thresholds. A standard strategy is to limit the variable to a variety reminiscent of:

    Observations falling outdoors this restricted vary are then changed by the closest boundary worth (the corresponding quantile or a worth decided by specialists).

    This strategy could be utilized in two methods:

    • Unilateral winsorization, the place just one aspect of the distribution is capped.
    • Bilateral winsorization, the place each the decrease and higher tails are truncated.

    On this instance, all observations with values under €6 are changed with €6 for the variable of curiosity. Equally, all observations with values above €950 are changed with €950.

    We compute the ninetieth, ninety fifth, and 99th percentiles of the person_age variable to verify whether or not the IQR methodology is suitable. If not, we’d use the 99th percentile because the higher certain for a winsorization strategy.

    On this case, the 99th percentile is the same as the IQR higher certain (51). This confirms that the IQR methodology is suitable for treating outliers on this variable.

    def apply_iqr_bounds(prepare, take a look at, oot, variables):
    
        prepare = prepare.copy()
        take a look at = take a look at.copy()
        oot = oot.copy()
    
        bounds = []
    
        for var in variables:
    
            Q1 = prepare[var].quantile(0.25)
            Q3 = prepare[var].quantile(0.75)
    
            IQR = Q3 - Q1
    
            decrease = Q1 - 1.5 * IQR
            higher = Q3 + 1.5 * IQR
    
            bounds.append({
                "Variable": var,
                "Decrease Sure": decrease,
                "Higher Sure": higher
            })
    
            for df in [train, test, oot]:
                df[var] = df[var].clip(decrease, higher)
    
        bounds_table = pd.DataFrame(bounds)
    
        return bounds_table, prepare, take a look at, oot
    
    bounds_table, train_clean_outlier, test_clean_outlier, oot_clean_outlier = apply_iqr_bounds(
        train_df,
        test_df,
        oot_df,
        variables
    )

    One other strategy that may typically be helpful when coping with outliers in steady variables is discretization, which I’ll focus on in a future article.

    Imputing Lacking Values

    The dataset incorporates two variables with lacking values: loan_int_rate and person_emp_length. Within the coaching dataset, the distribution of lacking values is summarized within the desk under.

    The truth that solely two variables comprise lacking values permits us to research them extra rigorously. As an alternative of instantly imputing them with a easy statistic such because the imply or the median, we first attempt to perceive whether or not there’s a sample behind the lacking observations.

    In apply, when coping with lacking information, step one is commonly to seek the advice of area specialists. They might present insights into why sure values are lacking and recommend cheap methods to impute them. This helps us higher perceive the mechanism producing the lacking values earlier than making use of statistical instruments.

    A easy solution to discover this mechanism is to create indicator variables that take the worth 1 when a variable is lacking and 0 in any other case. The thought is to test whether or not the likelihood {that a} worth is lacking depends upon the opposite noticed variables.

    Case of the Variable person_emp_length

    The determine under exhibits the boxplots of the continual variables relying on whether or not person_emp_length is lacking or not.

    A number of variations could be noticed. For instance, observations with lacking values are inclined to have:

    • decrease earnings in contrast with observations the place the variable is noticed,
    • smaller mortgage quantities,
    • decrease rates of interest,
    • and increased loan-to-income ratios.

    These patterns recommend that the lacking observations aren’t randomly distributed throughout the dataset. To substantiate this instinct, we are able to complement the graphical evaluation with statistical exams, reminiscent of:

    • Kolmogorov–Smirnov or Kruskal–Wallis exams for steady variables,
    • Cramér’s V take a look at for categorical variables.

    These analyses would usually present that the likelihood of a lacking worth depends upon the noticed variables. This mechanism is called MAR (Lacking At Random).

    Below MAR, a number of imputation strategies could be thought-about, together with machine studying approaches reminiscent of k-nearest neighbors (KNN).

    Nonetheless, on this article, we undertake a conservative imputation technique, which is often utilized in credit score scoring. The thought is to assign lacking values to a class related to the next likelihood of default.

    In our earlier analysis, we noticed that debtors with the very best default price belong to the primary quartile of employment size, comparable to clients with lower than two years of employment historical past. To stay conservative, we subsequently assign lacking values for person_emp_length to 0, that means no employment historical past.

    Case of the Variable loan_int_rate

    After we analyze the connection between loan_int_rate and the opposite steady variables, the graphical evaluation suggests no clear variations between observations with lacking values and people with out.

    In different phrases, debtors with lacking rates of interest seem to behave equally to the remainder of the inhabitants when it comes to the opposite variables. This commentary may also be confirmed utilizing statistical exams.

    The sort of mechanism is normally known as MCAR (Lacking Utterly At Random). On this case, the missingness is impartial of each the noticed and unobserved variables.

    When the lacking information mechanism is MCAR, a easy imputation technique is usually ample. On this research, we select to impute the lacking values of loan_int_rate utilizing the median, which is strong to excessive values.

    If you want to discover lacking worth imputation methods in additional depth, I like to recommend studying this article.

    The code under exhibits how you can impute the prepare, take a look at, and OOT datasets whereas preserving the independence between them. This strategy ensures that each one imputation parameters are computed utilizing the coaching dataset solely after which utilized to the opposite datasets. By doing so, we restrict potential biases that might in any other case have an effect on the mannequin’s means to generalize to new information.

    def impute_missing_values(prepare, take a look at, oot,
                              emp_var="person_emp_length",
                              rate_var="loan_int_rate",
                              emp_value=0):
        """
        Impute lacking values utilizing statistics computed on the coaching dataset.
    
        Parameters
        ----------
        prepare, take a look at, oot : pandas.DataFrame
            Datasets to course of.
            
        emp_var : str
            Variable representing employment size.
            
        rate_var : str
            Variable representing rate of interest.
            
        emp_value : int or float
            Worth used to impute employment size (conservative technique).
    
        Returns
        -------
        train_imp, test_imp, oot_imp : pandas.DataFrame
            Imputed datasets.
        """
    
        # Copy datasets to keep away from modifying originals
        train_imp = prepare.copy()
        test_imp = take a look at.copy()
        oot_imp = oot.copy()
    
        # ----------------------------
        # Compute statistics on TRAIN
        # ----------------------------
    
        rate_median = train_imp[rate_var].median()
    
        # ----------------------------
        # Create lacking indicators
        # ----------------------------
    
        for df in [train_imp, test_imp, oot_imp]:
    
            df[f"{emp_var}_missing"] = df[emp_var].isnull().astype(int)
            df[f"{rate_var}_missing"] = df[rate_var].isnull().astype(int)
    
        # ----------------------------
        # Apply imputations
        # ----------------------------
    
        for df in [train_imp, test_imp, oot_imp]:
    
            df[emp_var] = df[emp_var].fillna(emp_value)
            df[rate_var] = df[rate_var].fillna(rate_median)
    
        return train_imp, test_imp, oot_imp
    
    ## Software de l'imputation
    
    train_imputed, test_imputed, oot_imputed = impute_missing_values(
        prepare=train_clean_outlier,
        take a look at=test_clean_outlier,
        oot=oot_clean_outlier,
        emp_var="person_emp_length",
        rate_var="loan_int_rate",
        emp_value=0
    )

    We have now now handled each outliers and lacking values. To maintain the article targeted and keep away from making it lengthy, we are going to cease right here and transfer on to the conclusion. At this stage, the prepare, take a look at, and OOT datasets could be safely saved.

    train_imputed.to_csv("train_imputed.csv", index=False)
    test_imputed.to_csv("test_imputed.csv", index=False)
    oot_imputed.to_csv("oot_imputed.csv", index=False)

    Within the subsequent article, we are going to analyze correlations amongst variables to carry out strong variable choice. We can even introduce the discretization of steady variables and research two necessary properties for credit score scoring fashions: monotonicity and stability over time.

    Conclusion

    This text is a part of a sequence devoted to constructing credit score scoring fashions which can be each strong and secure over time.

    On this article, we highlighted the significance of dealing with outliers and lacking values through the preprocessing stage. Correctly treating these points helps forestall biases that might in any other case distort the mannequin and scale back its means to generalize to new debtors.

    To protect this generalization functionality, all preprocessing steps should be calibrated utilizing solely the coaching dataset, whereas sustaining strict independence from the take a look at and out-of-time (OOT) datasets. As soon as the transformations are outlined on the coaching information, they need to then be replicated precisely on the take a look at and OOT datasets.

    Within the subsequent article, we are going to analyze the relationships between the goal variable and the explanatory variables, following the identical methodological precept, that’s, preserving the independence between the prepare, take a look at, and OOT datasets.

    Picture Credit

    All pictures and visualizations on this article have been created by the writer utilizing Python (pandas, matplotlib, seaborn, and plotly) and excel, until in any other case acknowledged.

    References

    [1] Lorenzo Beretta and Alessandro Santaniello.
    Nearest Neighbor Imputation Algorithms: A Vital Analysis.
    Nationwide Library of Medication, 2016.

    [2] Nexialog Consulting.
    Traitement des données manquantes dans le milieu bancaire.
    Working paper, 2022.

    [3] John T. Hancock and Taghi M. Khoshgoftaar.
    Survey on Categorical Knowledge for Neural Networks.
    Journal of Huge Knowledge, 7(28), 2020.

    [4] Melissa J. Azur, Elizabeth A. Stuart, Constantine Frangakis, and Philip J. Leaf.
    A number of Imputation by Chained Equations: What Is It and How Does It Work?
    Worldwide Journal of Strategies in Psychiatric Analysis, 2011.

    [5] Majid Sarmad.
    Strong Knowledge Evaluation for Factorial Experimental Designs: Improved Strategies and Software program.
    Division of Mathematical Sciences, College of Durham, England, 2006.

    [6] Daniel J. Stekhoven and Peter Bühlmann.
    MissForest—Non-Parametric Lacking Worth Imputation for Combined-Sort Knowledge.Bioinformatics, 2011.

    [7] Supriyanto Wibisono, Anwar, and Amin.
    Multivariate Climate Anomaly Detection Utilizing the DBSCAN Clustering Algorithm.
    Journal of Physics: Convention Sequence, 2021.

    Knowledge & Licensing

    The dataset used on this article is licensed below the Artistic Commons Attribution 4.0 Worldwide (CC BY 4.0) license.

    This license permits anybody to share and adapt the dataset for any function, together with business use, offered that correct attribution is given to the supply.

    For extra particulars, see the official license textual content: CC0: Public Domain.

    Disclaimer

    Any remaining errors or inaccuracies are the writer’s duty. Suggestions and corrections are welcome.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow to Measure AI Value
    Next Article The Math That’s Killing Your AI Agent
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    The Math That’s Killing Your AI Agent

    March 20, 2026
    Artificial Intelligence

    How to Measure AI Value

    March 20, 2026
    Artificial Intelligence

    What’s the right path for AI? | MIT News

    March 20, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Production-ready agentic AI: key challenges and solutions 

    January 14, 2026

    SocialPost AI: Features, Benefits, and Alternatives

    February 12, 2026

    Benefits an End to End Training Data Service Provider Can Offer Your AI Project

    June 4, 2025

    Powering next-gen services with AI in regulated industries 

    June 13, 2025

    A Tale of Two Variances: Why NumPy and Pandas Give Different Answers

    March 13, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    New AI agent learns to use CAD to create 3D objects from sketches | MIT News

    November 19, 2025

    Building A Successful Relationship With Stakeholders

    October 13, 2025

    AI text-to-speech programs could “unlearn” how to imitate certain people

    July 15, 2025
    Our Picks

    The Math That’s Killing Your AI Agent

    March 20, 2026

    Building Robust Credit Scoring Models (Part 3)

    March 20, 2026

    How to Measure AI Value

    March 20, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.