No Data Scientists? No Problem. Forecast with AI in Seconds!

No Data Scientists? No Problem. Forecast with AI in Seconds!

Forecasting is no longer just for data scientists. Whether you're a developer building a sales dashboard or a marketer optimizing campaigns, JigsawStack's Prediction API lets you make accurate forecasts on time-series data with zero training required. 🚀

In this guide, we’ll show you how to use the Prediction API, best use cases, and why it’s a must-have for modern workflows.

What is the Prediction API?

The Prediction API leverages powerful generative LLM models trained on over 100 billion data points to provide quick and accurate time-series forecasts.

Why it’s awesome:

  • No training or fine-tuning needed.

  • Works with missing data points.

  • Scalable for datasets with millions of entries.

  • Results in seconds.

Let’s showcase this by forecasting departure delays (in minutes).

Getting Started

Install the SDK

Get started by installing the JigsawStack SDK:

npm install jigsawstack

Prepare Your Dataset

Your dataset can be in one of two forms: a direct JSON array or a CSV file. Let’s explore both options. We will be using this JSON and CSV files for the example below.

Your JSON array should include two values: date and value. For example:

const dataset = [
    { date: "2008-01-03", value: 353459 },
    { date: "2008-01-04", value: 313734 },
    { date: "2008-01-05", value: 333774 },
    { date: "2008-01-06", value: 348636 },
    { date: "2008-01-07", value: 278903 }
];

Make Predictions

Use the Prediction API to forecast future values. The array must contain at least 5 elements.

import { JigsawStack } from "jigsawstack";

const jigsawstack = JigsawStack({ apiKey: "your-api-key" });

const result = await jigsawstack.prediction({
  dataset: [
    { date: "2008-01-03", value: 353459 },
    { date: "2008-01-04", value: 313734 },
    { date: "2008-01-05", value: 333774 },
    { date: "2008-01-06", value: 348636 },
    { date: "2008-01-07", value: 278903 }
  ],
  steps: 3, // Number of future predictions
  columns: "date,value"
});

Output

{
  "success": true,
  "prediction": [
   { "date": "2008-01-10 00:00:00", "value": "315214.5625" },
   { "date": "2008-01-09 00:00:00", "value": "320094.71875" },
   { "date": "2008-01-08 00:00:00", "value": "316329.9375" }
],
  "steps": 3
}

Preparing Your CSV

Your CSV file should include two columns: date and value. For example:

date,value
2008-01-03,353459
2008-01-04,313734
2008-01-05,333774

CSV Example

Here’s how you can use the API to parse the CSV and make predictions:

import fs from "fs";
import Papa from "papaparse";
import { JigsawStack } from "jigsawstack";

const schema = {
  datasetPath: "your_file.csv", // Path to your local CSV file
  steps: 10, // Number of steps for predictions
  columns: "date,value", // Columns in your CSV file
};

const runPrediction = async (schema) => {
  try {
    // Read the local CSV file
    const csv = fs.readFileSync(schema.datasetPath, "utf-8");

    const { data, errors } = Papa.parse(csv, {
      delimiter: csv.includes("\t") ? undefined : ",",
      header: true,
    });

    if (!data.length) throw new Error("Invalid CSV file");
    if (errors.length) console.error("CSV import errors", errors);

    const [dateKey, valueKey] = schema.columns.split(",").map((col) => col.trim());

    const dataMapped = data.map((row) => ({
      date: row[dateKey],
      value: row[valueKey],
    }));

    const jigsawstack = JigsawStack({ apiKey: "your-api-key" });

    const result = await jigsawstack.prediction({
      dataset: dataMapped,
      steps: schema.steps,
      columns: schema.columns,
    });

    console.log("Prediction result:", result);
  } catch (error) {
    console.error("Error during prediction:", error.message);
  }
};

// Call the function with the local CSV file path
runPrediction(schema);

Output

{
  success: true,
  prediction: [
    { "date": "2008-11-21 00:00:00", "value": "306051.375" },
    { "date": "2008-11-22 00:00:00", "value": "301501.21875" },
    { "date": "2008-11-23 00:00:00", "value": "324348.40625" },
    { "date": "2008-11-24 00:00:00", "value": "372875.28125" },
    { "date": "2008-11-25 00:00:00", "value": "301101.9375" },
    { "date": "2008-11-26 00:00:00", "value": "288880.125" },
    { "date": "2008-11-27 00:00:00", "value": "324649.15625" },
    { "date": "2008-11-28 00:00:00", "value": "330629.6875" },
    { "date": "2008-11-29 00:00:00", "value": "325092.15625" },
    { "date": "2008-11-30 00:00:00", "value": "364174.34375" }
  ],
  steps: 10
}

Real-World Applications

In this example, we used historical departure delay data to predict delays with both JSON and CSV datasets. No time to set it up? Try it yourself here! This approach is versatile enough to support a range of time series scenarios, such as forecasting inventory demands for the holiday season in e-commerce and enhancing SaaS analytics by predicting subscription renewals.

Other applications include anticipating transport delays, estimating foot traffic for retail locations, and creating financial forecasts for budgeting and planning. No matter your goals, following a few best practices can help you get the most out of your predictions.

Best Practices

Start Simple: Test small datasets first to verify results before scaling.

Handle Missing Data: The Prediction API works seamlessly even with incomplete datasets, saving you cleanup time.

Optimize Steps: Choose the appropriate prediction window based on your use case (daily vs. monthly forecasts).

👥 Join the JigsawStack Developer Community

Need help with your time series data or have cool use cases to share? Join the conversation on Discord or X.

With JigsawStack’s Prediction API, the future is yours to forecast—no Ph.D. required. Let’s build something amazing together! 🚀