Linear best fit of temperature vs time

Hi, I am new to the arduino world and coding in general and I need some help with this project. I would like to measure the temperature from a K-type thermocouple and record a reading every half second or so. I am pretty sure I know how to do that, but I need to linearly best fit that data vs. time. My goal is to predict the temperature at a future time based on the trend. Any suggestions?

what you seem to be asking is that you want to have a control loop and to achieve a temperature.

is that a fixed temperature, like a thermostat ?

or, is that for a rising / lowering, like a ramp to temperature ?

also, how do you control the temperature ?
what are you heating ? a living space ? a kiln ? a device (coffee pot?)

as a note, when you add heat, it is only added locally, it takes time to spread out into the space. it is not uncommon to overshoot temperatures.

The math is fairly simple: Line of Best Fit (Least Square Method)

You will be limited by the number of samples you can keep in memory. You should only store the temperature values and generate the time values each time. Try to fit the temperatures in as small an integer as you can. What temperature range are you measuring?