Abstract
To reduce the resource and energy waste of colleges and universities more accurately and efficiently, this paper has developed a smart classroom data analysis system based on the Internet of Things, which realizes a variety of sensor information (temperature, humidity, smoke). Environmental parameters such as carbon dioxide concentration and light intensity), remote collection of equipment information, data storage and data analysis functions, and intelligent control of smart classrooms. Data analysis uses an improved LSTM model to predict energy consumption. The model uses LSTM and bidirectional LSTM and uses the ELU activation function instead of the sigmoid and tanh activation functions of the LSTM. Compared with the standard LSTM model and the LSTM model without the ELU activation function, the model improves the prediction accuracy, better avoid the gradient disappearance, and reduces the over-fitting. The system implementation results show that the system can effectively reduce school energy waste.
Introduction
In recent years, the Internet of Things has developed rapidly, and the agricultural Internet of Things, Industrial Internet of Things, and smart cities have also developed rapidly [1, 2]. Juan Juan and others developed a water quality monitoring system for aquaculture ponds by combining with the narrowband Internet of Things [3]; Wu Hui and others realized a farmland information collection system based on the Internet of Things model [4], which includes Information collection device, cloud server, mobile phone terminal, and PC terminal; Luo Le has realized a solar power generation monitoring system based on the Internet of Things [5]; Wang Dong et al. Library Internet monitoring system for WiFi Internet of Things [6]; Li Chao et al. Implemented a classroom intelligent energy-saving system based on WSNs and power carrier waves [7], which controlled the classroom to save energy by setting thresholds on sensors [8].
Although the data collected by the above applications of the Internet of Things are all-time series, they have not been analyzed in-depth [9]. As an important place for teaching tasks in colleges and universities, classrooms are also developing in a more intelligent and information-oriented direction. Compared with middle school classrooms, college classrooms are more open, so their corresponding classroom management needs are also stronger. Most colleges and universities lack the corresponding classroom resource management control system, and there is a serious waste of energy. Because the equipment in college classrooms is generally managed manually, energy waste caused by equipment forgetting to shut down in time often occurs [10].
In response to this situation, this article uses the Internet of Things architecture to build a smart classroom and a smart classroom data analysis system. Through real-time recording of classroom environmental data, equipment usage data, and time series analysis using LSTM models, and then predicting future energy consumption, thereby reducing energy waste.
The thesis is mainly divided into the following parts. First, the overall structure of the system is introduced in related work. In the part of neural network model construction, the advantages and disadvantages of LSTM and Bi-LSTM are analyzed first, as well as the influence of different activation functions on these two models, and then the improved LSTM model is proposed by adjusting the model structure. In the LSTM experiment and analysis part, the improved LSTM model was used to predict the classroom equipment and environmental data of the School of Information Technology, Shanghai Jianqiao University. The last part is to use this model to intelligently control classroom equipment, which can achieve a certain energy-saving effect.
Related Work
The smart classroom data monitoring system designed in this paper includes data collection, remote transmission, storage management, data monitoring, data analysis, and intelligent control functions. It implements distributed monitoring of smart classroom environment data and intelligent management of smart classroom equipment. The system consists of a four-layer structure such as perception layer, transmission layer, platform layer and application layer.
The perception layer is composed of smart classrooms, including single-chip computers, communication modules, power modules, various sensor modules, and equipment control modules. The transport layer is an intelligent gateway, which transmits uplink and downlink data through the intelligent gateway. The platform layer uses the cloud platform to perform operations on the database, receive processing results from the application layer, and pass device control data to the perception layer through the transmission layer. The application layer uses the data analysis system to obtain the equipment control results by acquiring data from the cloud platform, performing data visualization and data analysis. The overall system structure is shown in Fig. 1.

System structure diagram.
As shown in Fig 2, the Smart Classroom Data Analysis System was developed using Django, an open-source web application framework written in Python. The framework uses MTV (model, template, view) software design pattern, which can be used to develop database-driven websites easily and quickly. The system acquires data of the database from the cloud platform, and can perform real-time monitoring of classroom environment data, display classroom equipment status, and remote control. The acquired data uses a multi-layered improved LSTM model for energy prediction. Since the acquired classroom equipment data is a time series, LSTM is used here for energy consumption prediction. Finally, using data visualization, the data is displayed in the form of a line chart.

Smart Classroom Data Analysis system structure.
LSTM neural network model
LSTM [8–14] is a special RNN that can learn long-term dependency information. LSTM Structure is shown in Fig. 3. There is a hidden layer state similar to the original RNN in the LSTM structure [15], which is very sensitive to short-term inputs and adds a state C to maintain long-term memory. This state, also known as the cell state, records information that is passed over time. The cell state information is updated during the transfer process by the current input, the hidden layer state at the previous time, the cell state at the previous time, and the gate structure. The gate structure uses the sigmoid function to control the degree of update by taking values between 0 and 1. There are three gate structures in the LSTM network, namely the forgetting gate, the memory gate and the output gate. These three gates control the extent to which the state of the cell C is continuously preserved, the degree to which the state of the temporary cell is applied to the state of the cell, and whether the cell state is the output of the current hidden layer state.

