The Data Scientist designs experiments, builds predictive models, and extracts insights that drive product decisions. The difference between a data scientist and a notebook user is rigour: correct train/test splits, proper cross-validation, and statistical tests that distinguish signal from noise.
Exploratory Data Analysis
import pandas as pd
import numpy as np
df = pd.read_csv('data.csv', parse_dates=['created_at'])
# Always start with these
print(df.shape) # (rows, cols)
print(df.dtypes) # Column types - catch objects that should be numeric
print(df.isnull().sum()) # Missing value counts per column
print(df.describe()) # Numeric summary stats
# Check for duplicates
print(f"Duplicate rows: {df.duplicated().sum()}")
print(f"Duplicate IDs: {df['id'].duplicated().sum()}")
# Target variable distribution - class imbalance check
print(df['label'].value_counts(normalize=True))
# Outlier detection with IQR
Q1, Q3 = df['amount'].quantile([0.25, 0.75])
IQR = Q3 - Q1
outliers = df[(df['amount'] < Q1 - 1.5 * IQR) | (df['amount'] > Q3 + 1.5 * IQR)]
print(f"Outliers: {len(outliers)} ({len(outliers)/len(df):.1%})")
Model Selection & Cross-Validation
from sklearn.model_selection import cross_val_score, StratifiedKFold
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
# Always stratified split for classification (preserves class ratio)
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
models = {
'Logistic Regression': LogisticRegression(max_iter=1000),
'Random Forest': RandomForestClassifier(n_estimators=100, random_state=42),
'Gradient Boosting': GradientBoostingClassifier(random_state=42),
}
for name, model in models.items():
scores = cross_val_score(model, X_train, y_train, cv=cv, scoring='roc_auc')
print(f"{name}: {scores.mean():.3f} ± {scores.std():.3f}")
# Rule: never evaluate on test set until after final model selection
# Rule: if you tune on validation, test set must be held out entirely until the end
A/B Test Analysis
from scipy import stats
# Two-proportion z-test for conversion rate
def ab_test(control_conversions, control_n, treatment_conversions, treatment_n):
p_control = control_conversions / control_n
p_treatment = treatment_conversions / treatment_n
p_pooled = (control_conversions + treatment_conversions) / (control_n + treatment_n)
se = (p_pooled * (1 - p_pooled) * (1/control_n + 1/treatment_n)) ** 0.5
z = (p_treatment - p_control) / se
p_value = 2 * (1 - stats.norm.cdf(abs(z)))
return {
'control_rate': p_control,
'treatment_rate': p_treatment,
'lift': (p_treatment - p_control) / p_control,
'p_value': p_value,
'significant': p_value < 0.05,
}
# Minimum detectable effect - always calculate BEFORE running the test
# Use statsmodels.stats.power.tt_solve_power for sample size calculation