Predict Gold Prices using MindsDB

Alissa T
3 min readOct 9, 2022

By Alissa Troiano

Joshua Sortino Unsplash
Photo Credits: Joshua Sortino, Unsplash

Introduction

In this tutorial, we will use MindsDB’s sophisticated automated predictor to create and train a machine learning model that forecasts the value of gold using historical data.

Setup

If you’d like to follow this tutorial, you can use the MindsDB Cloud Editor (create your free MindsDB Cloud account here) to create and train your prediction model. You may also download the dataset we will be using, gold_price_data.csv, from Kaggle.

Let’s get started!

Step 1: Import Data to MindsDB

Fire up your MindsDB Cloud Editor and click ‘Add Data’.

mindsdb cloud editor

Next, select the “Files” tab.

MindsDB Import Files

Click on “Import File” to upload the .csv file from your device. (Note: You may also use the URL Import link).

Step 2: Preview The Dataset
Now that you’ve imported the dataset, let’s use SQL to preview its contents.

SHOW TABLES FROM files;
SELECT * FROM files.gold_price_data
LIMIT 10;

Step 3: Create The Predictor
Here comes the fun stuff. Now we are going to create and train our custom predictor!

CREATE PREDICTOR mindsdb.gold_value_predictor
FROM files
(SELECT * FROM gold_price_data)
PREDICT gold_value;

Let’s break this down:

  • To initiate our model, we use the CREATE PREDICTOR statement.
  • Next, we specify the columns of the table that we want to trainFROM you may think of these as features
  • Finally, we declare what we want our model to PREDICT you may think of these as labels

Step 4: Check Predictor Status
It may take a few minutes for your predictor to finish training. Go ahead and run this command to see if it’s done:

SELECT status
FROM mindsdb.predictors
WHERE name=’gold_value_predictor’;

Upon initial execution, you may see training
or complete.

Do not proceed until your output reads complete! (If you are stuck with an output that reads, ‘generating’ for an extended period of time, you may have made an error somewhere).

Step 5: Make Predictions
Now that your model has finished training, let’s start making predictions! The SQLSELECT statement allows us to make predictions based on our input variables & input columns.

Our imported historical dataset provides the value of gold from 1970–2020. Before we time-travel, let’s see what our predictor does if we input a date that’s included in our gold_price_data dataset:

Nice! It looks like our predictor has taken the average gold value for 1988

Now, let’s predict the value of gold in 2024:

Let’s fast-forward to 2090:

CONCLUSION

With that last step, we have successfully created and trained a machine learning model to make future predictions based on historical data!

As can be seen in this tutorial, MindsDB makes machine learning simple, intuitive, and extremely effective! Do you have something interesting you’d like to forecast? Head to MindsDB and start training your model today!

--

--