<jupyter_start><jupyter_text>FormulaBot v1.02A MEP algorithm that solves for a formula that will match a training dataset.<NAME>October 10, 2020<jupyter_code>import math
import pandas as pd
import statistics
import time
from concurrent.futures import ProcessPoolExecutor
from formulabot.mep import *
from sklearn.metrics import mean_absolute_error, mean_squared_error
from sklearn.model_selection import train_test_split
from IPython.display import display, Markdown, Math
from tqdm import tqdm<jupyter_output><empty_output><jupyter_text>Problem 1:  Solve Pythagorean Theorem  Import Training Data<jupyter_code>df = pd.read_csv(r"C:\Users\markr\Projects\Software\FormulaBot\data\hypotenuse_01.csv")
X = df[['A','B']].to_dict(orient='records')
Y = df['out'].tolist()

X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33)<jupyter_output><empty_output><jupyter_text>Build Population<jupyter_code>p = Population(population_size=250, 
               parameters=list(df.columns[:-1]), 
               operations_size=10, 
               operands_size=20, 
               epochs=100, 
               crossover_rate=0.80, 
               mutation_rate=0.15, 
               kill_rate=0.20,
               error_calc=mean_squared_error,
               inputs=X_train, 
               outputs=y_train)<jupyter_output><empty_output><jupyter_text>Run Epochs<jupyter_code>p.run_epochs(plot_nb=True)<jupyter_output><empty_output><jupyter_text>Model Training Results<jupyter_code># print best solution
print("\nBest Solution is: ")
display(Math(p.get_best_solution().to_latex_string()))
print('\nBest Solution: ', round(p.get_best_score(), 7), '\nAvg Solution: ', round(p.get_avg_score(), 7), '\n')<jupyter_output>Best Solution is:<jupyter_text>Test Model Resutls<jupyter_code>best = p.get_best_solution()
best.compute(X_test[2])
pred = [m for m in map(best.compute, X_test)]
score = p.fitness_calc(y_test, pred)

p.plot_predictions(best, pred, y_test);
print('\nTest Score: ', score, '\n')<jupyter_output>Test Score:  3951.6427668298534
StarcoderdataJupyterStructuredCleanDedup