How to fit IC50 dose-response curves in Python without hidden assumptions
Fit 4-parameter logistic IC50 curves in Python with SciPy, audit bottom-plateau and outlier forks, and download a verified Jupyter notebook and CSV.
By Amir Hesham

Fitting an IC50 curve in Python takes ten lines of scipy.optimize.curve_fit, yet two scientists running the exact same plate can walk away with IC50 values nearly 40% apart. The difference is rarely the math library; it comes from silent choices about whether the bottom asymptote is fixed at 0%, how vehicle controls are handled on a log axis, and what happens to one bad well at high dose.
Download the verified files for this recipe: dose_response_assay.csv (60 rows, SHA-256 13bfe2996e69) and ic50_dose_response_verified.ipynb (executed clean-start with zero errors).
Plain-English prompt walkthrough
In Dalliance, you do not start by wiring up a conda environment or hunting down a 4PL snippet from an old forum post. You drop dose_response_assay.csv into your project folder and ask one plain-English question per cell:
Fit a 4-parameter logistic (4PL) dose-response curve for Compound_A and Compound_B from
dose_response_assay.csv, report IC50 with 95% confidence intervals, and check how fixing Bottom=0% or excluding the edge outlier changes the IC50.
Dalliance inspects the local CSV first. The file contains 60 rows across two compounds, 30 rows for Compound_A and 30 rows for Compound_B, spanning 0.0 nM to 3000.0 nM with three replicates per dose.
Before showing a final number, Dalliance prints how it interpreted your request and underlines each modeling choice as a clickable control. You can test clicking an underlined assumption yourself in the interactive demo on dalliance.io without installing anything. Here, three choices determine the answer: whether zero-concentration vehicle wells are excluded from the log10 fit, whether the lower asymptote floats freely or locks to 0%, and whether a single high-residual well stays in the fit.
The analytical forks that move the IC50
Running all three modeling paths on dose_response_assay.csv shows how much those choices shift both the potency estimate and the confidence interval.

