Open-source project
trevorstephens/gplearn avatar
trevorstephens/gplearn

gplearn: Symbolic Regression With a scikit-learn Style Estimator API

Genetic Programming in Python, with a scikit-learn inspired API

1,887 stars324 forksPythonBSD-3-Clause

At a glance

What is it?
gplearn wraps genetic programming in a fit/predict interface and restricts itself to symbolic regression, binary classification and feature transformation. The API is familiar; the search underneath is stochastic and the parameter surface is wide.
Who is it for?
Adopt gplearn when you need an inspectable mathematical expression rather than a black-box prediction, and when you are willing to tune a stochastic search. Do not adopt it as a drop-in replacement for linear or gradient-boosted models on high-dimensional tabular data, since the search cost grows with the number of features and the result is not reproducible without fixing the random state.
Can I use it commercially?
Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 32 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

The Problem gplearn Targets: Expressions, Not Just Predictions

Most regression libraries return coefficients or a fitted function you cannot read. gplearn returns a formula. The README states that symbolic regression aims to identify an underlying mathematical expression that best describes a relationship, starting from a population of naive random formulas and evolving successive generations by selecting the fittest individuals for genetic operations. That output is the point: an expression you can write on a whiteboard, hand to a domain specialist, or embed in a simulation without shipping a model artifact. The audience is therefore narrow by design. The README says gplearn is purposefully constrained to symbolic regression, motivated by the scikit-learn ethos of having estimators that are straightforward to implement. If you want a general genetic programming toolkit that evolves arbitrary programs, this is not it. If you want a readable equation from tabular inputs, it is aimed squarely at you.

Three Estimators and What Each One Evolves

The package exposes three classes. SymbolicRegressor handles regression. SymbolicClassifier handles binary classification. SymbolicTransformer performs automated feature engineering, producing transformed features; the README states it is designed to support regression problems but should also work for binary classification. The transformer is the least obvious of the three and the most useful in a pipeline: it evolves expressions that become new columns, which you can then feed to a conventional estimator. Because all three follow the scikit-learn estimator contract, they compose with Pipeline and GridSearchCV. That composition is the real integration story here. You are not adopting a separate framework with its own fit loop and its own cross-validation helpers; you are adding three estimators to a library you already use. The cost of that choice is that anything scikit-learn cannot express, such as a custom evolutionary schedule or a non-standard selection operator, is not reachable through the public API.

The Evolutionary Loop Behind fit()

The mechanism described in the README is a generational loop. An initial population of random formulas is constructed to represent the relationship between independent variables and the target. Each successive generation is evolved from the previous one by selecting the fittest individuals and subjecting them to genetic operations. Fitness, selection pressure and the genetic operators are all parameterised, and the README is direct about the consequence: there are a lot of parameters to tweak, and reading the documentation should make the more relevant ones clear for your problem. That sentence is doing real work. It is an admission that the defaults are a starting point, not a tuned configuration, and that the useful subset of parameters depends on the dataset. Nothing in the supplied material specifies default population sizes, generation counts, parsimony coefficients or the operator set, so treat any figure you see elsewhere as unverified until you read the parameter reference at gplearn.readthedocs.io.

Installation and the scikit-learn Version Constraint

gplearn is distributed on PyPI, which is where the version badge in the README points, so the normal installation path is pip install gplearn. The README gives one hard prerequisite: gplearn is built on scikit-learn and a fairly recent copy is required for installation. That is a dependency constraint, not a suggestion. Because the estimators inherit scikit-learn's conventions, they are sensitive to changes in that library's internals, and the README directs users to the installation page for specifics rather than pinning a number in the main text. Check that page against your environment before upgrading scikit-learn in a project that already depends on gplearn. There is no separate command-line tool and no service to run; the entire surface is the three estimator classes imported from the package.

Where the Approach Breaks Down

The first limitation is intrinsic to the method: the search is stochastic. Two runs with different random seeds can land on different expressions with similar fitness, and nothing in the README promises otherwise. For a result you intend to publish or ship, you need to control the seed and accept that the expression is one of several plausible fits. The second limitation is dimensionality. Genetic programming explores a space of formulas over your input variables, and that space grows with the number of columns, so a wide feature matrix is a poor fit even though the API accepts it. The third is the parameter surface itself. A library that tells you to read the documentation to find the relevant parameters is telling you that out-of-the-box results may be mediocre and that tuning is part of the job. Finally, SymbolicTransformer is documented as designed for regression and only expected to work for binary classification. If your target is multiclass, the README gives you no support for that case.

gplearn Against a Gradient-Boosted Baseline

The obvious alternative for tabular regression is a boosted tree ensemble such as those in scikit-learn or XGBoost. The difference is not accuracy on a leaderboard; it is what you get back. A boosted model returns a set of split points and leaf values that you can inspect only indirectly, and its predictions are bounded by the training distribution. gplearn returns a closed-form expression in your original variables, which extrapolates according to the structure of that expression rather than according to observed ranges. That is a genuine advantage when the relationship is physical or mechanistic and you expect to evaluate it outside the sampled region. It is also a genuine hazard, because an evolved expression can extrapolate confidently and wrongly. The honest framing is that these tools answer different questions: one asks what predicts best, the other asks what the relationship looks like. If you only need the first, the boosted baseline is cheaper to run and easier to defend.

Maintenance, Releases and Licence Terms

The release history shows 0.4.2 in May 2022 and 0.4.3 in January 2026, with repository activity as recent as August 2026. That gap is the maintenance story: this is a low-churn project that receives occasional releases rather than continuous development, so pin your version and read the release notes before moving between them. The licence is BSD-3-Clause, a permissive licence that allows use in proprietary software provided the copyright notice and licence text are retained. That is a summary of the identifier, not legal advice; if you are redistributing gplearn inside a commercial product, have your own counsel confirm the notice requirements. The practical upgrade cost is tied to scikit-learn: because gplearn tracks that library's estimator conventions, a major scikit-learn upgrade is the event most likely to force a gplearn upgrade, not a gplearn release by itself.

Who Should Install It, and What to Check First

Reach for gplearn when the deliverable is an equation. Scientific modelling, sensor calibration, and feature construction where an interpretable transform beats a raw column are the cases the README describes. Skip it when you need multiclass classification, when your feature count is large, or when you need bit-for-bit reproducible training across machines without managing seeds. The first thing to verify is not the model quality but the environment: confirm your scikit-learn version against the installation page, since the README makes a recent copy a requirement. The second is a sanity check on a problem whose answer you already know, so you can see how many generations and what population size it takes before the evolved expression resembles the true one. That experiment tells you more about whether gplearn suits your data than any parameter list will.

Editorial conclusion

Adopt gplearn when you need an inspectable mathematical expression rather than a black-box prediction, and when you are willing to tune a stochastic search. Do not adopt it as a drop-in replacement for linear or gradient-boosted models on high-dimensional tabular data, since the search cost grows with the number of features and the result is not reproducible without fixing the random state. Before committing, verify three things: that the scikit-learn version you have installed satisfies the installation requirements, that SymbolicRegressor recovers a known expression on a small synthetic dataset you construct yourself, and that the fitted program's size and runtime are acceptable for your inference path.

Official sources

  1. License: BSD-3-Clause
  2. Project website
  3. README
  4. Releases
  5. trevorstephens/gplearn on GitHub
Community notes

Community notes