# Analysing Social Media Discourse on Electric Vehicles with Machine Learning
## 3 Materials and Methods
### Deep Learning  
The LSTM model was selected due to its superior performance in processing sequential data and its ability to capture long-term dependencies in text. Compared to traditional machine learning models, LSTM provides higher accuracy in sentiment classification tasks, particularly in short-text formats like tweets. It is also more effective in handling contextual variations and temporal dependencies, which are essential for understanding opinion trends in social media content. Sentiment analysis is an important natural language processing (NLP) method used to identify emotional tendencies in text. Although traditional machine learning algorithms produce successful results to a certain extent, deep learning models offer higher accuracy rates when the complexity of text data and contextual relationships need to be considered. In this context, the long short-term memory (LSTM) model is one of the most widely used deep learning architectures in sentiment analysis, especially for its ability to process sequential data [46; 51]. LSTM is an improved version of the RNN (recurrent neural networks) architecture. Traditional RNNs are used to make sense of text context by processing past information. However, RNNs are not able to preserve historical information in the long term due to the vanishing gradient problem. LSTM has a special cell structure to solve this problem and can learn long-term dependencies. This feature is a great advantage in tasks where context is important, such as sentiment analysis [52; 53]. The main components of LSTM are the following [54]:  
* Forget Gate: Determines how much of the previous cell state is kept or forgotten. \[\mathrm{f_{t}}=\sigma(\mathrm{W_{f^{\prime}}}[\mathrm{h_{t-1}},\mathrm{x_{t} }]+\mathrm{b_{f}})\] (1)
* Input Gate: Determines how much of the existing entrance will be added to the new cell state. \[\mathrm{i_{t}}=\sigma(\mathrm{W_{i^{\prime}}}[\mathrm{h_{t-1}},\mathrm{x_{t} }]+\mathrm{b_{i}})\] (2)
* Cell Status Update: New information candidate is created by tanh activation. \[\mathrm{\overset{\sim}{C}_{t}}=\mathrm{tanh}(\mathrm{W_{c^{\prime}}}[\mathrm{h _{t-1}},\mathrm{x_{t}}]+\mathrm{b_{C}})\] (3)
* Output Gate: Determines which part of the cell state is output. \[\mathrm{o_{t}}=\sigma(\mathrm{W_{o^{\prime}}}[\mathrm{h_{t-1}},\mathrm{x_{t} }]+\mathrm{b_{o}})\mathrm{h_{t}}=\mathrm{o_{t}}\cdot\mathrm{tanh}(\mathrm{C_{t }})\] (4)  
In the equations above, \(\mathrm{x_{t}}\) is the input vector at time step \(\mathrm{t}\); \(\mathrm{h_{t-1}}\) is the hidden state from the previous step; \(\mathrm{W_{f}}\), \(\mathrm{W_{i}}\), \(\mathrm{W_{o}}\), and \(\mathrm{W_{c}}\) are the respective weight matrices; \(\mathrm{b_{f}}\), \(\mathrm{b_{i}}\), \(\mathrm{b_{o}}\), and \(\mathrm{b_{c}}\) are the bias terms; and \(\sigma\) denotes the sigmoid activation function. LSTM models learn the context between words by sequentially processing text in sentiment analysis. This process consists of data preprocessing, model training, and prediction. First, in the data preprocessing stage, the text data are cleaned, tokenisation is applied, stop words are removed, and the text is converted into digital format by word embeddings to make it suitable for the model. Then, in the model training phase, the LSTM model is trained with the labelled dataset to learn sentiment classes such as positive, negative, and neutral. In this phase, the model evaluates contextual relationships between words by learning to capture long-term dependencies in sequential data. Finally, in the prediction and classification phase, when new texts are given to the model, it analyses the context to determine the emotional content of the text and classifies it into the relevant sentiment category. Through this process, LSTM-based sentiment analysis models can detect emotional tendencies in texts with high accuracy [55; 56]. The LSTM model used in this study consists of a single-layer bidirectional LSTM with 128 hidden units. A dropout rate of 0.3 was applied after the LSTM layer to preventoverfitting.