Data scientists spend up to 80% of their time on data preparation and feature engineering, according to a widely cited 2016 survey by CrowdFlower (now Figure Eight). That number hasn't improved much. In 2026, large language models can generate code, explain errors, and suggest transformations in seconds — but only if you ask the right way. The gap between a vague request and a precise, context-rich prompt is often the difference between a useless snippet and a production-ready pipeline.
This article is a practical cheat sheet. Each prompt below is a complete, copy-paste-ready instruction that covers a specific stage of the ML lifecycle: exploratory data analysis (EDA), feature engineering, model training, hyperparameter tuning, error analysis, and visualization. I've tested these prompts with models like GPT-4, Claude 3.5 Sonnet, and Gemini 1.5 Pro. They work best when you provide real column names, data types, and a sample of your dataframe.
A quick note on how to use them: replace anything in [brackets] with your actual context. The more precise your input, the less hallucination you'll get. And always validate generated code on a small sample before running it on your full dataset.
1. Exploratory Data Analysis (EDA) in One Shot
Task: Quickly profile a new dataset, detect data quality issues, and get a prioritized list of next steps.
Prompt:
You are a senior data scientist. I have a pandas DataFrame `df` with the following columns and dtypes:
[list columns and dtypes]
Sample rows:
[insert 3-5 rows]
Perform a comprehensive EDA. For each step, provide the exact Python code using pandas, numpy, and matplotlib/seaborn. Cover:
1. Shape, missing values, and unique counts.
2. Distribution of numeric features (histograms, boxplots).
3. Correlation matrix and top 10 correlated pairs.
4. Cardinality of categorical features and potential target leakage.
5. At least 3 data quality issues you notice (e.g., skewed distributions, outliers, constant columns).
6. A bullet-point summary of recommended next actions.
Example use: You load a churn dataset with 20 columns. The model returns a full EDA script, flags that customer_id has 100% unique values (drop it), and notes that monthly_charges is right-skewed — suggesting a log transform. You run the code, get plots, and save two hours of manual work.
2. Feature Engineering from Raw Timestamps
Task: Convert datetime columns into meaningful features for tree-based and linear models.
Prompt:
Given a pandas DataFrame with a datetime column `[timestamp_col]`, generate a feature engineering function that creates:
- Year, month, day, dayofweek, hour, minute.
- Is weekend, is month start/end, is quarter end.
- Cyclical encodings (sin/cos) for month, dayofweek, hour.
- Time since a reference date `[ref_date]` in days.
- Rolling window aggregates (mean, std) over the last 7 and 30 days for a numeric column `[value_col]`, grouped by `[group_col]`.
Return the function with docstrings and a usage example. Use only pandas and numpy.
Why it works: Tree models can't extrapolate trends; cyclical features preserve periodicity. This prompt saves you from writing the same boilerplate every time.
Example: For a demand forecasting dataset, the model generates hour_sin, hour_cos, and a 7-day rolling mean. Your XGBoost model improves its RMSE by a noticeable margin on validation.
3. Automated Feature Selection with Mutual Information
Task: Reduce dimensionality without losing predictive signal.
Prompt:
I have a DataFrame `df` with a binary target `[target]` and 150 numeric features. Write a Python script that:
1. Computes mutual information between each feature and the target.
2. Selects the top K features (K=30) using `SelectKBest`.
3. Compares results with a Random Forest feature importance ranking.
4. Plots the top 20 features by mutual information as a horizontal bar chart.
5. Outputs a list of features that appear in both top-30 lists.
Use scikit-learn. Explain in comments why mutual information is preferred over correlation for non-linear relationships.
Reference: Scikit-learn documentation on mutual_info_classif (sklearn.feature_selection).
Example: On a credit scoring dataset, the intersection of MI and RF top-30 gives you 18 stable features. You drop 132 columns, training time drops by half, and AUC stays within 0.01 of the full model.
4. Handling Missing Data with Iterative Imputation
Task: Impute missing values more intelligently than mean/mode.
Prompt:
My DataFrame has missing values in `[col1]`, `[col2]`, `[col3]`. Write a scikit-learn pipeline that:
- Uses `IterativeImputer` (from sklearn.experimental) with a BayesianRidge estimator.
- Adds a missing indicator for each column with >5% missingness.
- Compares imputation quality via cross-validated RMSE on a held-out set where I artificially mask 10% of values.
Provide the code and a short interpretation of when iterative imputation is worth the compute cost.
Note: IterativeImputer is still experimental in scikit-learn; import it via from sklearn.experimental import enable_iterative_imputer.
Example: For a medical dataset with 15% missing BMI, iterative imputation reduces downstream model error compared to mean imputation, especially when missingness is not random.
5. Baseline Model in 10 Lines
Task: Get a quick performance benchmark before investing in complex models.
Prompt:
Write a Python script that trains and evaluates three baseline models on my dataset `[X, y]`:
- DummyClassifier (most frequent) for classification, or DummyRegressor (mean) for regression.
- LogisticRegression or LinearRegression with default parameters.
- RandomForest with 100 trees.
Use 5-fold cross-validation. Report accuracy, F1, ROC-AUC (or RMSE, MAE for regression). Output a pandas DataFrame comparing the results.
Why it matters: Without a baseline, you can't tell if your 0.92 AUC is good or just reflects class imbalance.
Example: On an imbalanced fraud dataset, the dummy classifier gives 0.998 accuracy but 0.00 F1. Your logistic regression gives 0.85 F1 — now you know the real challenge.
6. Hyperparameter Tuning with Optuna
Task: Automate hyperparameter search with pruning and logging.
Prompt:
Create an Optuna study to tune an XGBoost classifier on `[X_train, y_train]`. Search over:
- n_estimators: 100–1000
- max_depth: 3–12
- learning_rate: 0.01–0.3 (log scale)
- subsample: 0.5–1.0
- colsample_bytree: 0.5–1.0
Use 5-fold stratified cross-validation, ROC-AUC as the objective, and `MedianPruner`. Run 50 trials. After the study, print the best params and plot the optimization history. Include code to save the study to a SQLite database.
Reference: Optuna documentation (optuna.org).
Example: A 50-trial study on a tabular dataset typically finds a better configuration than manual grid search in less time.
7. Error Analysis: Where Does Your Model Fail?
Task: Move beyond aggregate metrics and find systematic errors.
Prompt:
I have a trained classifier `model` and a test set `X_test, y_test`. Write code that:
1. Generates predictions and predicted probabilities.
2. Identifies the 20 false positives and 20 false negatives with the highest confidence.
3. For each error group, computes summary statistics of key features (e.g., mean age, most common category).
4. Plots a confusion matrix and a calibration curve.
5. Suggests 3 hypotheses for why the model fails on these cases.
Why it works: Aggregate metrics hide slice-level failures. This prompt forces the model to look at the tails.
Example: On a loan default model, error analysis reveals that false negatives cluster among young applicants with short credit history — a signal to add a feature or reweight the training set.
8. SHAP Values for Model Interpretation
Task: Explain individual predictions and global feature importance.
Prompt:
Using the `shap` library, write a script that:
- Computes SHAP values for my trained XGBoost model on `X_test`.
- Plots a summary plot (beeswarm) of the top 15 features.
- Plots a waterfall plot for the prediction of the first test instance.
- Outputs a DataFrame with mean absolute SHAP values per feature.
Explain in comments how to interpret positive vs negative SHAP values.
Reference: Lundberg & Lee (2017), "A Unified Approach to Interpreting Model Predictions," NeurIPS.
Example: For a marketing propensity model, SHAP shows that last_purchase_days_ago dominates, but email_opens_last_30d interacts strongly with it — insight you can hand to the business team.
9. Visualizing High-Dimensional Data with UMAP
Task: Reduce dimensions for clustering and visual inspection.
Prompt:
Write a Python script that:
- Applies UMAP (umap-learn) to my scaled feature matrix `X_scaled` (n_samples=5000, n_features=50).
- Plots a 2D scatter colored by `[label_col]` with a legend.
- Runs HDBSCAN on the UMAP embedding and overlays cluster labels.
- Prints the silhouette score for the clustering.
Use matplotlib and seaborn. Set random_state=42.
Reference: McInnes et al. (2018), "UMAP: Uniform Manifold Approximation and Projection," arXiv:1802.03426.
Example: On customer segmentation data, UMAP reveals three well-separated clusters that K-means on raw features missed.
10. Time Series Cross-Validation
Task: Avoid data leakage when validating temporal models.
Prompt:
I have a time series dataset with a datetime index `[date_col]` and target `[target]`. Write code that:
- Uses `TimeSeriesSplit` from scikit-learn with 5 splits.
- Trains a LightGBM regressor on each split.
- Reports RMSE, MAE, and MAPE per fold and on average.
- Plots actual vs predicted for the last fold.
Explain why random K-fold is invalid for time series.
Why it matters: Random splits leak future information into training, inflating metrics.
Example: For weekly sales forecasting, TimeSeriesSplit gives a realistic error estimate, while random K-fold gives an overly optimistic one.
11. Model Comparison Table with Statistical Significance
Task: Choose between models with confidence, not gut feeling.
Prompt:
I have cross-validation results (5 folds) for 4 models: LogisticRegression, RandomForest, XGBoost, LightGBM. Write code that:
- Builds a pandas DataFrame of mean and std of ROC-AUC per model.
- Runs a paired t-test (or Wilcoxon) between the best model and each other.
- Outputs a Markdown table with mean, std, and p-value.
- Concludes which differences are statistically significant at alpha=0.05.
Example: The table shows XGBoost and LightGBM are within noise, so you pick the one with faster inference.
12. Generating a Reproducible Training Script
Task: Turn a notebook into a clean, versioned script.
Prompt:
Convert the following notebook code into a production-ready Python script:
[insert code]
Requirements:
- Use argparse for hyperparameters and file paths.
- Set all random seeds (numpy, random, framework).
- Log metrics and params to MLflow.
- Save the trained model with joblib.
- Include a `if __name__ == "__main__":` block.
- Add type hints and docstrings.
Reference: MLflow documentation (mlflow.org).
Example: A messy 200-cell notebook becomes a 120-line script that runs from the command line and logs every experiment.
Comparison: Which Prompt for Which Stage?
| Stage | Prompt # | Typical Time Saved |
|---|---|---|
| EDA | 1 | 1–2 hours |
| Feature engineering | 2, 3 | 2–4 hours |
| Missing data | 4 | 1 hour |
| Baseline | 5 | 30 minutes |
| Tuning | 6 | 2–3 hours |
| Error analysis | 7 | 1–2 hours |
| Interpretation | 8 | 1 hour |
| Visualization | 9 | 1 hour |
| Time series | 10 | 1–2 hours |
| Model selection | 11 | 1 hour |
| Productionization | 12 | 2–3 hours |
Final Thoughts
These 12 prompts cover the full data science workflow — from the first df.head() to a versioned training script. The key is not to copy them blindly, but to adapt them with your column names, business context, and constraints. Always review generated code for correctness, especially around data leakage and imputation.
If you want to go deeper into prompt engineering for technical domains, explore the practical guides on asibiont.com. And remember: a prompt is a conversation starter, not a replacement for domain expertise.
Comments