In Cell 4 of the verified notebook, a residual check flags one outlier in Compound_A: a well at 1000.0 nM reading 41.8% viability, more than 3 SD away from the fitted curve. Here are the exact verified numbers across both compounds:
| Compound | Model | IC50 (nM) | 95% CI low (nM) | 95% CI high (nM) | Bottom (%) | Top (%) | Hill | R² |
|---|---|---|---|---|---|---|---|---|
| Compound_A | 4PL (all points) | 15.96 | 11.94 | 21.33 | 10.56 | 98.89 | 1.29 | 0.9678 |
| Compound_A | Bottom fixed at 0% | 18.71 | n/a | n/a | 0.00 | 104.61 | 0.83 | n/a |
| Compound_A | 4PL (excl 1 outlier) | 17.45 | 15.76 | 19.32 | 6.28 | 99.61 | 1.17 | 0.9965 |
| Compound_B | 4PL (all points) | 135.83 | 114.50 | 161.14 | 11.08 | 98.64 | 0.91 | 0.9949 |
| Compound_B | Bottom fixed at 0% | 188.81 | n/a | n/a | 0.00 | 100.73 | 0.71 | n/a |
Look at what each fork does to the interpretation:
- Excluding the single bad well on Compound_A. Keeping the
1000.0 nMwell at41.8%viability drags the estimated bottom plateau up to10.56%, widens the 95% confidence interval to11.94to21.33 nM, and pulls R² down to0.9678. Dropping that one residual outlier moves the IC50 from15.96 nMto17.45 nM, cuts the 95% CI width nearly in half (15.76to19.32 nM), brings Bottom down to6.28%, and raises R² to0.9965. - Fixing Bottom at 0% vs floating Bottom. Many default templates quietly force the lower plateau to
0%, turning a 4PL curve into a 3PL curve. OnCompound_A, that moves the IC50 from15.96 nMto18.71 nMand flattens the Hill slope from1.29to0.83. OnCompound_B, where true viability plateaus near11.08%, locking Bottom to0%pushes the IC50 from135.83 nMto188.81 nM, a 39% shift, and drags the Hill slope from0.91to0.71. - Fitting in log10 concentration space. Fitting
log10(concentration_nM)rather than raw nanomolar values stabilizescurve_fitconvergence and produces symmetric confidence intervals onlog_ic50that back-transform properly onto the nanomolar scale. Becauselog10(0)is undefined, the script filters to positive doses (concentration_nM > 0) for the logistic fit after inspecting the vehicle baseline.
None of these choices is wrong on its own. What breaks preclinical reporting is making one silently and handing a medicinal chemist a single number without showing the sensitivity check.
Copyable Python code from the verified notebook
This is the exact fitting block executed in Cell 4 of ic50_dose_response_verified.ipynb. Save dose_response_assay.csv in the same folder and run it directly:
import hashlib
import numpy as np
import pandas as pd
from scipy.optimize import curve_fit
csv_path = "dose_response_assay.csv"
sha = hashlib.sha256(open(csv_path, "rb").read()).hexdigest()[:12]
df = pd.read_csv(csv_path)
print(f"File: {csv_path} | Rows: {len(df)} | SHA-256: {sha}")
def four_pl(log_c, bottom, top, log_ic50, hill):
return bottom + (top - bottom) / (1.0 + 10.0 ** ((log_c - log_ic50) * hill))
def three_pl_zero_bottom(log_c, top, log_ic50, hill):
return top / (1.0 + 10.0 ** ((log_c - log_ic50) * hill))
summary = []
for comp, g in df.groupby("compound"):
g_pos = g[g["concentration_nM"] > 0].copy()
g_pos["log10_c"] = np.log10(g_pos["concentration_nM"])
# Unconstrained 4PL (all points)
popt, pcov = curve_fit(
four_pl, g_pos["log10_c"], g_pos["viability_pct"],
p0=[5.0, 100.0, np.log10(50.0), 1.0],
bounds=([0.0, 70.0, -2.0, 0.2], [50.0, 120.0, 5.0, 4.0]),
maxfev=10000
)
se = np.sqrt(np.diag(pcov))
resid = g_pos["viability_pct"] - four_pl(g_pos["log10_c"], *popt)
r2 = 1.0 - np.sum(resid**2) / np.sum((g_pos["viability_pct"] - g_pos["viability_pct"].mean())**2)
summary.append({
"compound": comp, "model": "4PL (all points)",
"IC50_nM": round(10.0 ** popt[2], 2),
"CI95_low": round(10.0 ** (popt[2] - 1.96 * se[2]), 2),
"CI95_high": round(10.0 ** (popt[2] + 1.96 * se[2]), 2),
"Bottom_pct": round(popt[0], 2), "Top_pct": round(popt[1], 2),
"Hill": round(popt[3], 2), "R2": round(r2, 4)
})
# Sensitivity 1: Fix Bottom = 0%
popt0, _ = curve_fit(
three_pl_zero_bottom, g_pos["log10_c"], g_pos["viability_pct"],
p0=[100.0, np.log10(50.0), 1.0], maxfev=10000
)
summary.append({
"compound": comp, "model": "Bottom fixed at 0%",
"IC50_nM": round(10.0 ** popt0[1], 2),
"CI95_low": np.nan, "CI95_high": np.nan,
"Bottom_pct": 0.0, "Top_pct": round(popt0[0], 2),
"Hill": round(popt0[2], 2), "R2": np.nan
})
# Sensitivity 2: Exclude residual outlier (> 3 SD of residuals)
z_resid = np.abs(resid) / resid.std(ddof=1)
outliers = g_pos[z_resid > 3.0]
if len(outliers) > 0:
g_clean = g_pos[z_resid <= 3.0]
popt_c, pcov_c = curve_fit(
four_pl, g_clean["log10_c"], g_clean["viability_pct"],
p0=[5.0, 100.0, np.log10(50.0), 1.0],
bounds=([0.0, 70.0, -2.0, 0.2], [50.0, 120.0, 5.0, 4.0]),
maxfev=10000
)
se_c = np.sqrt(np.diag(pcov_c))
resid_c = g_clean["viability_pct"] - four_pl(g_clean["log10_c"], *popt_c)
r2_c = 1.0 - np.sum(resid_c**2) / np.sum((g_clean["viability_pct"] - g_clean["viability_pct"].mean())**2)
summary.append({
"compound": comp, "model": f"4PL (excl {len(outliers)} outlier)",
"IC50_nM": round(10.0 ** popt_c[2], 2),
"CI95_low": round(10.0 ** (popt_c[2] - 1.96 * se_c[2]), 2),
"CI95_high": round(10.0 ** (popt_c[2] + 1.96 * se_c[2]), 2),
"Bottom_pct": round(popt_c[0], 2), "Top_pct": round(popt_c[1], 2),
"Hill": round(popt_c[3], 2), "R2": round(r2_c, 4)
})
print(pd.DataFrame(summary).to_string(index=False))
Note two practical details in the bounds passed to curve_fit. Keeping bottom between 0.0 and 50.0 and top between 70.0 and 120.0 prevents optimizer divergence on noisy plates while still letting incomplete inhibition curves settle at their true lower plateau. The full matplotlib plotting cell is included in ic50_dose_response_verified.ipynb.
Clean-start Verify proof
Every number in this post comes from a clean-start execution of ic50_dose_response_verified.ipynb on Python 3.14.7, numpy 2.5.5, pandas 3.1.1, scipy 1.18.1, and matplotlib 3.11.2, reading dose_response_assay.csv with SHA-256 prefix 13bfe2996e69.
In Dalliance, one-click Verify restarts Python from scratch, reruns every cell in order with zero AI calls, and flags any cell whose output changed. Every save pins package versions and data file fingerprints inside a standard .ipynb file on your Mac or Windows machine, with zero desktop telemetry. Because raw files stay local and saved cells rerun without an AI call, your IC50 tables keep reproducing even if you run out of credits or cancel your subscription. Dalliance does not offer a HIPAA BAA today, so keep your work focused on wet-lab, preclinical, genomics, biostatistics, and de-identified assay data.
Run this recipe on your own plate CSV
Download Dalliance on Starter for $0 to get 100 one-time credits on verified email sign-up with no credit card required, enough for about one 6-to-8-cell analysis on Claude Sonnet 5.5, with saved notebooks rerunning locally for free forever. Need regular monthly analysis across models from 18+ providers? Pro Annual is $199/year with two months free, 1,000 credits per month, rollover up to a 2,000-credit cap, and a single Polar PDF invoice for grant or department reimbursement.