0
$\begingroup$

I want to predict temperature when time (datetime type, hourly data for five months) and humidity is given. Before starting in python, I created a regression model in excel. But instead of predicting temperature, it gives date as an answer. On looking up the internet, I found that one can not do regression with datetime format. So some sources I looked upon have used datetime.toordinal() to convert dates to numerical Gregorian value. But my problem has date and time together. Will this method work with time too? If yes, how does it convert datetime? I need an efficient way to deal with datetime here, since it is vital in predicting the temperature being highly dynamic.

$\endgroup$
1
  • $\begingroup$ With temperature, yearly seasonality is to be expected. 5 months does not cover an entire year. There is a good chance your prediction model will not generalize outside of the 5 months of data that you have. Especially if the range of temperatures can be expected to be outside that of the dataset. $\endgroup$
    – Jon Nordby
    Mar 25, 2023 at 13:36

1 Answer 1

1
$\begingroup$

In order to run this regression you will have to encode the datatime column to a format a regressor can understand. When the granularity is large (e.g. daily or more) it can be done by simply adding an incrementing number to a 'time' column. A more rigorous way would be to extract features from the date, such as hour, day, and month. You can read more in this answer.

Note that as Jon stated, your model will not generalize well if there is a seasonal component to it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.