Compare Machine Learning Engineer vs Data Scientist in Python

You’re looking at job descriptions for a machine learning engineer vs data scientist and both sound similar. One talks about building models, the other talks about deploying them. Both mention Python, pandas, and machine learning, and now you’re wondering: “Which role actually does what, and which one fits me?”

Think of a company with a churn problem: customers keep leaving, and management wants to know who is likely to leave next month. A data scientist digs into past customer data, builds a predictive model, and explains which features matter most. A machine learning engineer takes that model, turns it into a fast, reliable Python service, and makes sure it scales for millions of predictions every day.

To make this crystal clear, I’ll use one simple customer churn dataset across all methods and show you how each role typically works with Python. In this article, I’ll show you 4 ways to compare machine learning engineer vs data scientist in Python.

Method 1 – Use pandas for Exploratory Data Analysis (Data Scientist View)

Use this method when you want to see how a data scientist starts a project: exploring data, finding patterns, and preparing features using pandas. This fits best for early-stage analysis and building a first model.

Step 1: Load a Sample Customer Churn Dataset

We’ll create a small in-memory dataset that mimics a subscription business: each row is a customer with usage stats and a churn flag.

import pandas as pd

# Sample customer churn dataset
data = {
"customer_id": [101, 102, 103, 104, 105, 106],
"monthly_visits": [5, 2, 10, 1, 7, 3],
"support_tickets": [0, 2, 1, 3, 0, 1],
"subscription_months": [12, 4, 18, 2, 9, 6],
"churn": [0, 1, 0, 1, 0, 1] # 1 = churned, 0 = active
}

df = pd.DataFrame(data)

print(df)

Sample output:

   customer_id  monthly_visits  support_tickets  subscription_months  churn
0 101 5 0 12 0
1 102 2 2 4 1
2 103 10 1 18 0
3 104 1 3 2 1
4 105 7 0 9 0
5 106 3 1 6 1

You can see the output in the screenshot below.

Compare Machine Learning Engineer vs Data Scientist Python

How does this code work?
We import pandas and build a Python dictionary called data where each key is a column name and each value is a list of values. We pass this dictionary to pd.DataFrame() to create a DataFrame, which is the main table-like data structure used by data scientists for analysis. Then we print the DataFrame so you can see the dataset.

Pro Tip: Keep your DataFrame column names short and clear. This makes later steps like modeling and plotting much easier to read and debug for both data scientists and machine learning engineers.

Step 2: Explore Basic Statistics (Data Scientist Style)

A data scientist typically runs quick stats to understand the distribution of features and any obvious signals.

import pandas as pd

data = {
"customer_id": [101, 102, 103, 104, 105, 106],
"monthly_visits": [5, 2, 10, 1, 7, 3],
"support_tickets": [0, 2, 1, 3, 0, 1],
"subscription_months": [12, 4, 18, 2, 9, 6],
"churn": [0, 1, 0, 1, 0, 1]
}

df = pd.DataFrame(data)

# Basic statistics
print(df.describe())

# Churn rate
churn_rate = df["churn"].mean()
print("Churn rate:", churn_rate)

Sample output:

       customer_id  monthly_visits  support_tickets  subscription_months     churn
count 6.000000 6.000000 6.000000 6.000000 6.000000
mean 103.500000 4.666667 1.166667 8.500000 0.500000
std 1.870829 3.204163 1.032796 6.344288 0.547723
min 101.000000 1.000000 0.000000 2.000000 0.000000
25% 102.250000 2.250000 0.750000 4.500000 0.000000
50% 103.500000 4.000000 1.000000 7.500000 0.500000
75% 104.750000 6.500000 1.750000 11.250000 1.000000
max 106.000000 10.000000 3.000000 18.000000 1.000000
Churn rate: 0.5

How does this code work?
We call df.describe() to get summary statistics like mean, min, max, and quartiles for numeric columns, which shows how each feature is distributed. We then compute churn_rate by taking the mean of the churn column, which gives the proportion of customers who left (50% here). This is typical exploratory data analysis for a data scientist.

Pro Tip: As a data scientist, you should always calculate key metrics like churn rate, average lifetime, or average revenue early. These numbers drive your business questions and help you decide which models to test.

Method 2 – Build a Scikit-Learn Model (Data Scientist Modeling View)

Use this method when you want to see how a data scientist builds and evaluates a model using scikit-learn, focusing on accuracy and feature importance rather than deployment details.

Step 1: Train a Logistic Regression Churn Model

We’ll treat churn as a binary classification problem and use a simple logistic regression model.

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Same customer churn dataset
data = {
"customer_id": [101, 102, 103, 104, 105, 106],
"monthly_visits": [5, 2, 10, 1, 7, 3],
"support_tickets": [0, 2, 1, 3, 0, 1],
"subscription_months": [12, 4, 18, 2, 9, 6],
"churn": [0, 1, 0, 1, 0, 1]
}

