Today, I wanted to mess around with time series forecasting, so I picked up darts. I’ve heard good things about it, and it seemed like a good opportunity to see what all the fuss is about. Plus, I needed something to forecast some sales data I’ve been playing with.
First things first, I had to get darts installed. It was pretty straightforward, just a simple pip install darts in my terminal. Then, I loaded up my data. It’s your typical CSV file, with dates and sales figures. Nothing fancy.
Data Loading and Preprocessing
After importing the necessary libraries, I used pandas to read the CSV file into a DataFrame. I noticed that the date column was being read as a string, so I had to convert it to a proper datetime format using *_datetime. Data always needs a bit of cleaning, right?

- Import libraries
- Load data
- Convert date column to datetime format
Then came the time to use darts. I created a TimeSeries object from my DataFrame using *_dataframe. I specified the time column and the value column, and just like that, I had my time series data ready for action. It’s surprisingly simple once you get the hang of it.
Model Training
Now, for the fun part – picking a model. Darts has a bunch of them, but I went with a basic ExponentialSmoothing model for starters. I initialized the model and then called the fit method, passing in my TimeSeries object. The training was quick, which was a pleasant surprise. No coffee break needed this time.
- Choose a model (ExponentialSmoothing)
- Initialize the model
- Train the model using the fit method
Forecasting
With the model trained, I wanted to see how it performed. I used the predict method to generate a forecast for the next 30 days. Darts spits out a new TimeSeries object representing the forecast. I was curious, so I plotted both the historical data and the forecast to see how they lined up. Not bad for a first try, the forecast seemed to capture the general trend pretty well.
- Use the predict method to generate a forecast
- Plot the historical data and the forecast
Of course, I didn’t stop there. I wanted to get a more concrete measure of the model’s accuracy. That’s where the backtesting feature in darts comes in handy. I performed a historical forecast using the backtest method, which essentially simulates making forecasts in the past and compares them to the actual data.
- Perform backtesting using the backtest method
- Compare actual data
The backtest gave me some error metrics, like the mean absolute percentage error (MAPE). It’s always good to have some numbers to back up your gut feeling about a model. The MAPE was a bit higher than I hoped, so I’ll probably need to do some more tweaking later.

All in all, it was a good day of experimenting with darts. The library is pretty user-friendly, and it has a lot of powerful features packed into a simple interface. I’m definitely going to keep exploring it and see how I can improve my forecasts. Maybe I’ll try some of those fancy deep learning models next time.
I was thinking about doing it next week. My friend Tom told me that it’s really powerful for sales.
This is today’s sharing, see you next time!