0

I need to predict temperature when time and humidity are given. Before starting in python, I created a regression model in excel. My data has time in datetime format [6/1/2022 0:00]. Instead of predicting temperature, it gives datetime as an answer.

On looking up the internet, I found that one can not do regression with datetime format. Some sources I looked upon have used

datetime.toordinal()

to convert dates to numerical Gregorian value (I didn't understand Julian vs Gregorian too). But my problem has date and time together. I need an efficient way to deal with datetime here, to feed into a regression model.

Scholar7
  • 11
  • 1
  • 1
    Get the time delta since a set point in time, such as POSIX uses the number of seconds since 1970-01-01 00:00:00 (See here for more: https://stackoverflow.com/questions/19801727/convert-datetime-to-unix-timestamp-and-convert-it-back-in-python) – MatBailie Mar 25 '23 at 16:38
  • There is no feature in the timedelta from a datum. You can't regress against a datum when you _know_ that weather is seasonal. – roganjosh Mar 25 '23 at 16:44
  • concerning the linked duplicate, see [datetime.timestamp](https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp) – FObersteiner Mar 25 '23 at 16:45
  • The dupe makes no sense for your purposes. The plan is misguided – roganjosh Mar 25 '23 at 16:46
  • @roganjosh temperature *might* have seasonality, but that strongly depends on the location – FObersteiner Mar 25 '23 at 16:47
  • But it's not on a monotonic scale if it _does_ have an impact – roganjosh Mar 25 '23 at 16:48
  • @roganjosh even if so, that's a question to meteorology, not programming I'd say. – FObersteiner Mar 25 '23 at 16:49
  • Not gonna disagree with that. The best bet would be to take the month mean temperature and display that. Why even have regression? – roganjosh Mar 25 '23 at 16:50
  • @roganjosh in general, I think you're right; [Convert Year/Month/Day to Day of Year in Python](https://stackoverflow.com/q/620305/10197418) is perhaps more appropriate. – FObersteiner Mar 25 '23 at 17:02
  • @roganjosh I am a beginner in regression analysis, so took up this project to know how to work with datetime variable data. Besides humidity it also has location info and building cover. I thought of predicting temperature by giving all these parameters at a date and time (which I understand would give correct answer only for date and time that is within the dataset). – Scholar7 Mar 25 '23 at 17:25
  • @FObersteiner Moreover I am thinking of taking hourly average over a month for all the seasons and do a regression with the other parameters. Any recommendations or suggestions for this? – Scholar7 Mar 25 '23 at 17:30

0 Answers0