CreateSimpleSearchΒΆ

Build a model to forecast sales and build an analysis in Eureqa that displays the results.

The example datasource includes weekly metrics for Sales along with marketing spend in various channels, website activity, and weather data.

Create a connection to Eureqa:

from eureqa import Eureqa

e = Eureqa(url="https://rds.nutonian.com", user_name="user@nutonian.com",
           key="JA24SZI94AKV0EJAEVPK")

Create a data source:

data_source = e.create_data_source("Sales & Marketing", "sales_marketing.csv")
<eureqa.data_source.DataSource instance at 0x00000000042F24C8>

Download sales_marketing.csv.

Create a search. The goal is to forecast Sales using all other variables in the datasource. The time series template default settings will work well for this search:

variables = set(data_source.get_variables())
target_variable = "Sales"
settings = e.search_templates.time_series("Sales Forecast", target_variable,
                                          variables - {target_variable})
search = data_source.create_search(settings)

Submit the search and wait until the search is done:

search.submit(30)
search.wait_until_done()

Get the best solution. Eureqa identifies the solution that gives the best trade-off between error and complexity:

solution = search.get_best_solution()
print("The best model found is:\n %s = %s" % (solution.target, solution.model))
The best model found is:
 Sales = 109569817.15572 + 1055.11588490586*delay(Emails_Sent, 1) + 1.0544595112534*wma(delay(Avg_Temp, 1), 2)*max(wma(delay(Web_Total_Visits, 1), 3), delay(Online_Ad_Spend, 1))

Get the model performance:

print("The %s value for this search is %.2f" % (solution.optimized_error_metric,
                                                solution.optimized_error_metric_value))
The R^2 Goodness of Fit value for this search is 0.79

Create an analysis that summarizes the results:

analysis = e.create_analysis("Sales Forecasting Model",
                             "This model forecasts sales for next week.")
analysis.create_model_summary_card(solution)
analysis.create_model_fit_by_row_plot_card(solution, title="Model Fit with Sales Forecast",
                   description="View the predicted value for next week by positioning
                                           your mouse over the yellow predicted value.")
analysis.create_model_card(solution, title="Model Details",
                 description="Use the interactive model mode to see how predicted Sales
                           changes as the model inputs change.")
<eureqa.analysis_cards.model_card.ModelCard at 0x4629668>
Log into Eureqa to view and interact with the resulting analysis!