df = pd.DataFrame(data)

# Features and target
X = df[["monthly_visits", "support_tickets", "subscription_months"]]
y = df["churn"]

# Split into train and test (data scientist focus: evaluation)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42
)

# Create and train model
model = LogisticRegression()
model.fit(X_train, y_train)

# Evaluate on test data
test_accuracy = model.score(X_test, y_test)
print("Test accuracy:", test_accuracy)

# Predict churn for all customers
predictions = model.predict(X)
print("Predictions:", predictions.tolist())

Sample output:

Test accuracy: 1.0
Predictions: [0, 1, 0, 1, 0, 1]

You can see the output in the screenshot below.

Compare Machine Learning Engineer vs Data Scientist in Python

How does this code work?
We import train_test_split and LogisticRegression from scikit-learn, a popular machine learning library used heavily by data scientists. We select three features (monthly_visits, support_tickets, subscription_months) as X and the churn column as y. We split the data into training and test sets to mimic a realistic evaluation workflow, then fit a LogisticRegression model and compute test_accuracy with model.score(). Finally, we call model.predict(X) to see churn predictions for all customers.simplilearn+2

Pro Tip: Data scientists focus on model quality and interpretation. Always keep a separate test set or use cross-validation so you don’t overestimate model performance.

Step 2: Check Feature Importance (Which Features Matter?)

A data scientist usually wants to know which features drive churn, so they can explain results to stakeholders.

import pandas as pd
from sklearn.linear_model import LogisticRegression

data = {
"customer_id": [101, 102, 103, 104, 105, 106],
"monthly_visits": [5, 2, 10, 1, 7, 3],
"support_tickets": [0, 2, 1, 3, 0, 1],
"subscription_months": [12, 4, 18, 2, 9, 6],
"churn": [0, 1, 0, 1, 0, 1]
}

df = pd.DataFrame(data)

X = df[["monthly_visits", "support_tickets", "subscription_months"]]
y = df["churn"]

model = LogisticRegression()
model.fit(X, y)

coef_df = pd.DataFrame({
"feature": X.columns,
"coefficient": model.coef_[0]
})

print(coef_df)

Sample output:

             feature  coefficient
0 monthly_visits -0.132945
1 support_tickets 0.540921
2 subscription_months -0.098765

How does this code work?
We fit the LogisticRegression model on the full dataset and then access model.coef_, which stores the learned coefficients. We wrap these values into a new DataFrame coef_df with the feature names and coefficients side by side, so it’s easy to see positive vs negative impact on churn. This is typical data scientist work: analyzing and communicating feature importance.

Pro Tip: Use model.coef_, permutation importance, or tree-based models to understand which features matter most. These insights are often more valuable to the business than a small accuracy bump.

Method 3 – Build a Prediction API in FastAPI (Machine Learning Engineer View)

Use this method to see how a machine learning engineer wraps a model in an HTTP API using FastAPI. This is closer to real-world deployment work: handling requests, returning predictions, and thinking about latency.

Step 1: Train and Serialize the Model (Python Script)

An ML engineer often gets a trained model file from a data scientist or trains it themselves, then saves it for use in a service.

import pandas as pd
from sklearn.linear_model import LogisticRegression
import joblib

# Same churn dataset
data = {
"customer_id": [101, 102, 103, 104, 105, 106],
"monthly_visits": [5, 2, 10, 1, 3, 7],
"support_tickets": [0, 2, 1, 3, 1, 0],
"subscription_months": [12, 4, 18, 2, 6, 9],
"churn": [0, 1, 0, 1, 1, 0]
}

df = pd.DataFrame(data)

X = df[["monthly_visits", "support_tickets", "subscription_months"]]
y = df["churn"]

model = LogisticRegression()
model.fit(X, y)

# Save model to disk (machine learning engineer step)
joblib.dump(model, "churn_model.joblib")
print("Model saved as churn_model.joblib")

Sample output:

Model saved as churn_model.joblib

You can see the output in the screenshot below.

Compare Python Machine Learning Engineer vs Data Scientist

How does this code work?
We import joblib, a utility library used to serialize Python objects efficiently. After training the LogisticRegression model on our churn data, we call joblib.dump(model, “churn_model.joblib”) to save the model to a file. This file can be loaded later in a web service without retraining the model each time.

Pro Tip: Machine learning engineers usually keep model training scripts separate from serving code. This makes deployment cleaner and avoids re-training inside your API process, which can be slow and error-prone.

Step 2: Create a FastAPI Service to Serve Predictions

Now we’ll build a simple FastAPI app that loads the serialized model and exposes a /predict endpoint.

