liveBook · Manning

Data drift

As explained in Starting Data Analytics with Generative AI and Python

Domain mismatch is the discrepancy between the data domain used to develop a model and the domain of the data to which it is applied.

Domain shift occurs when a model’s development data differs from the data it is applied to. A finance-focused sentiment classifier may not fit general customer reviews; sarcasm, regional language variation, and model biases can further affect results. section 6.2.5

Listing 6.2 Extracting positive reviews with the help of a suboptimal model
import pandas as pd
from transformers import pipeline

# Assuming df is your DataFrame and it has a column named 
'review_comment_message'
# Load the sentiment analysis pipeline with the FinBERT-PT-BR model
classifier = pipeline("sentiment-analysis", 
model="lucas-leme/FinBERT-PT-BR")
def get_sentiment(review):
    try:
        result = classifier(review)[0]
        return result['label'], result['score']
    except Exception as e:
        print(f"Error processing review: {e}")
        return None, None
# Apply the sentiment analysis to each review
df['sentiment'], df['score'] = 
zip(*df['review_comment_message'].map(get_sentiment))
# Filter the DataFrame to only include positive reviews
positive_reviews_df = df[df['sentiment'] == 'LABEL_1']   
# Assuming 'LABEL_1' is positive; adjust label as necessary based on model
output
# Now positive_reviews_df contains only the positive reviews

See how a sentiment pipeline applies FinBERT-PT-BR to Portuguese reviews, then filters records by predicted label. section 6.2.5

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Defines mismatch through a finance-versus-general-review example and lists risks, but does not establish the model’s actual efficacy.
Examples
Contrasts finance-specialized FinBERT-PT-BR with Portuguese customer reviews and flags sarcasm and regional variation.
What you can do after
Evaluate whether to proceed with FinBERT-PT-BR by monitoring errors and assessing its efficacy.
How it connects
Connects sentiment analysis with pretrained models, model bias, and human-in-the-loop review.

Also explained in

Compare how 6 books explain data drift →

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.