# An Application to Predict Range of Electric Two-Wheeler Using Machine Learning Techniques
## 3 Materials and Methods
### Data Analysis and Preparation  
We have sorted out the dataset from the stored raw data in this phase of the experiment. Although our stored data contained data collected in a trip for every second, we have converted the data such that one trip became one instance. Firstly, we converted the battery level data we collected from the rider. We observed that the range can differ based on the initial battery state. Moreover, it was observed that, while the initial battery level was 80-100%, the range provided by e-mobility is higher, while the last 20% provides less range than other states. Based on our observation, we have categorized the initial battery levels into five categories, named A, B, C, D, and E, ranging from 80 to 100%, 60 to 79%, 40 to 59%, \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Category** & **Data** & **Input by User** & **Collected Every Second** \\ \hline \multirow{2}{*}{Two-Wheeler} & Initial Battery Level & Yes & No \\  & Remaining Battery Level & Yes & No \\ \hline \multirow{2}{*}{Environmental} & Weather & No & No \\  & Temperature & No & No \\ \hline \multirow{2}{*}{Route} & Location & No & Yes \\  & Elevation & No & Yes \\ \hline \multirow{2}{*}{Rider Behavior} & Distance & No & Yes \\  & Time & No & No \\ \cline{1-1}  & Speed & No & Yes \\ \hline \hline \end{tabular}
\end{table} 
Table 3: List of data collected from each trip. 20 to 39%, and 0 to 19%, respectively. Subsequently, we converted the final battery level to total battery consumption by using the following formula:  
\[Battery_{con}=Battery_{init}-Battery_{final} \tag{1}\]  
Although different studies have shown the impact of environmental factors coming into play for range prediction and we are collecting the environmental data for each trip, we could not use the data in our study, as the environmental data were almost constant in every single case. Therefore, we have omitted the data from our final dataset, since the impact from them will be nonexistent. Subsequently, we have also omitted the location data, as they have no factor to play in the range prediction either. In our next step, we determined the elevation gain for the entire trip. Since we have the elevation data for every second, we needed to ascertain the total for the entire trip. To perform the calculation, we used the following Formula (2):  
\[Elev_{gain}=\sum_{i=2}^{n}Elev_{i}-Elev_{i-1}[(Elev_{i}-Elev_{i-1})>0] \tag{2}\]  
where \(n\) is the number of elevations in a trip. Finally, we have converted the speed data into three fields, namely, total acceleration, total deceleration, and total stop time. In order to achieve this feat, we calculated acceleration and deceleration from the speed data of every second at first. Then, we counted the number of times a rider accelerated and decelerated in a single trip. Furthermore, the total stop time was calculated based on the number of times speed went to 0. The following formulas were used for such calculations:  
\[Speed_{diff}=Speed_{curr}-Speed_{prev} \tag{3}\]  
\[Acc_{total}=|A|\text{, where }A=\left\{x:xeSpeed_{difference},\ x>0\right\} \tag{4}\]  
\[Dec_{total}=|B|\text{, where }B=\left\{x:xeSpeed_{difference},\ x<0\right\} \tag{5}\]  
\[Stop_{total}=|C|\text{, where }C=\left\{x:xeSpeed_{current},\ x=0\right\} \tag{6}\]  
Furthermore, the distance recorded was in meters, as it was collected every second from the previous position to the new position in order to clearly represent the actual travel distance rather than the distance provided by the APIs. The summation of said distance was then converted into kilometers to be included in the final dataset. \[Dist_{total}=\frac{\sum_{i=1}^{n}dist_{i}}{1000} \tag{7}\]  
where \(n\) is the number of instances in stored data. As explained in Section 3.1, each specific two-wheeler in our database is assigned a Unique ID (named \"UE_ID\" in storage) that is created by combining the specific user's information with the technical information of the specific two-wheeler.