# Learn Data Science for Business

## Become a Data Scientist in our online courses

Earn 6 figures or more in 6 months or less by learning R, Shiny, Machine Learning, Time Series, Web Apps, AWS, Cloud, and more!

5-10 Hours Per Week.  80/20 Skills.  End-To-End Business Projects.

[Start Your Courses Now! 👉](https://university.business-science.io/p/5-course-bundle-machine-learning-web-apps-time-series?el=website)

Join over 100,000+ Data Scientists

# How to use ChatGPT for Time Series in R

_Written by Matt Dancho_

* * *

Writing R code is a **slow process** especially when you are first learning Time Series Analysis. _What if you could speed it up?_ You can and this is how. In this free R-tip, I share a real case study where I made the working R code for my time series analysis and **saved over 3 hours of work using ChatGPT**.

### Table of Contents

Today I share how to automate 80% of your Time Series Analysis code with `ChatGPT`. Here’s what you’re learning today:

- _ChatGPT Prompts:_ The mistakes you’ll make and how to get ChatGPT to write your time series analysis code correctly.
- _2-Minute Case Study:_ How I made a time series analysis with `ChatGPT`.
- **Bonus: Sneak Peek At My NEW Shiny App that extends this ChatGPT tutorial** 👇

# Using ChatGPT for Time Series in R

I’m going to be fully transparent here. **ChatGPT is NOT 100% with Time Series yet.** It got me 80% of the way there. BUT the last mile, I actually had to know time series.

To help, I want to give you some pointers.

# ChatGPT Prompt Guide for Time Series

The mistake I made when I first started using ChatGPT was **not being specific** enough in directing `ChatGPT` what R code I want it to write for me. [I’ve since learned from this.](/content/code-tools/2023/04/30/chatgpt-prompt-osmdata.html)

Here’s a good starter chatgpt prompt for my time series problem:

Looks pretty straightforward, but it’s actually quite complex. Let’s break it down.

The key is specifying:

1. **Which R Libraries to Use**: I specified to forecast using the `modeltime` library. Full Disclosure: I’m the creator. But, it _IS_ awesome for time series.
2. **What Time Series Goal**: For my time series project it’s to forecast. Other time series problems might involve exploratory plotting, anomaly detection, or decomposition.
3. **What Inputs to the Time Series Problem**: For this time series project, I want to forecast initially the next 30 days (the forecast horizon) and it’s a daily time series data set with 2 columns: date and value.

And ChatGPT generates the code for me:

# Does the code work?

A big problem that data scientists are facing is that `chatgpt` code isn’t working out of the box.

So let’s test the code. I ran it, and it turns out…

# ChatGPT has Hallucinations

It didn’t run. What happened is so common people have termed it “ChatGPT Hallucinations”.

Yep, chatgpt makes stuff up. And this is why it’s important to know how to code.

# The reality: You need to know how to code and do time series

Fortunately, I’ve been doing this a while. And I just had to debug the code.

1. ChatGPT wrote the code **(15 Seconds)**
2. I debugged the code **(10 minutes)**

# BONUS: I asked ChatGPT to make a Shiny App to Forecast with Modeltime

I asked ChatGPT to make a Shiny App using my corrected code. _Making a shiny app is a task that would have taken me 3+ hours._

**Total Time Savings: 3 hours 30 minutes**

# Big Problem: You still need to learn how to do Time Series

If you learn one thing from this tutorial, it better be that ChatGPT isn’t the full solution. It’s a productivity enhancement. As you just saw, I completed 4 hours of work in under 30 minutes.

**Would you like help?** Here’s how I can help you become a data scientist and land a 6-figure job you love and learn how to use ChatGPT better ( **all for free**).
