liveBook · Manning

Bias

As explained in Starting Data Analytics with Generative AI and Python

Bias is a systematic preference or assumption that can distort the selection or interpretation of information, including generative-model outputs.

A useful-looking result can still be tilted. In generative-AI-assisted analytics, bias can unfairly favor groups or narrow what gets noticed. Skewed training data, model design choices, and skewed information supplied in a prompt can all affect the answer. The practical question is not just whether an output looks plausible, but whether it supports a fair decision. section 8.5 section 5.5.2

When a result seems questionable, check where the tilt might have entered:

  • Inherent bias comes with the pretrained model, whether from its algorithm or training data. Report concerns to its provider when you cannot change the model. section 8.5.1
  • Data bias comes from unbalanced or unrepresentative inputs; preprocessing bias enters during cleaning or feature selection. section 8.5.1
  • Label bias comes from subjective or biased labels, which can skew how results are interpreted even when the underlying data is unbiased. section 8.5.1

Monitor outputs over time, compare performance across groups or subsets, and ask users and stakeholders what they notice. Where appropriate, examine disparities, false-positive and false-negative rates, or patterns in prediction errors. Reranking, resampling, and reweighing can adjust outputs without retraining, but check that an adjustment does not impose a subjective result or conceal a poor choice of model. section 8.5.2 section 8.5.2

A lending decision

Suppose a model estimates a residential-loan applicant’s probability of default for an underwriter. Skewed historical training data could affect that estimate. Evaluate the model for bias before letting its advice shape a lending decision; an output adjustment alone is not a substitute for checking whether the model fits the use case. section 8.5.2

import pandas as pd
# Load your dataframe
df = pd.read_csv('olist_order_reviews_dataset.csv')

# List of positive keywords in Portuguese
positive_keywords = ['ótimo', 'excelente', 'bom', 'incrível', 
'maravilhoso', 'perfeito', 'gostei', 'satisfeito', 'recomendo', 
'amei']

# Define a function to check if a review contains positive keywords
def is_positive(review):
    for keyword in positive_keywords:
        if keyword.lower() in review.lower():
            return True
    return False

# Apply the function to the 'review_comment_message' column
df['is_positive'] = df['review_comment_message'].apply(is_positive)

# Create a new dataframe with only positive reviews
positive_reviews_df = df[df['is_positive']]

# Save the positive reviews to a new CSV file
positive_reviews_df.to_csv('positive_reviews.csv', index=False)

This Python filter selects Portuguese reviews using a fixed list of positive words. Inspect both selected and missed reviews: a narrow keyword list can leave relevant opinions out and create a misleading sense of completeness. section 5.5.6 section 5.5.2

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Defines four bias types and gives monitoring and mitigation methods, while leaving correction of a pretrained model’s internal bias to its provider.
Examples
Illustrates bias risks with residential-loan default advice and Python filtering of Portuguese customer reviews by positive keywords.
What it assumes
Assumes access to a pretrained generative AI and analytical data, while defining bias types and describing output checks.
What you can do after
Diagnose/debug with it by comparing groups, inspecting error patterns, and checking whether input data or output adjustments distort decisions.
How it connects
Connects bias to training data, preprocessing, labels, fairness metrics, confusion matrices, and residual analysis.

Also explained in

Compare how 28 books explain bias →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.