ml-symbolic-regression

Classical MLgplearnrigorous codebase

Description

Symbolic Regression: GP Search Strategy

Objective

Design and implement a better genetic programming search strategy for symbolic regression. Your code goes in custom_sr.py. Three reference implementations (Standard GP, Parsimony GP, Lexicase GP) demonstrate different approaches.

Background

Symbolic regression discovers mathematical expressions that fit data. Genetic programming evolves a population of expression trees through selection, crossover, and mutation. Key challenges include balancing exploration vs exploitation, controlling expression complexity (bloat), and escaping local optima. Different approaches address these through fitness shaping, novel selection mechanisms, or improved genetic operators.

Evaluation

Tested on three standard symbolic regression benchmarks: Nguyen-7 (univariate transcendental), Nguyen-10 (bivariate trigonometric), Koza-3 (univariate polynomial). Metric: R² on held-out test set (higher is better).

Code

custom_sr.py
EditableRead-only
1#!/usr/bin/env python3
2"""Symbolic Regression via Genetic Programming.
3
4A self-contained GP framework for symbolic regression benchmarks.
5The editable section contains the search strategy: fitness function,
6selection, crossover, mutation, and per-generation evolution logic.
7"""
8
9import argparse
10import math
11import random
12import sys
13import os
14import numpy as np
15

Additional context files (read-only):

  • gplearn/gplearn/genetic.py
  • gplearn/gplearn/_program.py
  • gplearn/gplearn/fitness.py

Results

ModelTypetest r2 nguyen7 test r2 nguyen10 test r2 koza3
lexicase_gpbaseline0.9470.5480.912
parsimony_gpbaseline0.9860.8090.996
standard_gpbaseline0.3300.5880.993
anthropic/claude-opus-4.6vanilla0.9910.9030.985
deepseek-reasonervanilla0.9300.6170.963
google/gemini-3.1-pro-previewvanilla0.9960.7720.971
openai/gpt-5.4vanilla0.9951.0000.981
qwen/qwen3.6-plusvanilla---
qwen/qwen3.6-plusvanilla---
qwen/qwen3.6-plusvanilla---
anthropic/claude-opus-4.6agent0.9910.9030.985
deepseek-reasoneragent0.9300.6170.963
google/gemini-3.1-pro-previewagent0.9900.8600.995
openai/gpt-5.4agent0.9931.0000.992
qwen/qwen3.6-plusagent---
qwen/qwen3.6-plusagent---
qwen/qwen3.6-plusagent---

Agent Conversations