Data Science & ML: 10 Battle-Tested Prompts That Take You from Raw Data to Production

You've got a dataset, a deadline, and a vague sense that machine learning could solve your problem. But where do you start? The gap between a raw CSV and a deployed model is full of pitfalls: messy data, overfitting, silent bugs, and deployment nightmares. As a developer who uses AI daily, I've compiled the prompts that actually work—each one battle-tested, with real examples. Whether you're cleaning data, building a model, or shipping it to production, these prompts will save you hours and headaches.

1. The Exploratory Data Analysis (EDA) Prompt

Prompt:

Act as a senior data scientist. Perform a comprehensive exploratory data analysis on the dataset at [path]. Generate summary statistics, identify missing values, outliers, and data types. Visualize distributions and correlations. Provide a markdown report with key insights and recommendations for data cleaning.

Why it works: It forces the AI to structure its output like a professional report, not just a pile of numbers. The explicit request for visualizations and recommendations turns raw output into actionable insights.

Example:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv('customer_data.csv')
print(df.describe())
print(df.isnull().sum())
# AI would generate a full report with histograms, correlation heatmaps, etc.

2. Data Cleaning and Preprocessing

Prompt:

Clean the dataset at [path]. Handle missing values using appropriate strategies (e.g., median for numerical, mode for categorical). Remove duplicates and outliers using IQR or Z-score. Normalize/standardize numerical features. Encode categorical variables. Output the cleaned dataset and a summary of changes made.

Why it works: It specifies the exact techniques, leaving no room for ambiguity. The request for a summary ensures you can verify the transformations.

Example:

from sklearn.preprocessing import StandardScaler, OneHotEncoder
import numpy as np

# AI would generate code to fill NaNs, cap outliers, scale, and encode

3. Feature Engineering

Prompt:

For the dataset at [path], suggest and implement new features that could improve model performance. Consider domain knowledge, interactions, and polynomial features. Explain each feature's rationale and show the code to create them.

Why it works: It taps into the AI's ability to brainstorm, while grounding it in code. The explanation requirement helps you understand the logic, making it easier to trust.

Example:

# AI suggests: 'income_per_capita' = income / household_size, 'age_squared', etc.
df['income_per_capita'] = df['income'] / df['household_size']

4. Model Selection and Baseline

Prompt:

Given a classification problem with [target] and features from [path], train a baseline model using logistic regression and a random forest. Compare their performance using cross-validation. Report accuracy, precision, recall, F1, and ROC-AUC. Recommend which model to pursue and why.

Why it works: It sets a clear benchmark and compares models, giving you a data-driven starting point.

Example:

from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score

models = {'LR': LogisticRegression(), 'RF': RandomForestClassifier()}
for name, model in models.items():
    scores = cross_val_score(model, X, y, cv=5, scoring='roc_auc')
    print(f'{name}: {scores.mean():.3f}')

5. Hyperparameter Tuning

Prompt:

Perform hyperparameter tuning for a [model type] on [path] using GridSearchCV or RandomizedSearchCV. Define a reasonable parameter grid, use 5-fold cross-validation, and optimize for F1-score. Show the best parameters and the corresponding performance.

Why it works: It automates the tedious search and ensures you don't miss optimal configurations.

Example:

from sklearn.model_selection import GridSearchCV
param_grid = {'n_estimators': [100, 200], 'max_depth': [None, 10, 20]}
grid = GridSearchCV(RandomForestClassifier(), param_grid, cv=5, scoring='f1')
grid.fit(X_train, y_train)
print(grid.best_params_)

6. Handling Imbalanced Data

Prompt:

The dataset at [path] has imbalanced classes. Apply techniques like SMOTE or class_weight adjustments. Train a model and compare performance before and after. Report precision, recall, and F1 for the minority class.

Why it works: It directly addresses a common pitfall and provides a quantitative comparison.

Example:

from imblearn.over_sampling import SMOTE
smote = SMOTE(random_state=42)
X_res, y_res = smote.fit_resample(X_train, y_train)

7. Model Interpretation and Explainability

Prompt:

Explain the predictions of the trained model at [path] using SHAP or LIME. Generate a summary plot showing feature importance and a force plot for a specific instance. Interpret the results in plain language.

Why it works: It bridges the gap between black-box models and stakeholder trust.

Example:

import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test)

8. Writing Production-Ready Code

Prompt:

Refactor the model training code at [path] into a production-ready Python script. Include proper error handling, logging, and configuration via environment variables. Structure it with functions or classes, and add type hints. Ensure it can be run from the command line.

Why it works: It transforms a notebook into maintainable code, a crucial step for deployment.

Example:

import logging
from typing import List, Dict
import joblib

def train_model(data_path: str, model_path: str) -> None:
    # code with logging and error handling

9. Deploying a Model as an API

Prompt:

Create a FastAPI application that serves predictions from the model at [path]. Include a /predict endpoint that accepts JSON input and returns predictions. Add input validation, error handling, and a health check endpoint. Provide instructions for running with uvicorn.

Why it works: It gives you a working API with best practices, ready to containerize.

Example:

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import joblib

app = FastAPI()
model = joblib.load('model.pkl')

class Features(BaseModel):
    feature1: float
    feature2: int

@app.post('/predict')
def predict(features: Features):
    try:
        pred = model.predict([[features.feature1, features.feature2]])
        return {'prediction': int(pred[0])}
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))

@app.get('/health')
def health():
    return {'status': 'ok'}

10. Monitoring and Retraining Strategy

Prompt:

Suggest a monitoring strategy for a deployed ML model. Define metrics to track (e.g., data drift, model drift, prediction latency). Provide code for logging predictions and features, and for triggering retraining when performance degrades. Use tools like MLflow or custom logging.

Why it works: It addresses the often-forgotten post-deployment phase, ensuring long-term reliability.

Example:

import mlflow
mlflow.log_metric('data_drift', drift_score)
# Set up a job that checks accuracy on a sliding window

11. Generating Synthetic Data

Prompt:

Generate synthetic data that mimics the distribution and correlations of the dataset at [path]. Use a method like CTGAN or Gaussian Copula. Provide code and validate that the synthetic data has similar statistical properties.

Why it works: It's useful for testing, privacy, or augmenting small datasets.

Example:

from sdv.tabular import CTGAN
model = CTGAN()
model.fit(df)
synthetic = model.sample(1000)

12. Automating ML Pipelines

Prompt:

Build an end-to-end ML pipeline using scikit-learn's Pipeline and ColumnTransformer. Include preprocessing for numerical and categorical features, a model, and a cross-validated evaluation. Output the pipeline and show how to use it for predictions.

Why it works: It ensures reproducibility and simplifies deployment.

Example:

from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
preprocessor = ColumnTransformer([
    ('num', StandardScaler(), num_cols),
    ('cat', OneHotEncoder(), cat_cols)
])
pipe = Pipeline([('prep', preprocessor), ('clf', RandomForestClassifier())])
pipe.fit(X_train, y_train)

These 12 prompts aren't just theory—they're the exact ones I use to accelerate my workflow. They've helped me turn messy datasets into reliable models and deploy them without panic. The next time you're stuck, try one. Your future self will thank you.

If you want to master these skills further, consider a structured course that covers the full ML lifecycle. But start here: pick a prompt, apply it to your data, and see the difference. AI is a tool; these prompts are the handle.

← All posts

Comments