Full text
id177582 IMPROVING FITNESS WITH DATA CARLA MIQUEL BLASCO Thesis supervisor: DENNISREIDSMA(UniversityofTwente) Tutor:SILVERIOJUANMARTÍNEZFERNÁNDEZ(DepartmentofServiceandInformationSystem Engineering) Degree:Bachelor'sDegreeinDataScienceandEngineering Thesis report Facultat d'Informàtica de Barcelona (FIB) Escola Tècnica Superior d'Enginyeria de Telecomunicació de Barcelona (ETSETB) Facultat de Matemàtiques i Estadística (FME) Universitat Politècnica de Catalunya (UPC) - BarcelonaTech
Improving fitness with data Iwouldliketoexpressmysincerethankstoallthepeoplewhohavecontributedsignificantly to the development and completion of my thesis. First of all, I would like to thank my supervisors, Silverio Martinez and Dennis Reidsma, for their invaluable guidance, ideas, suggestions and constant support throughout the process. Their expertise and dedication have been fundamental to the success of this project. I would also like to extend my thanks to the University of Twente for providing me with the opportunity to conduct my thesis from the Netherlands. This international experience has been enriching and has contributed significantly to my academic and personal development. Iamdeeplygratefultoallthepeoplewhogenerouslysharedtheirdata,thusallowingthe validation and application of my research. Your collaboration has been fundamental for obtaining reliable and relevant results. Last but not least, I would like to express my gratitude to my family. Your unconditional support, encouragement and understanding throughout this process have been of great importance to me. Your constant presence has given me the strength and motivation to overcome challenges and achieve my goals. To all of these people, my sincere thanks. Without your contribution, this achievement would not have been possible. I am deeply grateful for your support and confidence in me. Carla Miquel Blasco 2 UPC & UT
Improving fitness with data Contents 1 Introduction & Goal 6 2 Related work 7 3 Requirements of the project 8 4 Proposed solution 9 4.1 ML model creation pipeline ............................. 9 4.1.1 Obtaining the data .............................. 10 4.1.2 Finding suitable model ............................ 15 4.2 ML system ....................................... 16 4.2.1 Prediction of the future physical condition ................. 17 4.2.2 Visualizing relevant insights ......................... 17 5 Validation 17 5.1 Results with my own data .............................. 18 5.1.1 Analyze the cleaned data ........................... 18 5.1.2 Metrics of the model ............................. 22 5.2 Results with other’s data ............................... 24 6 Discussions and future work 26 7 Appendix 29 7.1 Example of my results ................................ 29 7.1.1 Main page ................................... 29 7.1.2 Prediction ................................... 30 7.1.3 Visualization ................................. 31 7.2 Correlation with all features ............................. 33 Carla Miquel Blasco 3 UPC & UT
Improving fitness with data The project consists of an ML-based web application. All the code and project documents can be found at the following GitHub link: GitHub The deployed application can be found in the following link: Application The credentials for singing in and visualizing the test results with my own data are the following: •User: CarlaMiquelBlasco •Pasword: abc My database1that I have used as a sample to develop the application can be found in the following link: Dataset.csv 1Access to the database is restricted to persons with UPC mail domain. Carla Miquel Blasco 4 UPC & UT
Improving fitness with data Abstract As an individual who has collected training activity data through Strava and Garmin APIs over the years, a substantial database has been amassed containing valuable information that has the potential to enhance performance and achieve athletic goals. Through personal observation, it has been recognized that optimizing training is not solely about exerting maximum e↵ort daily or pushing the body to its limits. Instead, a balanced routine encompassing various training types and appropriate rest periods is crucial. While these observations are based on personal intuition, it is reasonable to assume that patterns exist within the aforementioned database, enabling the inference of current physical condition and the development of an optimal training routine geared towards personal performance improvement. Furthermore, like any extensive database, this dataset contains latent information that can be further explored and comprehended through visualizations and analytical techniques. Leveraging the power of data science, it is possible to delve deeper into the data, uncovering trends, patterns, and correlations that may not be immediately apparent. Such insights can then be employed to adjust training regimens and fine-tune approaches to cater to individual needs more e↵ectively. Carla Miquel Blasco 5 UPC & UT
Improving fitness with data is defined for each activity as a Gaussian distributed number between 1-10 the mean of which depends on the activity type, and the sigma is maxmin 4. Similar to the outlier removal technique, the clustering of activity types is also considered. For this reason, the mean of the performance for each activity type is defined taking into account the following scaled and normalized parameters: •Mountain biking: Distance, ElapsedTime, AverageHeartRate, AverageSpeed, TotalAscent, MovingTime, Calories, MaximumAltitude. •Road biking: Distance, ElapsedTime, AverageHeartRate, AverageSpeed, TotalAscent, MovingTime, AveragePower, Calories, MaximumAltitude. •Spinning: ElapsedTime, AverageHeartRate, AveragePower, Calories. •Running: Distance, AverageHeartRate, AverageSpeed, ElapsedTime, MovingTime, TotalAscent, Calories, MaximumAltitude. •Weight training: Calories, ElapsedTime, AverageHeartRate, MaximumHeartRate, MovingTime. It is worth to say that only the key features that are relevant and accurate are used. This means that any features that have been poorly registered, contain errors or have missing values (NaN) are not used in the calculation. Furthermore, there are some features in the dataset that essentially contain the same information. For example, the elapsed time and time, total ascent and total descent, or average heart rate and maximum heart rate, among others. In these cases, only one of these features is used in the calculation of the performance feature. Note that the performance calculation is defined as a random number following a Gaussian distribution with a mean and a variance. Thus, because of the variance, the value inferred may di↵er somewhat. To overcome this uncertainty and to ensure credibility of the data, the final result is the average of 20 runs. At the end, my cleaned database with the calculated performance looks like the following: Figure 2: Cleaned data Labeling the data: Grouping and comparing Many athletes follow a weekly or bi-weekly training routine. As far as I am concerned, I have always followed a weekly routine. Therefore, I have grouped the original dataset by weeks, computing the average of all the features, along with the performance that has already been defined. This has allowed me to label the data by comparing consecutive weeks. Carla Miquel Blasco 12 UPC & UT
Improving fitness with data The resulting label can be positive, negative, or a maintenance training routine. A positive label indicates that future performance is likely to be higher than the current performance, a negative label suggests a decline in future performance, and a maintenance label implies that future performance is expected to remain stable. To accomplish this, I have used the following criterion for labeling the weekly grouped dataset: •If the average performance of the following week (i+1) is within +-0.25 of the average performance of the current week (i), then the label for the current week is maintenance training routine. if avg(perf[i]) 0.25 < avg(perf[i+1])< avg(perf[i]) + 0.25 )Maintenance •If the average performance of the following week (i+1) is higher than the average performance of the current week (i) plus 0.25, then the label for the current week is positive training routine. if avg(perf[i+1])> avg(perf[i]) + 0.5)P ositive •If the average performance of the following week (i+1) is less than the average performance of the current week (i) minus 0.25, then the label for the current week is negative training routine. if avg(perf[i+1])< avg(perf[i]) 0.5)Negative Labeling the data: Improvement In summary, there are three main steps for labelling each week: 1. Calculate the performance for each activity record (remember that the performance is the result of averaging 20 executions). 2. Group the data by weeks by averaging each feature, including the performance. 3. Compare one week with the next to label the weekly grouped dataset. Note that the label depends on the performance and, as the performance calculation has a variance, in some cases the label can still be ambiguous. To solve this uncertainty, I have executed these three steps 5 times, so that the final label is defined as follows: •If there is more than one positive label and more than one negative label among the 5 runs, the week is defined as ambiguous and removed from the dataset. •If there are more positive labels than maintenance, and there are 1 or less negative labels among the 5 runs, then the week is defined as positive. •If there are more negative labels than maintenance and there are 1 or less positive labels among the 5 runs, then the week is defined as negative. •Otherwise, the week is defined as maintenance. Carla Miquel Blasco 13 UPC & UT
Improving fitness with data To better understand and visualise this labeling, at the end of the 5 executions we obtain a table which stores the label for each of the executions, the sum of each result, and the final label: Note that each final label is the result of executing 5 times the three steps mentioned Figure 3: Labels earlier in this section. Accordingly, since the first step involves computing the performance, which is calculated as the average of 20 runs, the ultimate outcome for each week requires 20x5 calculations of performance for each activity. Although it is a bit time-consuming, this way I ensure the credibility of the labels. Generate new data: Balancing the dataset It is possible that, after the data labeling process, the resulting dataset may be unbalanced, meaning that one class of data (positive, negative or maintenance) may be significantly overrepresented compared to the others. This can negatively a↵ect the performance of the model because it can bias the model towards the majority class, making it less e↵ective at predicting or classifying the minority classes. In order to resolve this problem, I have generated additional data for the original database. As a result, since the weekly grouped dataset is obtained from this original database, new data has also been incorporated into the grouped dataset. It is worth noting that the performance is not produced anew, but is inferred as before, hence also the label. Consequently, to guarantee that the resulting label for each newly generated week corresponds to the minority classes, I have employed the following oversampling technique: The system starts by randomly choosing one of the two minority classes. Then, taking this choice into account, it generates three training activities for the corresponding week with the following specifications: •Activity type: A random choice. •Date: The dates of the new generated activities are defined as a Saturday, a Thursday or a Tuesday of the week before the minimum generated so far. For instance, taking into account that the minimum date of my original data is 15 June 2019, the activities of the Carla Miquel Blasco 14 UPC & UT
Improving fitness with data first week generated will be on 08, 06 and 04 June 2019; Similarly, the activities of the second week generated will be on 01 June 2019 and 30 and 28 May 2019. •Other features: They follow the distribution of the values from the original dataset, taking into account the activity type and whether activities are being generated for one or the other minority class. Finally, the newly generated data is added to the original database, which is grouped by weeks and labeled following the same specifications as previously described. Although this process is repeated until a balanced dataset is obtained, typically the weekly dataset is balanced after the first attempt using this technique. In my particular case, the initial dataset included 65 maintenance weeks, 44 positive weeks, and 53 negative weeks. After generating additional data, the resulting dataset contains 71 maintenance weeks, 77 positive weeks, and 78 negative weeks. Obtaining the data: Latency improvement Thus far, the system has cleaned the original dataset, grouped it by weeks, labeled the grouped dataset, and balanced it. While this process may be somewhat time-consuming, the results are saved, and the steps required to achieve these results are stored in the cache. This way, the application never needs to repeat this process. Additionally, both the cleaned original and the cleaned weekly grouped dataset can be downloaded from the application. 4.1.2 Finding suitable model The aim of the model is to classify the current week as positive, negative or maintenance, without knowledge of the following week. For this, I have used the previously detailed dataset grouped by weeks to train a supervised ML model. Since there exist many possible classification models, the application tests 5 di↵erent models for training. In addition, each model is trained twice: the first time with all parameters and the second time with the 10 most important parameters according to the result of the first training. The models used are Logistic Regression, SVM, KNN, Decision Tree, Random Forest and Naive Bayes. In addition, before the training process begins, the system includes additional parameters in the database that I deemed potentially useful for the model: •Count: The total number of activities done during the week. •Month: The number of the month corresponding to the week. •Year: The year corresponding to the week. •Other counts: Extra feature for each type of activity that indicates the number of activities of that type performed during the week. The process of training is stopped when a suitable model is found. This means, a model that meets user-specified metrics. Then, the system shows the resulting metrics to the user and give them the chance of storing the model for further use. Finally, the results are deployed online, with the open-source app framework Streamlit. Carla Miquel Blasco 15 UPC & UT
Improving fitness with data 4.2 ML system Once the data pipeline has been run, a system is created so that the user can use the trained model in order to infer their future physical condition taking into account their last week training routine. The system also includes a section for visualizing relevant insights in the data. To do this, both the model and the clean databases are stored in the AWS bucket. Specifically, each user has his own folder within AWS. In addition, the Streamlit web framework is used in order to deploy the system and interact with the user. I have chosen AWS S3 because it has a free plan, and o↵ers a highly scalable, secure and durable cloud storage service. It provides a reliable solution for storing and accessing large volumes of data, o↵ering high availability and file durability. On the other hand, I have chosen Streamlit because is a web deployment framework that o↵ers simplicity, efficiency and integration capabilities for rapid development of interactive, data-driven applications. Its simple syntax and ability to reflect real-time changes streamlines the development process. In addition, it easily integrates with popular Python libraries and o↵ers customization options. Streamlit facilitates deployment in local or cloud environments, freeing developers from managing the underlying infrastructure. Figure 4: Architecture Diagram Carla Miquel Blasco 16 UPC & UT
Improving fitness with data 4.2.1 Prediction of the future physical condition The background for this focuses on two primary tasks. Firstly, it reads and cleans the new data submitted by the user. Then, it uses this data along with the saved model to forecast the user’s physical condition and label each new week. To read the data provided by the user, the application presents a customizable table with the necessary fields to be completed. Additionally, the table displays informative messages about the metrics that need to be used to ensure accurate reading of the data. This table is created using an experimental table widget from Streamlit, which permits the user to modify any data they want. Once the modifications are made, the data is converted into a Pandas DataFrame for processing and undergo cleaning, including steps such as data type treatments and the calculation of the performance for each recorded activity. Finally, the cleaned dataset is grouped by weeks, and the previously saved model is used in order to predict the label for each new week. The results that are displayed are the following: •Gauge chart: Altair visualization that displays the percentage of the user’s current performance in comparison to their maximum and minimum values stored in the data. •Label: Prediction made by the model indicating whether the user’s training routine has been positive, negative, or maintenance in terms of his/her future performance. •Recommendation messages: Based on statistical analysis of all the historical data. These messages take into account the di↵erences between the training of the current week and similar trainings of past weeks where higher performance was achieved. Currently, there are eight possible recommendation messages that can be displayed The user has the option to save their submitted data by clicking on the save button. This action immediately appends the new data to the original dataset. This is useful because as the original dataset becomes sufficiently increased, the user can return to the main page and use the saved data training option to retrain the model with the new and improved dataset. This process will likely result in a model with better metrics. 4.2.2 Visualizing relevant insights The background of this page uses previously saved data to create interactive visualizations using Altair. Streamlit widgets are also utilized in the application to enable user interaction and to produce personalized charts. To create certain charts, additional features such as the name of the month are incorporated into the dataset. Whenever new data is saved, the charts are automatically refreshed. 5 Validation In order to validate the results of the application, I firstly used my own data. Then, I tested the application with the data of other people who voluntarily accepted to participate in the project. These individuals signed a consent form and provided me with their data to use in the application. Subsequently, I validated the corresponding results by interviewing them. Carla Miquel Blasco 17 UPC & UT
Improving fitness with data 5.1 Results with my own data 5.1.1 Analyze the cleaned data Firstly, I have implemented a clustering analysis to verify that the data is, indeed, distributed according to the activity type. To do so, I have applied a PCA + KMEANS technique to reduce the dimensionality and generate the clusters. The results are the following: Figure 5: K-means As we can see, the separation between the 5 activity types is clear. Thus, the existence of the five sub-groups of data is not only a result of intuition, but is proven. For this reason, I have worked with the data taking into account this separation at all times. To continue, I have analysed each of the parameters separately for each activity type. The results are as follows: Mountain biking Carla Miquel Blasco 18 UPC & UT
Improving fitness with data Road biking Spinning Carla Miquel Blasco 19 UPC & UT
Improving fitness with data Weight training Running As we can see, there are some issues in some registered values. For instance, it makes no sense that there are negative values in the minimum and maximum temperature of some spinning activities; also, there are extremely negative temperatures in road and mountain biking. Additionally, if we look at the null values, we only see them in some parameters of Spinning and Weight training. Finally, if we look at the performance feature, we see that the mean, maximum and minimum values for each activity type are very similar. Thus, although calculated on the basis of di↵erent features, the result is fair and well distributed. Carla Miquel Blasco 20 UPC & UT
Improving fitness with data To continue, in order to get a more detailed understanding of the database and the performance calculation, I have analysed the correlation of all features with the performance. The result is as follows: Mountain biking Road biking Spinning Weight training Running With the above images we can see that even though the performance is inferred from the rest of the features, it has not a strong linear correlation with them. This means that the performance provides extra information. On the other hand, taking into account the correlations of all the features with all the features, we see that there are indeed some features that have a strong linear correlation. This information is very useful because it allows us to know that we can reduce the dimensionality of the data without losing information. The full heatmap can be found in the appendix, yet the most important linear correlations are the following: Carla Miquel Blasco 21 UPC & UT
Improving fitness with data References https://docs.streamlit.io https://docs.aws.amazon.com https://platform.openai.com/docs/guides/classifications https://scholar.google.es/scholar/classification/models/supervised/models/AI/documentation https://docs.github.com/es https://github.com/CarlaMiquelBlasco/SportsAnData/settings/keys https://www.overleaf.com/learn https://www.deepl.com/translator https://www.advancedinstaller.com/user-guide/qa-deploy-python-script.html https://www.v7labs.com/blog/ai-in-sports https://www.thats-ai.org/en-GB/units/ai-in-sports https://www.infront.sport/blog/sports-technology/revolutionising-sports-with-ai-the-use-cases- challenges-and-future https://www.utwente.nl Sports Anlytics review Science and Sports analytics Carla Miquel Blasco 28 UPC & UT
Improving fitness with data 7 Appendix 7.1 Example of my results 7.1.1 Main page Figure 9: Main page where users can upload their data. Then, this data is processed and used for finding a classification ML-supervised model that meets the requirement metrics specified by the user. Carla Miquel Blasco 29 UPC & UT
Improving fitness with data 7.1.2 Prediction Figure 10: Prediction page where users can report their last week training routine. This information is the input of the pre-trained model. Then, the results are displayed. Carla Miquel Blasco 30 UPC & UT
Improving fitness with data 7.1.3 Visualization Figure 11: Visualization section where users can see the evolution of their performance over years with an interactive graph. Figure 12: Visualization section where users can interactive graphs about the total amount of activities, and the amount of an specific numerical features. Carla Miquel Blasco 31 UPC & UT
Improving fitness with data Figure 13: Visualization section where users can see the correlation analysis between two numerical features, and the distribution analysis of one specific feature. Carla Miquel Blasco 32 UPC & UT
Improving fitness with data 7.2 Correlation with all features Carla Miquel Blasco 33 UPC & UT
Improving fitness with data Carla Miquel Blasco 35 UPC & UT