LSTM Structure.
For the traditional form of genetic algorithm, we use, the whole computational process of the algorithm is centered on the individual [16–18]. The advantage of an individual computing center is that it is computationally fast and can reduce the number of
As shown, it x t is set to the current t-time input, C t is the cell state value at time t, and h t is the cell′s output.
σ is the sigmoid function, as shown in Equation 1. φ is the tanh function, as shown in Equation 2.
The update of the memory unit is divided into the following steps according to the gate structure.
(3) Forgetting gate calculation: f t represents the forgotten gate output at time t; [ht-1, x t ] represents the splicing of the two matrices into a matrix; W f and b f is the weight matrix and offset at time t-1, respectively item.
(4) Memory gate calculation: i t represents the memory gate output at time t; W i and b i is the weight matrix and offset term of the input gate at time t-1, respectively.
(5) Output gate calculation: o t is the output gate output at time t; W o and b o are the weight matrix and offset term of the input gate at time t-1, respectively.
(6) Temporary cell state calculation:
(7) Cell state calculation: C t is the cell state; the long-term state at time t-1 is multiplied by the forgetting gate output at time t, plus the product of the input gate output and the immediate state at time t.
(8) Hidden layer state calculation: h t is expressed as the hidden layer state output at time t; the output is determined by the output gate and the cell state.
Schuster et al. [14] proposed a bidirectional recurrent neural network model (BRNN). Compared with the RNN model, this model can enhance the processing ability of the subsequent data. The RNN model can only process data in one direction. A two-way recurrent neural network puts each training sequence into a recurrent neural network that can propagate forward and backward and connect it to the output layer. Bi-LSTM neural network model is a new model formed by combining two models of bidirectional RNN and LSTM. It replaces the cyclic unit in the classic two-way RNN model with LSTM [15, 16]. Compared with the standard LSTM model, using this method can better understand the long-term dependence of time series.
Figure 4 shows the bidirectional recursive network Bi-LSTM superposition of recursive layers in two different directions. The forward recursive layer starts from the initial moment, and the reverse recursive layer starts from the last moment.

Bi-LSTM Structure.
Equation 9 represents the forward propagation output, Equation 10 represents a backward propagation output, and Equation 11 represents the two-way propagation output. Among them, ϕ represents the LSTM structure,
During the training of LSTM, gradients may disappear and overfitting is likely to occur [17]. To avoid the problem of gradient disappearance, this article will forget the activation functions of gates, memory gates, output gates, and temporary unit states, hidden layers. The state activation function is replaced by the ELU activation function. The related expressions of the ELU function are as follows:
Among them, f (x) and f′ (x) are the original and derivative functions of ELU, respectively, and are the independent variables of the function [18, 19]. The ELU activation function combines the characteristics of smooth saturation on the left side of the sigmoid activation function and the linearity characteristics of the right side of the ReLU activation function [19]. The right side of the activation function is a linear part, making it have a mitigating effect on the disappearance of the gradient, and the soft saturation on the left side of the function can reduce its sensitivity to outliers and improve the robustness of the model [19]. The average value of the ELU output is close to zero, and the model can converge faster than the tanh activation function and sigmoid activation function.
Based on the improved LSTM model algorithm, the Bi-LSTM network is used to further learn and train the time series predicted by the previous LSTM network through the Dropout layer. The bidirectional LSTM model combines forward LSTM and reverse LSTM. Information, and the inverse LSTM obtains later information, which has the advantages of capturing data timing and long-range dependence [7], which can further improve the accuracy of prediction results.
The Improved LSTM energy consumption prediction algorithm flow is shown in Fig. 5 including the following steps:

