Zero Labs
Industry News / AI

Why Removing Sensitive Features Doesn’t Prevent Bias in Machine Learning Models

Source · Towards AI By Sudip Khadka

From the publisher’s feed, collected in the ZeroLabs newsroom.

This Image is Generated via AIMachine Learning models are making high stakes decision about people’s lives everyday on who gets a loan, who gets free housing, and who advances in a hiring process. The organizations deploying these models are aware of the risk of discrimination and are taking steps to prevent it. In order to overcome this challenge they remove all protected attributes including race, gender and martial status from the model training data. So, why does bias persist?In this article we will explain what this problem is called, how it arises, and most importantly, how it makes model systematically unfair. We will connect mathematically on how excluding those sensitive feature during pre processing does not eliminate the bias completely.What is the Problem?The problem is called latent leakage, and it occurs in several different ways. Through encoded information in the label from historical relation, feature engineering, and proxy variables. Not to get confused, bias is the discriminatory outcome. Latent leakage is the hidden statistical mechanism through which a model learns to reproduce that discrimination, even when the obvious causes have been removed from the data.1. Encoded Information in the LabelThe encoded information in the label are perhaps the most common form of leakage. When a model is trained on historical outcomes about who was approved for a loan, hiring decisions, and receiving housing assistance program it learn from decisions that were themselves shaped by the human bias. The outcome or label already carries the fingerprint of past discrimination. The model doesn’t need to see race or gender directly, it can simply learns to replicate the patterns encoded into the data.2. Feature EngineeringFeature engineering could introduce leakage when new variables are created from the raw data. A feature like “average commute time to the nearest bus stops” or “years in current neighborhood” may seem neutral on its surface, but in practice these variables can be tightly correlated with race due to historical residential segregation and redlining. The model now has mathematically encoded version of a protected attribute without even being told what it represents.3. Proxy VariablesProxy variables introduce bias through the indirect pathway, making them one of the most insidious forms of latent leakage. A zip code, a university name, a job title or even a person’s first name can serve as reliable statistical proxy for race, gender, or socioeconomic background. When the model discovers that applicants from certain ZIP codes are approved at lower rates because of who historically lived there, not because of the creditworthiness. The model has effectively learned to discriminate without a single protected attribute in sight.High Level Overview of LeakageThis is why simply removing sensitive columns from a datasets is not enough to eliminate systematic risk in Machine Learning models. The information remains indirectly embedded across dozens of features, and therefore, the model does not need to be given someone’s race explicitly. It can often infer it from correlated variables and behave accordingly. This is what makes latent leakage so difficult to detect and makes ML models unreliable in practices.A fairness audit that only checks whether protected attributes were included in training will pass the model cleanly. This is because the problem is not in the input level but inside the statistical structure of the feature space. To understand it more clearly, let’s push the discussion a bit further and look at what is happening mathematically behind the scene.The Math Behind the LeakageSuppose you are building a loan approval model for a financial institution. You collect a dataset, and during the preprocessing you removed the sensitive attribute ‘Race’ denoted as ‘S’ , and feed the model a feature vector X that no longer contains S. Doing this, you are assuming you have completely eliminated the effect of S from the model during training. But the “output” or “label” denoted as Y used during training was not generated by your model, it was generated by loan officers back then. If the historical decisions were influenced by S, then the dependence can remain embedded in the data, especially Y, even after S is removed from the feature set. The historical process may satisfy:This means that two applicants with identical observation characteristics X = x can still receive different outcome depending on S. When a model is trained by minimizing prediction error,it attempts to reproduce the statistical structure present in the data. If the historical labels encode decisions influenced by S, the model can learn patterns that indirectly replicate those decisions.Similarly, if we remove the sensitive feature S, the model still sees variable that are correlated with it. For example, “zip code” may strongly correlate with ‘race” or “socioeconomic status”. So although the model does not observe S directly, it observes X \ S, and that remaining features set can still contain information about S. Let’s say, if we use mutual information function I to measure how much information about the sensitive attribute remain embedded in the other features after deletion. The value is rarely zero because many features act as proxies for sensitive attributes. If the model produces prediction Y_hat, then by the data preprocessing inequality:This implies that removing S from the input imposes an upper bound on how much sensitive information can leak into the prediction. But, it does not guarantee the leakage to be small. If the true Y itself depends on S, and the training will often increase I(S;Y_hat) until it approaches the information about S that is indirectly encoded in the features and the label.Another potential cause of leakage is during feature engineering. Assume we have two variables, Z_1 which is “median income of the neighborhood” and Z_2 an “average house price in the neighborhood”, and both of them are somewhat related to “Race’” or “Gender” with correlation Corr(Z_1, S) = ρ_1 and Corr(Z_2, S) = ρ_2. Now we create a new feature which to measure “how affordable housing is in that neighborhood” from them, such as Z_3 = Z_1 / Z_2. The new variable Z_3 might actually reveal more about the neighborhood’s demographic composition than either income or house price alone.When we put all these factors together, a model is fair with respect to S only if the sensitive attribute has zero influence on its prediction. Formally expressed asIn reality, this condition rarely satisfied because it is challenging to identify covariates that are both strongly predictive and independent of the sensitive features. Model fairness cannot be achieved by data exclusion alone, it requires active intervention in the model’s learning process.Experiments:To see how this plays out in practice, consider what the mathematics above actually implies for a real modeling pipeline. The inequalities and mutual information expression we examined are measurable in the model’s output distribution. The following experiment operationalizes these ideas using a synthetic loan approval dataset by demonstrating that mutual information remains completely unavoidable even after sensitive feature is removed from training.Here is our loaded sample dataset:Step 1: Preprocessingfrom sklearn.preprocessing import OneHotEncoderfrom sklearn.compose import ColumnTransformerfrom sklearn.pipeline import Pipelinefrom sklearn.model_selection import train_test_splitX_raw = df.drop(columns='loan_approved')y = df['loan_approved']X_train_raw, X_test_raw, y_train, y_test = train_test_split( X_raw, y, test_size=0.2, random_state=42)# Create a column transformer for preprocessingpreprocessor = ColumnTransformer( transformers=[ ('cat', OneHotEncoder(handle_unknown='ignore'), categorical_features), ('num', 'passthrough', numerical_features) ])# Fit and transform X_raw to get the processed feature matrix XX_train = preprocessor.fit_transform(X_train_raw)X_test = preprocessor.transform(X_test_raw)Step 2: Train a logistic regression model using all relevant features, including ‘race’ , and generate predictions.from sklearn.linear_model import LogisticRegression# Train modelmodel_with_race = LogisticRegression(max_iter=1000, random_state=42)model_with_race.fit(X_train, y_train)# Predict on test sety_pred_with_race = model_with_race.predict(X_test)Step 3: calculate I(S; Ŷ) using the defined function.from sklearn.metrics import mutual_info_scoredef calculate_mutual_information(sensitive_attribute, predictions): return mutual_info_score(sensitive_attribute, predictions)model_with_race = calculate_mutual_information(df['race'], y_pred_with_race)print(f"Mutual Information I(race; Y_hat) with 'race' included: {model_with_race:.4f}")This gives us the Mutual Information of 0.6021 when evaluated with race and predicted label.Step 4: Now we remove ‘race’ from the features. By comparing the mutual information between the model’s predictions and the actual race data, we can detect whether other variable is acting as a proxy for race. If the MI remains high, it signals that the model still indirectly contains information about race despite race itself being removedX_no_race = df.drop(columns=['loan_approved', 'race'])y_no_race = df['loan_approved']X_train_nr, X_test_nr, y_train_nr, y_test_nr = train_test_split( X_no_race, y_no_race, test_size=0.2, random_state=42)preprocessor = ColumnTransformer( transformers=[ ('cat', OneHotEncoder(handle_unknown='ignore'), categorical_features), ('num', 'passthrough', numerical_features) ])X_train_nr = preprocessor.fit_transform(X_train_nr)X_test_nr = preprocessor.transform(X_test_nr)model_with_nr = LogisticRegression(max_iter=1000, random_state=42)model_with_nr.fit(X_train_nr, y_train_nr)y_pred_nr = model_with_race.predict(X_test_nr)model_with_nr = calculate_mutual_information(df['race'], y_pred_nr)print(f"Mutual Information I(race; Y_hat) with 'race' included: {model_with_nr:.4f}")This gives us the Mutual Information of 0.51 when evaluated with race and predicted label.The proximity of the mutual information values (0.6021 vs. 0.51) strongly suggests that other variables serves as an effective proxy for ‘race’ in the loan approval prediction, even when ‘race’ is explicitly removed from the model’s training features.How Can We Fix:As we saw in the loan approval example, the model does not need to be told someone’s race. If zip code, education and historical approval encodes race then the model has absorbed information about sensitive feature S from multiple directions simultaneously.So, latent leakage is not a problem that can be fixed by merely removing certain variables from the training data. Addressing latent leakage requires applying interventions at multiple stages of the machine learning pipeline. The following approaches have been used in combination to control leakages.1. Audit historical labels for biasInvestigate whether the target variable was itself generated by a biased process before training. If historical outcome reflect discrimination consider relabeling or reweighing samples data. Technique such as label reweighing can be used to assign lower importance to examples where the historical decision is suspected to encode bias.2. Proxy variable detectionUse statistical tests such as mutual information scoring to identify features that carry significant information about sensitive features even after removal. Features where the mutual information exceeds a defined threshold should be reviewed and either dropped or transformed before training.3. Counterfactual fairnessUse a casual graph of the feature relationships to identify and block the pathways through which sensitive features influences target variable, rather than simply removing it from the input.4. Post-hoc fairness auditingEven after the above interventions models should be audited against formal fairness metrics such as demographic parity, equalized odds, and calibration across subgroups. This audit must measure the mutual information to check whether sensitive features appears in the input features. A model that passes a surface level audit can still be deeply unfair, as the article has shown.Building fair and responsible AI system requires treating bias as a structural property of the entire pipeline, not just a data quality problem solved as preprocessing stage. Latent leakage reminds us that the statistical traces of past discrimination that do not disappear easily. Even when the original cause is removed from the data, the correlations it created can still influence model predictions. But with the right tools and safeguards, their impact can be meaningfully constrained.Why Removing Sensitive Features Doesn’t Prevent Bias in Machine Learning Models was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.