TuringBot offers a great library for running Symbolic Regression in Python. The API allows the search to be fully customized. Here we will show how to install, load, and use this library to turn your data into formulas.

## Installing & Loading TuringBot

TuringBot is easy to use and installation is painless.

The first step is downloading the program (for free) from the official website: Download.

Once you have the program installed, you can load its Python library by first appending the installation directory to your search path. This is how to do that in WIndows:

# Windows version import sys sys.path.insert(1, r'C:\Users\user\AppData\Local\Programs\TuringBot') import turingbot as tb import time

And this is a Linux example:

# Linux version import sys sys.path.insert(1, '/usr/share/turingbot') import turingbot as tb import time

After importing TuringBot, you will be set to create your Symbolic Regression optimization.

## Symbolic Regression in Python with TuringBot

Creating a Symbolic Regression optimization using TuringBot’s library is very easy. The search is called as a method of a simulation() object:

sim = tb.simulation() sim.start_process(path, input_file, threads=4, config=config_file) time.sleep(10) sim.refresh_functions() print(*sim.functions, sep='\n') print(sim.info)

After the start_process() method is called, the optimization is started in the background, and you can get the current best list of formulas using the refresh_functions() method.

The output will look something like this, with formulas shown along with their sizes and errors:

[1, 177813.0, '186276'] [3, 7890.39, '11.7503*x'] [5, 6895.25, '11.9394*(-472.889+x)'] [7, 1769.0, '(10.4154+3.9908e-05*x)*x'] [11, 1666.42, '(9.10666+3.26179e-05*x)*(1.156*(-93.3986+x))'] [21, 1224.31, '-1624.3+((9.18774*sign(x-10.1264)+3.13847e-05*x)*(1.1586*(-158.606+x)))']

The full description of the parameters that you can provide to the start_process() method can be found on the Documentation: Running TuringBot from Python. The error metric, base functions, etc of the search can all be defined by providing the program with a simple settings file.

Note that you can evaluate all of these functions, which are in string format, by using Python’s native eval function:

x = 1 eval('(10.4154+3.9908e-05*x)*x')

## Conclusion

Symbolic Regression is a method to predict the hidden structure of a dataset without any assumptions on what the model should look like. By having good algorithms for solving symbolic regression problems, it is possible to build highly predictive machine learning models. TuringBot offers an easy way of running symbolic regression from Python.