By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Exploratory Data Analysis (EDA) is the first‑hand, visual‑and‑statistical inspection of a dataset to uncover its shape, spot problems, and generate hypotheses before any modeling. In a churn‑prediction project, EDA tells you whether “tenure” is skewed, if “monthly charges” and “total charges” are almost duplicates, or whether a handful of customers have impossible values (e.g., negative tenure). Those insights dictate cleaning, feature engineering, and the choice of algorithms.
Load & Inspect python df = pd.read_csv('churn.csv') print(df.shape, df.head()) df.info() # dtype, missing counts
python df = pd.read_csv('churn.csv') print(df.shape, df.head()) df.info() # dtype, missing counts
Univariate Checks – For each column:
df[col].describe()
sns.histplot(df[col], kde=True)
df[col].value_counts().plot.bar()
Compute skew/kurtosis; flag heavily skewed numeric features.
Bivariate Exploration – Pairwise diagnostics:
sns.scatterplot(x=col1, y=col2, data=df)
df.groupby(cat)[num].agg(['mean','std'])
Categorical vs categorical: pd.crosstab(df[cat1], df[cat2]) + chi2_contingency.
pd.crosstab(df[cat1], df[cat2])
chi2_contingency
Correlation & Redundancy python corr = df.select_dtypes('number').corr() sns.heatmap(corr, cmap='coolwarm', annot=True)
python corr = df.select_dtypes('number').corr() sns.heatmap(corr, cmap='coolwarm', annot=True)
Drop one of any pair with |r| > 0.9 (or use PCA later).
Outlier Detection & Treatment
z = np.abs(stats.zscore(df[num])) > 3
IsolationForest().fit_predict(df[num])
Decide: capping, log transform, or remove based on business impact.
Finalize Cleaned Data – Impute missing values (SimpleImputer(strategy='median')), encode categoricals (OneHotEncoder(handle_unknown='ignore')), and store the EDA notebook for reproducibility.
SimpleImputer(strategy='median')
OneHotEncoder(handle_unknown='ignore')
Mistake: Relying only on mean ± 2 σ to flag outliers. Correction: Use robust methods (IQR, Z‑score with median, or Isolation Forest) because heavy tails distort the mean and σ.
Mistake: Treating a high Pearson r as proof of causation. Correction: Remember correlation ≠ causation; always check for confounders and consider domain knowledge.
Mistake: Dropping all rows with any missing value. Correction: Impute intelligently (median for skewed numeric, most_frequent for categoricals) or model‑based imputation; otherwise you lose valuable data.
Mistake: Running a single histogram and assuming the distribution is “normal”. Correction: Complement histograms with Q‑Q plots (stats.probplot) and skew/kurtosis metrics; apply Box‑Cox/Yeo‑Johnson when needed.
stats.probplot
Mistake: Ignoring categorical correlation (e.g., using Pearson on encoded integers). Correction: Use Cramér’s V or chi‑square for categorical‑categorical relationships; encode only after assessing dependence.
Scenario: Your “total_charges” column is almost perfectly correlated (r = 0.99) with “monthly_charges”. Answer: Drop one (or combine) because the redundancy inflates variance in linear models; tree models can tolerate it.
Scenario: After computing Z‑scores, 5 % of rows are flagged as outliers, but they belong to a high‑value “enterprise” customer segment. Answer: Do not automatically drop them; investigate business relevance and consider capping or separate modeling for that segment.
Scenario: A scatter plot of “age” vs “spending_score” shows a curved pattern. Answer: Pearson r will be low; use Spearman ρ or fit a non‑linear model (e.g., polynomial regression) after confirming monotonicity.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.