I am a beginner in ML and I want to create a smart thermostat, that after collecting enough data from the interaction with the user, it will start to set the home temperature by itself.

What I got so far is the hardware prototype that lets the user set the temperature, and in the same time it posts the Environment and the UserSetTemperature to ThingSpeak (to easily store the data for later access)

The other part is a python algorithm that gets the data from ThingSpeak and it converts it into a Pandas DataFrame.

The data frame looks like bellow:

timeStamp                      environment_temp    user_set_temp  

2018-05-27T00:12:43Z               20            21              
2018-05-27T00:17:27Z               20            22                 
2018-05-27T00:17:59Z               20            24                
2018-05-27T00:20:01Z               20            21                  
2018-05-27T00:23:14Z               20            24                 
2018-05-28T09:39:07Z               20            22             
2018-05-28T10:40:17Z               20            23               
2018-05-28T20:12:47Z               20            25              
2018-05-28T20:14:16Z               23            25               
2018-05-30T20:29:30Z               18            24  

And here is where I got stuck. I don't know how to use this data with the ML libraries in order to make predictions on how the temperature should be set when the environment temperature is x.

I tried to use the sklearn train_test_split() and LinearRegression(), but with no significant result. I really don't know how to use this data

Every suggestion will be highly appreciated!!

  • $\begingroup$ Is this sample data from your reading or fake/ dummy data ? $\endgroup$ Jun 10, 2018 at 2:03
  • $\begingroup$ it is data from the device, but is a little hardcoded, because I allowed the prototype to post even if the temperature was not correct. In the future I am planning to use real and correct data $\endgroup$ Jun 10, 2018 at 6:52
  • $\begingroup$ Why do you think that the environment temperature will be useful in predicting the user's choice of temperature? What relationship do you expect them to have? Have you tried visualizing your data to see if there seems to be a relationship between environment_temp and user_set_temp? between day of the week and user_set_temp? between time of day and user_set_temp? The first step is always to "look at the data". $\endgroup$
    – D.W.
    Jun 10, 2018 at 20:01
  • 1
    $\begingroup$ @EmanuelGiurgiu I would not recommend to go ahead with current data. but if you can get hold of local weather data for the timestamps in your data then below recommended procedure would be beneficial. $\endgroup$ Jun 11, 2018 at 3:15

4 Answers 4


I would not recommend going ahead with the data that you know might be wrong.

Looking at your current data, the reason you got a bad result with linear regression is because the relation between them is not linear for the current data. For eg. There is high variation in response (i.e. user_set_temp) for same value of your predictor (i.e. environment_temp).

First, get hold of correct temperature for your recorded timestamps from local weather data to replace environment temp with this data, till you get the issue rectified with your original recorded environment_temp. When you rectify the issue, then I would recommend you to use both weather and environment temp to predict, as a person might set the temperature depending upon a combination of both.

After you get a good representative data, this should be a reasonable procedure to help you predict the temperature:

  1. Exploratory data analysis for uni-variate timeseries: This will help you observe patterns in data, which will help you decide on which new features to engineer/ create from timestamps (step 2) you have of recordings. Also, look at the acf/ pacf plots to help figure out the lags in data that might help you predict better. Fit a basic uni-variate model like STL or ARIMA model to get a good base model for prediction (this model you will compare new models with to see how they perform)

  2. Feature Engineering: Time of day, day of week, week of month etc identified in step 1. Also, look for any other features that might help your algorithm find patterns.

  3. Regression Models: Test with advanced algorithms like RandomForest, Gradient Boosting and RNN-LSTM to check how they perform against each other and the base model.


I would highly recommend using Recurrent Neural Networks for your purpose, because of their demonstrated ability to forecast time series, due to their inherent memory.

A perfect tutorial for your purposes can be found here. I am sure it will help you a lot :)


In my opinion a RNN is too computational heavy. You have to run it on a cloud service or on a GPU.

Furthermore I think that based in the environment temperature you can not predict the wanted temperature by the user. You would need additional data such as humidity, because you have to learn how the user feels the temperature and this depends on several factors. If this aren't fake data, you can obviously see that there is no correlation. And it seems that you only record the environment temperature when the thermostat temperature changes. This is not enough for predicting.

If you don't have any additional data I would suggest that you calculate the gradient of the temperature change over a specific time, as well.

If you have more data I would suggest to start with plotting the data nicely to get an impression. Then I would try a multiple linear regression and a Perceptron or a multi layer Perceptron.


Let's consider :

t : timeStamp
x : environment_temp
y : user_set_temp 
  1. It would be helpful if you test your data to see if it comes from stationary process o not. The t should play a significant role in predicting y. So, if you want a good prediction model you should keep and use this information alongside with x.

  2. You have a time-series, so you should consider a time-window(w): w=1 is when you only use current (t,x) for setting current y. If you choose w=10, this means that you use 10 past observations of (t,x) for predicting current y. So, you can create a new dataset for training your model based on the chosen window size: a matrix(size $M\times W$) as your data and a vector(size $M$) as the labels.

  3. Currently, the best choice for working with such data might be ConvNet or LSTM. Look at this blog post. This is not a high-dimensional data and you can find and fit a model which is not so heavy for running on an edge device.

Finally, the sampling rate is also very important. Are you collecting data minute-by-minute or you recording data just when the user changes temperature? It is important because we usually name the former case "time-series" and the latter case "sequential" data. Techniques are some-time different for each case.

  • $\begingroup$ The data is collected each time the user sets a new temperature $\endgroup$ Jun 11, 2018 at 10:08
  • $\begingroup$ @EmanuelGiurgiu: So, it is trickier now. I suggest you build a matrix contains both t and x and use LSTM. You can also decompose 't' into subfeatures like season day, hour, ... : Look at this: bit.ly/2JwACgS and this: bit.ly/2JwA4HQ . Will help you very well to understand how to work with seq. data. $\endgroup$
    – Mo-
    Jun 11, 2018 at 11:20

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