Can we get datetime as an input variable?

조회 수: 3 (최근 30일)
Ayesha
Ayesha 2024년 9월 2일
편집: Luca 2024년 9월 6일
I’m trying to predict internal temperature using BPNN, NARX, ANFIS and LSTM models. Can I take ‘datetime’ as an input variable to the model because my target variable is ‘Internal Temperature’. I only consider winter data for this model. Please help me with this. I need to know whether I can take datetime as an input variable.

답변 (2개)

Anshuman
Anshuman 2024년 9월 2일
Yes, you can use 'datetime' as an input variable for your models, but you will need to preprocess it appropriately. Raw datetime values are not directly useful for most machine learning models. Here are few techniques to transform datetime into useful features:
  1. Extract Temporal Features: Break down the datetime into more granular components that can capture temporal patterns. For winter data, you might consider:
  • Hour of the day
  • Day of the week
  • Day of the month
  • Week of the year
  • Whether it's a weekend or a weekday
2. Cyclical Encoding: Since time has a cyclical nature (e.g., hours in a day, days in a week), you can use cyclical encoding to represent these features:
For hours:
  • hour_sin = sin(2 * π * hour / 24)
  • hour_cos = cos(2 * π * hour / 24)
Similarly, you can encode day of the week, month, etc.
3. Seasonality Indicators: Since you are focusing on winter data, you might want to create a binary feature indicating if the datetime falls within typical winter months for your location (e.g., December, January, February).
  댓글 수: 1
Ayesha
Ayesha 2024년 9월 3일
Hi Anshuman, thank you very much for the explanation you provided. It’s really help me to solve my problem

댓글을 달려면 로그인하십시오.


Zinea
Zinea 2024년 9월 3일
Hi Ayesha,
When predicting a time-dependent variable like internal temperature, especially with a focus on winter data, the ‘datetime’ feature can be quite informative. However, directly using raw ‘datetime’ values might not be optimal for models like BPNN, NARX, ANFIS and LSTM models. You should try extracting meaningful components from the ‘datetime’ feature to use as input as mentioned by Anshuman.
But in case you need to use ‘datetime’ as an input variable, you need to convert ‘datetime’ to numerical features to be used for prediction in models. The .CSV file named 'your_data.csv' storing the datetime values looks like this and is also attached:
You may refer to the following code for the conversion of 'datetime':
% Load data
data = readtable('your_data.csv');
% Convert DateTime to numerical features
data.DayOfYear = day(data.DateTime, 'dayofyear');
data.HourOfDay = hour(data.DateTime);
% Filter for winter data
% Assuming winter is defined as certain months, e.g., December to February
data = data(month(data.DateTime) == 12 | month(data.DateTime) == 1 | month(data.DateTime) == 2, :);
% Extract features and target
features = [data.DayOfYear, data.HourOfDay];
target = data.InternalTemperature;
You may refer to the following links for conversion from datetime to ‘day’ and ‘hour’ respectively:
  1. https://www.mathworks.com/help/matlab/ref/datetime.day.html
  2. https://www.mathworks.com/help/matlab/ref/datetime.hour.html
Hope this helps!
  댓글 수: 2
Ayesha
Ayesha 2024년 9월 3일
Hi,Thank you very much for your prompt response and valuable explanation
Luca
Luca 2024년 9월 6일
편집: Luca 2024년 9월 6일
Hi Ayesha!
Have you implemented LSTM on your project?
I am trying to make a LSTM network similar to yours, but mine has to predict the CO2 level within a structure and I need in input a datetime variable like yours but that considers even the minutes and whether it is a working day or not.
Could you share your model or give me some suggestions on how to do this?
I am new to neural networks and Matlab, it would be very helpful!
Thanks in advance!
P.s. This is my dataset, with lower values of CO2 during the weekend and a similar trend during the weekday

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by