Improved LSTM energy consumption prediction algorithm flowchart.
Step 1 Prepare the data. Get the data you need to predict from the cloud platform. The initial effective time series is calculated based on the energy consumption of multiple classrooms at the same time interval. This data uses the total daily energy consumption during the working day. By calculating the energy consumption of all equipment in the classroom during the working day, the calculation formula is: energy consumption = rated power * usage time. The data is in five columns, the first to fifth columns are the energy consumption from Monday to Friday, and each row represents the weekly energy consumption. As shown in Table 1.
Energy data format
Step 2 Normalize the data. Improve the model’s convergence speed and accuracy. Use 0-1 normalization to map the data so that the result is in the interval [0,1], as shown in Equation 14. Where max is the maximum value of the sample data and min is the minimum value of the sample data.
Step 3 Divide the sample set. Two consecutive samples (two rows of data) are taken as x, and the next third sample is taken as the label y. 30% of the samples were used as test sets and 70% were used as training sets.
Step 4 Use the improved LSTM for energy consumption prediction. Since the energy consumption changes periodically according to the season [21], the experiment uses short-term predictions. The training uses the Multiple Parallel method, that is, input is multiple sequences, and output is multiple sequences. This experiment uses two different LSTM structures. The difference between the two is that one of the models uses Bi-LSTM and the other uses standard LSTM. For these two different structures, their activation functions are respectively activated. A replacement of the ELU activation function was performed. The following steps use the Bi-LSTM layer as an example. Set the sequence length to len_seq, and then use the first len_seq-1 data to predict the data of the len_seq. The first layer is the LSTM layer. The input is the length and dimension of each input data, and the length and dimension of the output data are obtained through calculation. The second layer is the Dropout layer, which uses the Dropout layer to suppress 20% of neuronal activation, preventing local optimism. The third layer is the Bi-LSTM layer. The standard LSTM processes the sequence in chronological order, taking only historical information and ignoring future information. Therefore, using the bidirectional LSTM network to extract forward and reverse classroom energy consumption sequence information, The forward recursive layer begins with the initial classroom energy consumption time of the predicted period, and the backward recursive layer begins with the last classroom energy consumption time. The fourth layer is the LSTM layer and the fifth layer is the Dropout layer. The last layer is a fully connected layer, without the activation function. The minimum error is the stochastic gradient descent method (SGD).
Step 5 The trained model is used to predict the test set, and the predicted classroom energy consumption value is denormalized and an error analysis is performed with the real classroom energy consumption value.
Step 6 Display the real and predicted values using a line chart to observe the effect. Save the current model.
The specific structures of the two models are shown in Figs. 6 and 7.

Model structure diagram using Bi-LSTM layer.

Model structure diagram using only LSTM layer.

Bi-LSTM+ELU.
Experimental prediction results
The data used in this article is the classroom environment and equipment data of the School of Information Technology, Shanghai Jianqiao University from March to June, and July to October 2019. The specific prediction effect is shown in the figure below. Figure 8 shows the model using the Bi-LSTM layer and the ELU activation function, Fig. 9 shows the model using the Bi-LSTM layer and the default activation function, and Fig. 10 shows the LSTM model using the ELU activation function. Figure 11 shows a model using a standard LSTM.

Bi-LSTM.

LSTM+ELU.

LSTM.
The evaluation index uses the mean square error (MSE) to measure the prediction result, as shown in Equation 15. Where y
i
represents the true value and
After comparison, the classroom energy consumption errors for the next 15 working days are predicted to be 0.03931%, 0.04218%, 0.04651%, and 0.04926%, as shown in Table 2. The model using the Bi-LSTM layer has a smaller prediction error than the model without this layer, and the model using the ELU activation function has a smaller prediction error than the model without the ELU activation function. Since the change of classroom energy consumption itself has a certain periodicity, it is more suitable for prediction in the form of time series. The Bi-LSTM + ELU model can ensure better prediction accuracy.
Model prediction error table
Model prediction error table
Specific experimental process
As shown in Fig. 12, the intelligent classroom data analysis system reads the data uploaded by the sensor nodes of the perception layer to the database and uses the improved LSTM energy prediction method to train the model, that is, the model with the best experimental prediction performance (Bi-LSTM + ELU)), Save the trained model [26]. When using the device intelligent control function, first read the saved prediction model, obtain the state of the device at that time through the prediction model, and finally send the device state to the sensor nodes of the perception layer according to the time node.

Classroom intelligent control flowchart.
In this experiment, the monitoring data of the School of Information Technology of Shanghai Jianqiao University in September 2019 was selected. The sensor node upload period was set to 15 s. By recording two classrooms with similar courses, the recording time was September 14–18, 2019. The data analysis system was installed in one of the classrooms and the other was not. A comparison of power consumption is shown in Fig. 13. Compared with classrooms without this system, the average daily energy consumption of a single classroom is reduced by 23.41%, and an average of 32.32 kWh is saved.

Energy consumption graph.
This paper develops an IoT smart classroom data analysis system using improved LSTM. The system collects classroom data continuously and periodically through the nodes of the perception layer and uses an improved LSTM model to predict energy consumption. First use the classroom equipment to use the data to train an LSTM model, and use its output as the input of the next Bi-LSTM model, and then make further deep-level predictions. After a large number of experiments, it is verified that the algorithm is superior to the existing LSTM prediction methods in terms of accuracy, and the method is feasible and effective. After experiments, the system can reduce energy waste and has certain feasibility and practicability.
