<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Kyrillos Ishak | UCSC OSPO</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/author/kyrillos-ishak/</link><atom:link href="https://deploy-preview-1007--ucsc-ospo.netlify.app/author/kyrillos-ishak/index.xml" rel="self" type="application/rss+xml"/><description>Kyrillos Ishak</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><image><url>https://deploy-preview-1007--ucsc-ospo.netlify.app/author/kyrillos-ishak/avatar_hu8f4700b1a96a053cd93e514df7e18caa_103379_270x270_fill_q75_lanczos_center.jpg</url><title>Kyrillos Ishak</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/author/kyrillos-ishak/</link></image><item><title>Understanding Data Leakage in Machine Learning: A Focus on TF-IDF</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240905-kyrillosishak/</link><pubDate>Thu, 05 Sep 2024 00:00:00 +0000</pubDate><guid>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240905-kyrillosishak/</guid><description>&lt;p>Hello again!&lt;/p>
&lt;p>This is my final blog post, and I will be discussing the second material I created for the 2024 Summer of Reproducibility Fellowship. As you may recall from my first post, I am working on the &lt;strong>Exploring Data Leakage in Applied ML: Reproducing Examples of Irreproducibility&lt;/strong> project with &lt;a href="https://deploy-preview-1007--ucsc-ospo.netlify.app/author/fraida-fund/">Fraida Fund&lt;/a> and &lt;a href="https://deploy-preview-1007--ucsc-ospo.netlify.app/author/mohamed-saeed/">Mohamed Saeed&lt;/a> as my mentors.&lt;/p>
&lt;p>This blog post will explore how data leakage can occur during feature extraction, particularly with the commonly used &lt;strong>TF-IDF&lt;/strong> vectorizer, and its impact on model generalization.&lt;/p>
&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>In machine learning, data leakage is a critical issue that can severely impact model performance. It occurs when information from outside the training dataset is improperly used to create the model, leading to overly optimistic performance during evaluation. One common source of leakage comes from how features, such as those extracted using &lt;strong>TF-IDF&lt;/strong> (Term Frequency-Inverse Document Frequency), are handled. In this post, we&amp;rsquo;ll explore how data leakage can happen during feature extraction with TF-IDF and how it affects model accuracy.&lt;/p>
&lt;h1 id="what-is-tf-idf">What is TF-IDF?&lt;/h1>
&lt;p>TF-IDF is a method used to evaluate how important a word is in a document relative to a collection of documents. It consists of two components:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Term Frequency (TF)&lt;/strong>: Measures how frequently a term appears in a document.&lt;/li>
&lt;li>&lt;strong>Inverse Document Frequency (IDF)&lt;/strong>: Reduces the importance of terms that appear frequently across many documents.&lt;/li>
&lt;/ol>
&lt;p>Together, they provide a weighted value for each word, reflecting its importance relative to the dataset.&lt;/p>
&lt;h1 id="how-data-leakage-occurs-with-tf-idf">How Data Leakage Occurs with TF-IDF&lt;/h1>
&lt;p>Data leakage with TF-IDF happens when the inverse document frequency (IDF) is calculated using the entire dataset (including the test set) before splitting it into training and test sets. This means the model has access to information from the test set during training, leading to artificially inflated results. This is a subtle form of data leakage, as it often goes unnoticed.&lt;/p>
&lt;p>For example, when calculating the TF-IDF score, if the word &amp;ldquo;banana&amp;rdquo; appears more frequently in the test set but is considered during training, the model downplays its significance. As a result, the model may fail to predict correctly when &amp;ldquo;banana&amp;rdquo; is important in the test data.&lt;/p>
&lt;h1 id="why-does-this-matter">Why Does This Matter?&lt;/h1>
&lt;p>If the test data is included when calculating the IDF, the model gains unintended insight into the test set&amp;rsquo;s word distribution. In real-world scenarios, the test data is supposed to be unseen during training. By allowing the model to see this information, you&amp;rsquo;re essentially reducing the uncertainty that the model should have about future data.&lt;/p>
&lt;h1 id="impact-of-data-leakage-on-model-performance">Impact of Data Leakage on Model Performance&lt;/h1>
&lt;p>Let&amp;rsquo;s consider two cases to understand the impact of data leakage in detail:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>When a word is rare in the training set but common in the test set&lt;/strong>: The model will underestimate the importance of this word during training, leading to poor performance when the word is critical in test documents.&lt;/li>
&lt;li>&lt;strong>When a word is common in the training set but rare in the test set&lt;/strong>: The model will overemphasize the word during training, leading to poor predictions when the word doesn’t appear as often in unseen data.&lt;/li>
&lt;/ol>
&lt;h3 id="case-study-data-leakage-in-tf-idf">Case Study: Data Leakage in TF-IDF&lt;/h3>
&lt;p>To see this effect in action, consider a small toy dataset where the presence of the word &amp;ldquo;banana&amp;rdquo; determines the label. If the word &amp;ldquo;banana&amp;rdquo; appears in a sentence, the label is 1; otherwise, the label is 0. Using &lt;strong>TF-IDF&lt;/strong> to vectorize the text, we train a machine learning model to predict this label.&lt;/p>
&lt;p>In the &lt;strong>first scenario&lt;/strong>, we calculate the &lt;strong>TF-IDF&lt;/strong> using the entire dataset before splitting it into training and testing sets. This causes data leakage since the model now knows the distribution of words across both sets. For instance, if &amp;ldquo;banana&amp;rdquo; is more common in the test set than the training set, the &lt;strong>IDF&lt;/strong> score for &amp;ldquo;banana&amp;rdquo; will be lower across the entire dataset, leading the model to downplay its importance.&lt;/p>
&lt;p>In the &lt;strong>second scenario&lt;/strong>, we calculate &lt;strong>TF-IDF&lt;/strong> only on the training set, ensuring that the test set remains unseen. This preserves the integrity of the test set, giving us a more realistic evaluation of the model&amp;rsquo;s performance.&lt;/p>
&lt;p>In both scenarios, the model&amp;rsquo;s accuracy is drastically different. When leakage is present, performance is artificially high during training but poor when tested on unseen data. Without leakage, the model generalizes better, as it is evaluated on truly unseen data.&lt;/p>
&lt;h1 id="avoiding-data-leakage">Avoiding Data Leakage&lt;/h1>
&lt;p>Avoiding data leakage is essential for building reliable machine learning models that generalize well to new data. Here are a few guidelines to help prevent leakage:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Split the dataset before feature extraction&lt;/strong>: Always divide your data into training and test sets before applying any feature engineering techniques.&lt;/li>
&lt;li>&lt;strong>Ensure proper cross-validation&lt;/strong>: When using cross-validation, ensure that the training and test splits do not overlap in any way that can leak information between them.&lt;/li>
&lt;li>&lt;strong>Be cautious with time-series data&lt;/strong>: In time-series models, avoid using future data to predict past events, as this can lead to leakage.&lt;/li>
&lt;/ol>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>Avoiding data leakage is crucial for building robust machine learning models. In the case of TF-IDF, ensuring that feature extraction is done &lt;strong>only on the training set&lt;/strong> and not on the entire dataset is key to preventing leakage. Properly addressing this issue leads to better generalization and more reliable models in real-world applications.&lt;/p>
&lt;p>This blog post provided a case study on how TF-IDF can introduce data leakage and why it&amp;rsquo;s important to carefully handle your dataset before feature extraction. By splitting your data properly and ensuring that no test data &amp;ldquo;leaks&amp;rdquo; into the training process, you can build models that truly reflect real-world performance.&lt;/p>
&lt;p>Thanks for reading!&lt;/p></description></item><item><title>Reproducing and addressing Data Leakage issue : Duplicates in dataset</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240823-kyrillosishak/</link><pubDate>Fri, 23 Aug 2024 00:00:00 +0000</pubDate><guid>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240823-kyrillosishak/</guid><description>&lt;p>Hello!&lt;/p>
&lt;p>In this blog post, I will explore a common issue in machine learning called data leakage, using an example from the paper:&lt;/p>
&lt;blockquote>
&lt;p>Benedetti, P., Perri, D., Simonetti, M., Gervasi, O., Reali, G., Femminella, M. (2020). Skin Cancer Classification Using Inception Network and Transfer Learning. In: Gervasi, O., et al. Computational Science and Its Applications – ICCSA 2020. ICCSA 2020. Lecture Notes in Computer Science(), vol 12249. Springer, Cham. &lt;a href="https://doi.org/10.1007/978-3-030-58799-4_39" target="_blank" rel="noopener">https://doi.org/10.1007/978-3-030-58799-4_39&lt;/a> &lt;a href="https://arxiv.org/pdf/2111.02402v1" target="_blank" rel="noopener">arXiv&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;h1 id="overview-of-the-paper">Overview of the Paper&lt;/h1>
&lt;p>In this paper, the authors use transfer learning on a pretrained convolutional neural network (CNN) to classify skin lesions in dermatoscopic images from the HAM10000 (Human Against Machine with 10,000 training images) dataset. The paper reports a final accuracy of 78.9% on the validation set.&lt;/p>
&lt;p>While this reported result appears to be impressive, there are concerns regarding the validity of this performance metric due to data leakage. Data leakage occurs when the model is trained or evaluated on data that it would not have access to during real-world deployment, leading to an overestimation of the model&amp;rsquo;s true performance.&lt;/p>
&lt;h1 id="identifying-data-leakage-in-the-original-paper">Identifying Data Leakage in the Original Paper&lt;/h1>
&lt;p>Upon closer inspection, it appears that the original experiment suffers from data leakage in two significant ways:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Duplicate Images in Training and Validation Sets:&lt;/p>
&lt;p>The HAM10000 dataset contains near-duplicate images of the same lesions in both the training and validation sets. This results in the model seeing very similar images during training and then again during validation. Consequently, the model&amp;rsquo;s performance is artificially inflated because it has already been &amp;ldquo;trained&amp;rdquo; on images similar to those in the validation set, making the task easier than it should be.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="Lesions" srcset="
/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate_HAM10000_hu729e02c2ef4cc1a337c6f61174a87df8_81762_dd4057c4bb0e4dc6092a43699881c4f4.webp 400w,
/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate_HAM10000_hu729e02c2ef4cc1a337c6f61174a87df8_81762_95478285e99e3f18a8b724b5a0a3dbb5.webp 760w,
/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate_HAM10000_hu729e02c2ef4cc1a337c6f61174a87df8_81762_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate_HAM10000_hu729e02c2ef4cc1a337c6f61174a87df8_81762_dd4057c4bb0e4dc6092a43699881c4f4.webp"
width="620"
height="104"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="Lesions2" srcset="
/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate2_HAM10000_hu1c922099c4dc23532306de6197bf4d86_99960_a0e705292db1f7f683a77cd92f29edc0.webp 400w,
/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate2_HAM10000_hu1c922099c4dc23532306de6197bf4d86_99960_fae997e88feee11018435aebd9ed6c88.webp 760w,
/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate2_HAM10000_hu1c922099c4dc23532306de6197bf4d86_99960_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240823-kyrillosishak/Near-duplicate2_HAM10000_hu1c922099c4dc23532306de6197bf4d86_99960_a0e705292db1f7f683a77cd92f29edc0.webp"
width="620"
height="104"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Using the Validation Set for Early Stopping and Final Evaluation:&lt;/p>
&lt;p>Another critical issue is the use of the validation set for both early stopping and final model evaluation. Early stopping is a technique where training is halted when the model&amp;rsquo;s performance on a validation set no longer improves, preventing overfitting. However, if this same validation set is later used to evaluate the model&amp;rsquo;s final performance, it can lead to overfitting on the validation data itself, resulting in an overly optimistic estimate of model accuracy.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h1 id="our-reproduction-and-results">Our Reproduction and Results&lt;/h1>
&lt;p>To demonstrate the impact of these data leakage issues, we reproduced the experiment with corrected methodologies:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Corrected Data Split: We ensured that there were no duplicate images between the training and validation sets. This setup is crucial to simulate a realistic scenario where the model encounters completely unseen data during validation.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Separate Validation and Test Sets: We introduced a distinct test set to evaluate the final model performance, independent of the data used for early stopping.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Results Comparison&lt;/strong>&lt;/p>
&lt;table>
&lt;tr>
&lt;td>&lt;/td>
&lt;td>Original results&lt;/td>
&lt;td>Our results&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
Accuracy
&lt;/td>
&lt;td>
78.9%
&lt;/td>
&lt;td>
78.6%
&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
Number of epochs
&lt;/td>
&lt;td>
Approx. 42 epochs
&lt;/td>
&lt;td>
40 epochs
&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
Training size
&lt;/td>
&lt;td>
Unknown
&lt;/td>
&lt;td>
7000 samples
&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
Validation size
&lt;/td>
&lt;td>
478 samples
&lt;/td>
&lt;td>
478 samples
&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>
Confusion martix
&lt;/td>
&lt;td>
&lt;img src="https://raw.githubusercontent.com/kyrillosishak/re-SkinCancer/main/assets/paper's_results.jpeg" />
&lt;/td>
&lt;td>
&lt;img src="https://raw.githubusercontent.com/kyrillosishak/re-SkinCancer/main/assets/Our_results.jpeg" />
&lt;/td>
&lt;/tr>
&lt;/table>
&lt;h1 id="analysis-of-the-results">Analysis of the Results&lt;/h1>
&lt;p>While our reproduced accuracy of 78.6% is close to the original reported accuracy, it is based on a properly separated training and validation set, avoiding the data leakage pitfalls of the original paper. The slight drop in accuracy further highlights the overestimation of the original model&amp;rsquo;s performance due to data leakage.&lt;/p>
&lt;p>Moreover, using a separate test set for final evaluation provides a more reliable measure of the model&amp;rsquo;s ability to generalize to new, unseen data. The confusion matrices show that our model&amp;rsquo;s performance is consistent across different lesion classes, confirming the robustness of the evaluation.&lt;/p>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>Data leakage is a common and often overlooked problem in applied machine learning, leading to misleading performance metrics and irreproducible results. By carefully examining and correcting these issues in our reproduction, we hope to provide a clearer understanding of the importance of proper data handling and validation practices.&lt;/p>
&lt;p>It is crucial for researchers and practitioners to be vigilant about data leakage and ensure that their models are trained, validated, and tested under realistic conditions. This not only ensures the credibility of their results but also enhances the real-world applicability of their models.&lt;/p>
&lt;p>Thank you for reading, and stay tuned for more insights on machine learning reproducibility!&lt;/p></description></item><item><title>Data leakage in applied ML: reproducing examples of irreproducibility</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240614-kyrillosishak/</link><pubDate>Fri, 14 Jun 2024 00:00:00 +0000</pubDate><guid>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre24/nyu/data-leakage/20240614-kyrillosishak/</guid><description>&lt;p>Hello,&lt;/p>
&lt;p>I am Kyrillos Ishak I am happy to be part of SOR 2024, I am working on &lt;a href="https://deploy-preview-1007--ucsc-ospo.netlify.app/project/osre24/nyu/data-leakage/">Data leakage in applied ML: reproducing examples of irreproducibility&lt;/a> project. My &lt;a href="https://drive.google.com/file/d/1u9FGQqxlPMhceKwS_NJxIhkIrQVGIp-0/view" target="_blank" rel="noopener">proposal&lt;/a> was accepted.&lt;/p>
&lt;p>I am excited to work with &lt;a href="https://deploy-preview-1007--ucsc-ospo.netlify.app/author/fraida-fund/">Fraida Fund&lt;/a> and &lt;a href="https://deploy-preview-1007--ucsc-ospo.netlify.app/author/mohamed-saeed/">Mohamed Saeed&lt;/a> as my mentors. The objective of the project is to develop educational resources that can be adjusted by professors/instructors to explain specific data leakage problems. This involves ensuring the reproducibility of certain research papers that contain data preprocessing issues, then fixing these issues to demonstrate how they can affect the results.&lt;/p>
&lt;p>Data leakage is a problem caused when information from outside the training dataset is used to create the model. This issue can lead to overly optimistic performance estimates and, ultimately, models that do not perform well on new, unseen data.&lt;/p>
&lt;p>Despite the importance of addressing data leakage, many people from fields not closely related to computer science, are often unfamiliar with it, even if they are aware of best practices for data preprocessing. Developing educational materials on this topic will greatly benefit them.&lt;/p>
&lt;p>I am excited to dive into the topic of data leakage in machine learning. Throughout the summer, I will be sharing regular updates and insightful blog posts on this subject. Stay tuned for more information!&lt;/p></description></item></channel></rss>