By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Python for Data Science is the toolbox that lets you turn raw data into actionable insights. It bundles NumPy for fast numeric arrays, pandas for tabular manipulation, Matplotlib/Seaborn for visual storytelling, and scikit‑learn for ready‑to‑use machine‑learning pipelines. In a churn‑prediction project, you’d load millions of customer events with NumPy, clean and aggregate them with pandas, explore patterns with Seaborn, and ship a logistic‑regression model via scikit‑learn—all in a single, reproducible Python script.
X + 5
groupby
pivot
merge
.loc
.iloc
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y)
RandomForestClassifier
GradientBoostingClassifier
python import numpy as np, pandas as pd df = pd.read_csv('customer_events.csv') print(df.head(), df.describe())
df.fillna(method='ffill')
df.groupby('customer_id')['event'].sum()
pd.get_dummies(df['plan'])
python from sklearn.model_selection import train_test_split X = df.drop('churn', axis=1) y = df['churn'] X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, stratify=y, random_state=42) from sklearn.preprocessing import StandardScaler scaler = StandardScaler().fit(X_train) X_train, X_test = scaler.transform(X_train), scaler.transform(X_test)
python from sklearn.linear_model import LogisticRegression model = LogisticRegression(max_iter=500, class_weight='balanced') model.fit(X_train, y_train)
python from sklearn.metrics import classification_report, roc_auc_score preds = model.predict(X_test) print(classification_report(y_test, preds)) print('AUC:', roc_auc_score(y_test, model.predict_proba(X_test)[:,1]))
GridSearchCV
RandomizedSearchCV
Mistake: Scaling after train‑test split on the combined data. Correction: Fit the scaler only on the training set and apply the same transformation to the test set to avoid data leakage.
Mistake: Ignoring class imbalance and using default accuracy. Correction: Use class_weight='balanced' or resampling techniques; evaluate with ROC‑AUC or Precision‑Recall instead of raw accuracy.
class_weight='balanced'
Mistake: Mixing .loc and .iloc in the same indexing expression, leading to unexpected rows/columns. Correction: Stick to one style per operation; double‑check shapes with .shape.
.shape
Mistake: Assuming np.mean on a DataFrame works column‑wise like pandas. Correction: Convert to NumPy (df.values) or use pandas methods (df.mean()) to respect column labels.
np.mean
df.values
df.mean()
Mistake: Over‑fitting by using the test set for hyper‑parameter tuning. Correction: Reserve a validation set or use nested cross‑validation; keep the final test set untouched until the very end.
GROUP BY
.sum()
.mean()
.apply()
np.where
.mask
Scenario: Your churn model’s ROC‑AUC is 0.92 but Precision is only 0.35 on the minority class. Answer: Use a Precision‑Recall curve and possibly adjust the decision threshold; consider oversampling or class‑weighting.
Scenario: After adding a new categorical feature, model training slows dramatically. Answer: Apply One‑Hot Encoding only to high‑cardinality columns after frequency filtering or use Target Encoding to keep dimensionality low.
Scenario: You notice the training loss keeps decreasing but validation loss plateaus. Answer: Increase regularization (e.g., C in LogisticRegression) or add early stopping; the model is likely over‑fitting.
C
penalty='l1'
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.