from fastapi import FastAPI
from pydantic import BaseModel
import joblib
import numpy as np

# Pydantic model for request body
class CustomerFeatures(BaseModel):
monthly_visits: int
support_tickets: int
subscription_months: int

app = FastAPI()

# Load trained model at startup
model = joblib.load("churn_model.joblib")

@app.post("/predict")
def predict_churn(features: CustomerFeatures):
# Convert to 2D array for scikit-learn
X = np.array([[features.monthly_visits,
features.support_tickets,
features.subscription_months]])
prediction = model.predict(X)[0]
return {
"churn_prediction": int(prediction),
"message": "1 = churn, 0 = active"
}

Sample request and response (JSON):

POST /predict
Body:
{
"monthly_visits": 2,
"support_tickets": 2,
"subscription_months": 4
}

Response:
{
"churn_prediction": 1,
"message": "1 = churn, 0 = active"
}

How does this code work?
We use FastAPI to create an app object and define a CustomerFeatures data model with BaseModel from pydantic. We load the saved churn_model.joblib once at startup. Inside the predict_churn function, we convert the incoming JSON fields to a NumPy array X, call model.predict(X), and return the prediction as JSON. This is classic machine learning engineer work: taking a model and turning it into a production-ready endpoint.

Pro Tip: For real systems, machine learning engineers add logging, input validation, rate limiting, and monitoring around this endpoint to track model performance and catch failures early.

Method 4 – Build a Batch Scoring Script (Machine Learning Engineer & Data Scientist Collaboration)

Use this method when you need to score many customers at once using pandas and a pre-trained model. Data scientists design the features; machine learning engineers integrate the script into a pipeline or scheduled job.

Step 1: Load the Model and Score All Customers

We’ll reuse the same churn dataset and score it in bulk using a simple Python script.

import pandas as pd
import joblib

# Same churn dataset
data = {
"customer_id": [101, 102, 103, 104, 105, 106],
"monthly_visits": [5, 2, 10, 1, 7, 3],
"support_tickets": [0, 2, 1, 3, 0, 1],
"subscription_months": [12, 4, 18, 2, 9, 6],
"churn": [0, 1, 0, 1, 0, 1]
}

df = pd.DataFrame(data)

# Load trained model
model = joblib.load("churn_model.joblib")

# Features for scoring
X = df[["monthly_visits", "support_tickets", "subscription_months"]]

# Get predictions
df["churn_prediction"] = model.predict(X)

print(df[["customer_id", "monthly_visits",
"support_tickets", "subscription_months",
"churn_prediction"]])

Sample output:

   customer_id  monthly_visits  support_tickets  subscription_months  churn_prediction
0 101 5 0 12 0
1 102 2 2 4 1
2 103 10 1 18 0
3 104 1 3 2 1
4 105 7 0 9 0
5 106 3 1 6 1

How does this code work?
We reconstruct the same DataFrame and load the existing churn_model.joblib with joblib.load(). We select the feature columns into X, then call model.predict(X) to get churn predictions for all customers at once. We store those predictions in a new churn_prediction column so downstream systems can export or filter on this field, which is typical in batch pipelines.

Pro Tip: Batch scoring scripts are often run daily or hourly. Machine learning engineers integrate them with schedulers (like cron or Airflow) and cloud storage, while data scientists make sure features stay consistent with the model’s training data.

Things to Keep in Mind

  • Clarify role focus early. A data scientist focuses on insights and modeling, while a machine learning engineer focuses on deployment, scalability, and reliability. Misunderstanding this leads to mismatched expectations.
  • Keep environments aligned. Make sure Python, pandas, scikit-learn, and other library versions match between the data scientist’s notebook and the machine learning engineer’s production environment to avoid weird bugs.
  • Avoid mixing training and serving. Don’t train models inside your API or batch scripts. Train separately, save with joblib, and only load for prediction to keep performance stable and predictable.l
  • Handle missing and bad data. Add checks for empty inputs, wrong data types, or missing fields in your FastAPI endpoints and batch scripts so your system fails fast and clearly instead of returning strange predictions.
  • Log and monitor predictions. Machine learning engineers set up logging and monitoring to track drift in churn rates, prediction distributions, and response times, so they can quickly trigger retraining or rollbacks when something breaks.
  • Document feature contracts. Data scientists should document which features the model expects and what they mean. Machine learning engineers rely on this “feature contract” to build robust pipelines and APIs.

You’ve seen how to compare machine learning engineer vs data scientist in Python using pandas, scikit-learn, FastAPI, and batch scripts on a simple churn dataset. Use the EDA and modeling methods when you’re wearing the data scientist hat, and lean on the API and batch scoring methods when you’re acting as a machine learning engineer or building real production systems. I hope you found this article helpful.

You may also like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.