Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

10 Biggest Mistakes in Machine Learning and How to Avoid Them
Latest   Machine Learning

10 Biggest Mistakes in Machine Learning and How to Avoid Them

Last Updated on July 25, 2023 by Editorial Team

Author(s): Nick Minaie, PhD

Originally published on Towards AI.

Your Guide to Becoming a Better Data Scientist

Machine learning has revolutionized various industries by enabling computers to learn from data and make intelligent decisions. However, in the journey of building machine learning models, it’s easy to stumble upon common mistakes that can hinder progress and lead to sub-optimal results. In this blog post, we will highlight ten common mistakes in machine learning and provide practical tips on how to avoid them, ensuring smoother and more successful model development.

Photo by Francisco De Legarreta C. on Unsplash

1 — Insufficient Data Preprocessing

Neglecting data preprocessing steps can have a detrimental impact on model performance. For example, failing to handle missing values can introduce bias or lead to inaccurate predictions. In a study by Nguyen and Verspoor (2018), they found that improper handling of missing data in a gene expression dataset led to significant performance degradation in the classification task. Preprocessing techniques like imputation or deletion can be employed to address missing data effectively.

Another important preprocessing step is feature scaling, where the values of different features are normalized to a common scale. Neglecting feature scaling can result in certain features dominating the learning process, especially when using distance-based algorithms like k-nearest neighbors or clustering algorithms. For instance, in a study by Carreira-Perpiñán and Idelbayev (2015), they observed that failure to scale features led to suboptimal clustering results. Techniques like standardization or normalization can be applied to scale features appropriately.

Handling outliers is also crucial during data preprocessing. Outliers can introduce noise and affect the model’s ability to capture patterns. For instance, in a study by Khan et al. (2020), they found that outliers in a credit-scoring dataset led to biased risk assessment models. Techniques like trimming, winsorizing, or using robust statistical measures can help mitigate the impact of outliers on model performance.

To ensure thorough data preprocessing, it is essential to understand the characteristics of the dataset and employ appropriate techniques tailored to the specific context. By addressing missing values, scaling features, and handling outliers effectively, the quality of the input data can be improved, leading to better model performance.

2 — Lack of Feature Engineering

Feature engineering is a crucial step in machine learning that involves transforming raw data into informative features that capture relevant patterns. Failing to perform feature engineering or using incorrect features can limit model performance and the ability to uncover valuable insights.

Consider a text classification task where the goal is to categorize customer reviews as positive or negative. By solely relying on the raw text data without feature engineering, the model may struggle to capture important indicators of sentiment. However, by extracting features such as word frequency, n-grams, or sentiment scores, the model can leverage more meaningful representations of the text, improving classification accuracy.

Feature engineering is not limited to numerical or textual data but can also apply to other domains. For instance, in image classification, extracting features using techniques like convolutional neural networks (CNNs) allows the model to capture hierarchical patterns in images. By identifying edges, textures, and shapes, the model can learn more discriminative representations and make accurate predictions.

Moreover, feature engineering can involve domain-specific knowledge and understanding of the problem context. For example, in fraud detection, domain experts can identify specific patterns or variables that are indicative of fraudulent transactions. By incorporating such domain knowledge into feature engineering, models can achieve better performance and identify suspicious activities effectively.

Investing time in feature engineering requires a deep understanding of the problem domain, collaboration with domain experts, and experimentation to identify the most informative features. By transforming raw data into meaningful representations, models can better capture patterns and improve their predictive power.

3 — Overfitting

Overfitting is a common mistake in machine learning where a model performs well on the training data but fails to generalize to unseen data. This occurs when the model becomes overly complex and starts to memorize the training examples rather than capturing the underlying patterns.

For instance, imagine training a classification model to distinguish between different types of flowers using various features like petal length, petal width, and sepal length. If the model is too complex and has too many parameters, it may end up memorizing the unique characteristics of each individual flower in the training set rather than learning the general patterns that distinguish the flower types. As a result, when presented with new unseen flowers during testing, the model will struggle to make accurate predictions.

To avoid overfitting, several techniques can be employed. Regularization methods, such as L1 and L2 regularization, introduce a penalty term to the model’s loss function, encouraging it to prioritize simpler solutions and reduce the impact of overly complex features. Cross-validation is another effective technique where the data is split into multiple folds, allowing the model to be trained and validated on different subsets of the data. This helps assess the model’s performance on unseen data and prevents overfitting by providing a more reliable estimate of its generalization ability.

Early stopping is also widely used to combat overfitting. It involves monitoring the model’s performance during training and stopping the training process when the performance on the validation set starts to deteriorate. By doing so, the model is prevented from overly fitting the training data and is instead stopped at the point where it achieves the best balance between training and validation performance.

By utilizing techniques like regularization, cross-validation, and early stopping, data scientists can mitigate the risk of overfitting, leading to more robust and generalizable models.

4 — Ignoring Model Evaluation Metrics

Choosing appropriate evaluation metrics is crucial for accurately assessing model performance and determining its effectiveness in solving the problem at hand. Different evaluation metrics capture different aspects of model performance, and neglecting them can lead to misleading conclusions or suboptimal decisions.

For example, in a binary classification problem where the goal is to predict whether a customer will churn or not, accuracy alone may not provide a comprehensive view of the model’s performance. If the dataset is imbalanced and the majority of customers do not churn, a model that simply predicts “no churn” for all instances can achieve high accuracy but fail to capture the minority class (churned customers). In such cases, metrics like precision, recall, F1 score, or area under the curve (AUC) of the receiver operating characteristic (ROC) curve should be considered. These metrics consider true positive, false positive, true negative, and false negative rates, providing a more nuanced evaluation of the model’s performance.

Moreover, it is important to align the evaluation metrics with the specific objectives of the problem. For instance, in a medical diagnosis task, the cost of false negatives (misdiagnosing a sick patient as healthy) might be higher than the cost of false positives. In such cases, optimizing for metrics like sensitivity (recall) becomes more important.

Considering the characteristics of the data, the problem domain, and the associated costs or priorities, data scientists can select the most appropriate evaluation metrics to measure the performance of their models accurately.

5 — Lack of Sufficient Training Data

Insufficient training data is a common mistake that can hinder the performance of machine learning models. When the available training data is limited or unrepresentative of real-world scenarios, the model may struggle to capture the underlying patterns and generalize well to unseen data.

For instance, imagine training a sentiment analysis model to classify customer reviews as positive or negative. If the training dataset consists of only a few hundred examples, the model may not have enough diversity and variability to learn the intricate nuances of language and sentiment. Consequently, the model’s predictions may be inaccurate or biased when applied to a larger and more diverse dataset.

To address this issue, data scientists should strive to collect a sufficient amount of training data that adequately covers the range of variations and patterns present in the problem domain. They can leverage techniques like data augmentation, where additional synthetic examples are generated by applying transformations or perturbations to the existing data. Transfer learning is another approach that can be beneficial when data availability is limited. By leveraging pre-trained models on large-scale datasets, data scientists can extract relevant features or fine-tune models for their specific tasks, even with smaller datasets.

It’s important to note that the quality of the data is equally crucial as the quantity. The training data should be accurately labeled, free from noise, and representative of the target population. Data preprocessing steps, such as removing duplicates, handling missing values, and addressing data biases, should be performed to ensure the data’s integrity and reliability.

6 — Failure to Address Class Imbalance

Class imbalance occurs when the distribution of classes in the training data is significantly skewed, with one class being dominant while others are underrepresented. Failing to address class imbalance can lead to biased models that favor the majority class, resulting in poor performance for the minority class.

For example, consider a fraud detection task where only a small fraction of transactions are fraudulent. If the training data is imbalanced, a model trained on this data may achieve high accuracy by simply predicting all transactions as non-fraudulent. However, such a model fails to effectively identify rare fraudulent transactions, defeating the purpose of fraud detection.

To tackle class imbalance, data scientists employ various techniques. Oversampling involves replicating or generating new instances of the minority class to balance its representation in the training data. Undersampling, on the other hand, reduces the number of instances from the majority class to match the minority class. These techniques can help the model learn from a more balanced distribution of classes.

Alternatively, class weighting can be applied during model training, assigning higher weights to instances from the minority class. This ensures that the model pays more attention to the minority class during the learning process.

There are also advanced techniques like ensemble methods and anomaly detection approaches that can effectively handle class imbalance. These methods leverage a combination of models or focus on identifying anomalous instances to address the challenges posed by imbalanced data distributions.

7 — Disregarding Hyperparameter Tuning

Hyperparameters are the configuration settings that determine the behavior and performance of machine learning models. Failing to properly tune these hyperparameters can lead to suboptimal model performance and hinder the ability to achieve the best possible results.

For instance, consider the hyperparameter “learning rate” in a neural network. Setting it too high can cause the model to overshoot the optimal solution and fail to converge, while setting it too low can result in slow convergence and longer training times. By neglecting to tune the learning rate to an appropriate value, the model may struggle to find the right balance and achieve optimal performance.

To address this mistake, data scientists should explore techniques like grid search, random search, or Bayesian optimization to systematically search the hyperparameter space and identify the best combination of values that maximize model performance. Grid search involves specifying a predefined set of hyperparameter values and exhaustively evaluating each combination, while random search randomly samples the hyperparameter space. Bayesian optimization employs a probabilistic model to intelligently explore the space based on previous evaluations, focusing on promising regions.

Furthermore, it’s essential to understand the impact of each hyperparameter on the model’s behavior and performance. Data scientists should have a good grasp of the theory behind the algorithms and their hyperparameters to make informed decisions during the tuning process. Regular experimentation and evaluation of different hyperparameter configurations are necessary to identify the optimal settings for a given task.

8 — Not Regularly Updating Models

Machine learning models should not be treated as one-time solutions but rather as dynamic entities that require regular updates and refinements. Failing to update models with new data can result in degraded performance and decreased effectiveness over time.

For example, imagine training a recommendation system based on user preferences and behavior. As user preferences evolve, new items are introduced, and trends change, the model needs to adapt to these shifts to provide relevant recommendations. By neglecting to update the model with fresh data and retraining it periodically, the recommendations may become less accurate and fail to meet the changing needs of the users.

To avoid this mistake, data scientists should establish processes to regularly retrain and update models with new data. This may involve setting up automated pipelines that fetch new data, performing necessary preprocessing steps, and retraining the model on a scheduled basis. It’s important to strike a balance between the frequency of updates and the cost of retraining to ensure that models stay up to date without incurring excessive computational resources.

Furthermore, monitoring the performance of the models over time is crucial. By tracking key performance metrics and comparing them to baseline performance, data scientists can identify when a model’s performance starts to degrade and take proactive measures to address any issues.

9 — Lack of Interpretability and Explainability

Interpretability and explainability are crucial aspects of machine learning, especially in domains where transparency and understanding the decision-making process are essential. Neglecting to prioritize interpretability can lead to a lack of trust in the model’s predictions and hinder its adoption in critical applications.

For instance, in the medical field, where patient health and well-being are at stake, it is important to understand why a model made a particular prediction or diagnosis. Relying solely on complex black-box models, such as deep neural networks, without considering interpretability techniques, can make it challenging to provide explanations for the model’s decisions.

To address this mistake, data scientists should explore techniques like LIME (Local Interpretable Model-Agnostic Explanations) or SHAP (SHapley Additive exPlanations) to gain insights into the inner workings of the model. These techniques provide explanations at the instance level, highlighting the features that contributed the most to a particular prediction. By using such techniques, data scientists can provide interpretable explanations to end-users or domain experts, enhancing the model’s trustworthiness and facilitating its adoption.

10 — Disregarding the Importance of Domain Knowledge

Domain knowledge plays a pivotal role in machine learning projects. Neglecting to understand the problem domain can lead to improper feature selection, inadequate model architecture, or misinterpretation of results. Collaboration with domain experts and developing a deep understanding of the problem is crucial for making informed decisions throughout the entire machine learning pipeline.

For example, consider a fraud detection system in the financial industry. Without a solid understanding of fraud patterns, regulatory requirements, and industry-specific knowledge, it becomes challenging to identify the relevant features or design an effective fraud detection model. Domain experts can provide valuable insights into potential data biases, feature engineering techniques, or model evaluation criteria specific to the industry.

To avoid this mistake, data scientists should actively engage with domain experts, establish effective communication channels, and continuously learn from their expertise. Collaborative efforts can lead to the development of more accurate models that align with the specific requirements and nuances of the industry. Additionally, data scientists should invest time in understanding the problem domain through literature reviews, attending industry conferences, and participating in relevant discussions to stay up to date with the latest advancements and challenges in the field.

Final thoughts…

By being aware of these common mistakes in machine learning and implementing the suggested strategies to avoid them, data scientists and machine learning practitioners can significantly improve their model development process and achieve more accurate and reliable results. Remember to prioritize data preprocessing, feature engineering, and model evaluation, and pay attention to factors such as overfitting, class imbalance, and hyperparameter tuning. Continuously learn, iterate, and leverage domain knowledge to build robust and impactful machine-learning models.

References

  • Nguyen, H. Q., & Verspoor, K. (2018). Handling missing values in longitudinal gene expression data. BMC Bioinformatics, 19(1), 9.
  • Carreira-Perpiñán, M. A., & Idelbayev, Y. (2015). Feature scaling for clustering. Neural Networks, 67, 114–123.
  • Khan, S., et al. (2020). Dealing with outliers in credit scoring: A survey. Knowledge-Based Systems, 202, 106207.
  • Aggarwal, C. C., & Zhai, C. (2012). Mining text data. Springer Science & Business Media.
  • LeCun, Y., et al. (2015). Deep learning. Nature, 521(7553), 436–444.
  • Dal Pozzolo, A., et al. (2015). Calibrating probability with undersampling for unbalanced classification. In Symposium on Computational Intelligence and Data Mining (CIDM) (pp. 1–8).
  • Hastie, T., et al. (2009). The elements of statistical learning: data mining, inference, and prediction. Springer Science & Business Media.
  • Bishop, C. M. (2006). Pattern recognition and machine learning. Springer.
  • Sokolova, M., et al. (2009). A systematic analysis of performance measures for classification tasks. Information Processing & Management, 45(4), 427–437.
  • Powers, D. M. (2011). Evaluation: from precision, recall and F-measure to ROC, informedness, markedness, and correlation. Journal of Machine Learning Technologies, 2(1), 37–63.
  • Goodfellow, I., et al. (2016). Deep learning. MIT press.
  • Bengio, Y., et al. (2013). Representation learning: A review and new perspectives. IEEE Transactions on Pattern Analysis and Machine Intelligence, 35(8), 1798–1828.
  • Chawla, N. V., et al. (2002). SMOTE: Synthetic minority over-sampling technique. Journal of artificial intelligence research, 16, 321–357.
  • He, H., et al. (2009). Learning from imbalanced data. IEEE Transactions on Knowledge and Data Engineering, 21(9), 1263–1284.
  • Bergstra, J., et al. (2012). Random search for hyper-parameter optimization. Journal of Machine Learning Research, 13(Feb), 281–305.
  • Snoek, J., et al. (2012). Practical Bayesian optimization of machine learning algorithms. In Advances in neural information processing systems (pp. 2951–2959).
  • Hinton, G., et al. (2015). Distilling the knowledge in a neural network. arXiv preprint arXiv:1503.02531.
  • Domingos, P. (2012). A few useful things to know about machine learning. Communications of the ACM, 55(10), 78–87.
  • Ribeiro, M. T., et al. (2016). “Why should I trust you?”: Explaining the predictions of any classifier. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (pp. 1135–1144).
  • Caruana, R., et al. (2015). Intelligible models for healthcare: Predicting pneumonia risk and hospital 30-day readmission. In Proceedings of the 21th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (pp. 1721–1730).

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓

Sign Up for the Course
`; } else { console.error('Element with id="subscribe" not found within the page with class "home".'); } } }); // Remove duplicate text from articles /* Backup: 09/11/24 function removeDuplicateText() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, strong'); // Select the desired elements const seenTexts = new Set(); // A set to keep track of seen texts const tagCounters = {}; // Object to track instances of each tag elements.forEach(el => { const tagName = el.tagName.toLowerCase(); // Get the tag name (e.g., 'h1', 'h2', etc.) // Initialize a counter for each tag if not already done if (!tagCounters[tagName]) { tagCounters[tagName] = 0; } // Only process the first 10 elements of each tag type if (tagCounters[tagName] >= 2) { return; // Skip if the number of elements exceeds 10 } const text = el.textContent.trim(); // Get the text content const words = text.split(/\s+/); // Split the text into words if (words.length >= 4) { // Ensure at least 4 words const significantPart = words.slice(0, 5).join(' '); // Get first 5 words for matching // Check if the text (not the tag) has been seen before if (seenTexts.has(significantPart)) { // console.log('Duplicate found, removing:', el); // Log duplicate el.remove(); // Remove duplicate element } else { seenTexts.add(significantPart); // Add the text to the set } } tagCounters[tagName]++; // Increment the counter for this tag }); } removeDuplicateText(); */ // Remove duplicate text from articles function removeDuplicateText() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, strong'); // Select the desired elements const seenTexts = new Set(); // A set to keep track of seen texts const tagCounters = {}; // Object to track instances of each tag // List of classes to be excluded const excludedClasses = ['medium-author', 'post-widget-title']; elements.forEach(el => { // Skip elements with any of the excluded classes if (excludedClasses.some(cls => el.classList.contains(cls))) { return; // Skip this element if it has any of the excluded classes } const tagName = el.tagName.toLowerCase(); // Get the tag name (e.g., 'h1', 'h2', etc.) // Initialize a counter for each tag if not already done if (!tagCounters[tagName]) { tagCounters[tagName] = 0; } // Only process the first 10 elements of each tag type if (tagCounters[tagName] >= 10) { return; // Skip if the number of elements exceeds 10 } const text = el.textContent.trim(); // Get the text content const words = text.split(/\s+/); // Split the text into words if (words.length >= 4) { // Ensure at least 4 words const significantPart = words.slice(0, 5).join(' '); // Get first 5 words for matching // Check if the text (not the tag) has been seen before if (seenTexts.has(significantPart)) { // console.log('Duplicate found, removing:', el); // Log duplicate el.remove(); // Remove duplicate element } else { seenTexts.add(significantPart); // Add the text to the set } } tagCounters[tagName]++; // Increment the counter for this tag }); } removeDuplicateText(); //Remove unnecessary text in blog excerpts document.querySelectorAll('.blog p').forEach(function(paragraph) { // Replace the unwanted text pattern for each paragraph paragraph.innerHTML = paragraph.innerHTML .replace(/Author\(s\): [\w\s]+ Originally published on Towards AI\.?/g, '') // Removes 'Author(s): XYZ Originally published on Towards AI' .replace(/This member-only story is on us\. Upgrade to access all of Medium\./g, ''); // Removes 'This member-only story...' }); //Load ionic icons and cache them if ('localStorage' in window && window['localStorage'] !== null) { const cssLink = 'https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css'; const storedCss = localStorage.getItem('ionicons'); if (storedCss) { loadCSS(storedCss); } else { fetch(cssLink).then(response => response.text()).then(css => { localStorage.setItem('ionicons', css); loadCSS(css); }); } } function loadCSS(css) { const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); } //Remove elements from imported content automatically function removeStrongFromHeadings() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, h6, span'); elements.forEach(el => { const strongTags = el.querySelectorAll('strong'); strongTags.forEach(strongTag => { while (strongTag.firstChild) { strongTag.parentNode.insertBefore(strongTag.firstChild, strongTag); } strongTag.remove(); }); }); } removeStrongFromHeadings(); "use strict"; window.onload = () => { /* //This is an object for each category of subjects and in that there are kewords and link to the keywods let keywordsAndLinks = { //you can add more categories and define their keywords and add a link ds: { keywords: [ //you can add more keywords here they are detected and replaced with achor tag automatically 'data science', 'Data science', 'Data Science', 'data Science', 'DATA SCIENCE', ], //we will replace the linktext with the keyword later on in the code //you can easily change links for each category here //(include class="ml-link" and linktext) link: 'linktext', }, ml: { keywords: [ //Add more keywords 'machine learning', 'Machine learning', 'Machine Learning', 'machine Learning', 'MACHINE LEARNING', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, ai: { keywords: [ 'artificial intelligence', 'Artificial intelligence', 'Artificial Intelligence', 'artificial Intelligence', 'ARTIFICIAL INTELLIGENCE', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, nl: { keywords: [ 'NLP', 'nlp', 'natural language processing', 'Natural Language Processing', 'NATURAL LANGUAGE PROCESSING', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, des: { keywords: [ 'data engineering services', 'Data Engineering Services', 'DATA ENGINEERING SERVICES', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, td: { keywords: [ 'training data', 'Training Data', 'training Data', 'TRAINING DATA', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, ias: { keywords: [ 'image annotation services', 'Image annotation services', 'image Annotation services', 'image annotation Services', 'Image Annotation Services', 'IMAGE ANNOTATION SERVICES', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, l: { keywords: [ 'labeling', 'labelling', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, pbp: { keywords: [ 'previous blog posts', 'previous blog post', 'latest', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, mlc: { keywords: [ 'machine learning course', 'machine learning class', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, }; //Articles to skip let articleIdsToSkip = ['post-2651', 'post-3414', 'post-3540']; //keyword with its related achortag is recieved here along with article id function searchAndReplace(keyword, anchorTag, articleId) { //selects the h3 h4 and p tags that are inside of the article let content = document.querySelector(`#${articleId} .entry-content`); //replaces the "linktext" in achor tag with the keyword that will be searched and replaced let newLink = anchorTag.replace('linktext', keyword); //regular expression to search keyword var re = new RegExp('(' + keyword + ')', 'g'); //this replaces the keywords in h3 h4 and p tags content with achor tag content.innerHTML = content.innerHTML.replace(re, newLink); } function articleFilter(keyword, anchorTag) { //gets all the articles var articles = document.querySelectorAll('article'); //if its zero or less then there are no articles if (articles.length > 0) { for (let x = 0; x < articles.length; x++) { //articles to skip is an array in which there are ids of articles which should not get effected //if the current article's id is also in that array then do not call search and replace with its data if (!articleIdsToSkip.includes(articles[x].id)) { //search and replace is called on articles which should get effected searchAndReplace(keyword, anchorTag, articles[x].id, key); } else { console.log( `Cannot replace the keywords in article with id ${articles[x].id}` ); } } } else { console.log('No articles found.'); } } let key; //not part of script, added for (key in keywordsAndLinks) { //key is the object in keywords and links object i.e ds, ml, ai for (let i = 0; i < keywordsAndLinks[key].keywords.length; i++) { //keywordsAndLinks[key].keywords is the array of keywords for key (ds, ml, ai) //keywordsAndLinks[key].keywords[i] is the keyword and keywordsAndLinks[key].link is the link //keyword and link is sent to searchreplace where it is then replaced using regular expression and replace function articleFilter( keywordsAndLinks[key].keywords[i], keywordsAndLinks[key].link ); } } function cleanLinks() { // (making smal functions is for DRY) this function gets the links and only keeps the first 2 and from the rest removes the anchor tag and replaces it with its text function removeLinks(links) { if (links.length > 1) { for (let i = 2; i < links.length; i++) { links[i].outerHTML = links[i].textContent; } } } //arrays which will contain all the achor tags found with the class (ds-link, ml-link, ailink) in each article inserted using search and replace let dslinks; let mllinks; let ailinks; let nllinks; let deslinks; let tdlinks; let iaslinks; let llinks; let pbplinks; let mlclinks; const content = document.querySelectorAll('article'); //all articles content.forEach((c) => { //to skip the articles with specific ids if (!articleIdsToSkip.includes(c.id)) { //getting all the anchor tags in each article one by one dslinks = document.querySelectorAll(`#${c.id} .entry-content a.ds-link`); mllinks = document.querySelectorAll(`#${c.id} .entry-content a.ml-link`); ailinks = document.querySelectorAll(`#${c.id} .entry-content a.ai-link`); nllinks = document.querySelectorAll(`#${c.id} .entry-content a.ntrl-link`); deslinks = document.querySelectorAll(`#${c.id} .entry-content a.des-link`); tdlinks = document.querySelectorAll(`#${c.id} .entry-content a.td-link`); iaslinks = document.querySelectorAll(`#${c.id} .entry-content a.ias-link`); mlclinks = document.querySelectorAll(`#${c.id} .entry-content a.mlc-link`); llinks = document.querySelectorAll(`#${c.id} .entry-content a.l-link`); pbplinks = document.querySelectorAll(`#${c.id} .entry-content a.pbp-link`); //sending the anchor tags list of each article one by one to remove extra anchor tags removeLinks(dslinks); removeLinks(mllinks); removeLinks(ailinks); removeLinks(nllinks); removeLinks(deslinks); removeLinks(tdlinks); removeLinks(iaslinks); removeLinks(mlclinks); removeLinks(llinks); removeLinks(pbplinks); } }); } //To remove extra achor tags of each category (ds, ml, ai) and only have 2 of each category per article cleanLinks(); */ //Recommended Articles var ctaLinks = [ /* ' ' + '

Subscribe to our AI newsletter!

' + */ '

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

'+ '

Towards AI has published Building LLMs for Production—our 470+ page guide to mastering LLMs with practical projects and expert insights!

' + '
' + '' + '' + '

Note: Content contains the views of the contributing authors and not Towards AI.
Disclosure: This website may contain sponsored content and affiliate links.

' + 'Discover Your Dream AI Career at Towards AI Jobs' + '

Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 10,000 live jobs today with Towards AI Jobs!

' + '
' + '

🔥 Recommended Articles 🔥

' + 'Why Become an LLM Developer? Launching Towards AI’s New One-Stop Conversion Course'+ 'Testing Launchpad.sh: A Container-based GPU Cloud for Inference and Fine-tuning'+ 'The Top 13 AI-Powered CRM Platforms
' + 'Top 11 AI Call Center Software for 2024
' + 'Learn Prompting 101—Prompt Engineering Course
' + 'Explore Leading Cloud Providers for GPU-Powered LLM Training
' + 'Best AI Communities for Artificial Intelligence Enthusiasts
' + 'Best Workstations for Deep Learning
' + 'Best Laptops for Deep Learning
' + 'Best Machine Learning Books
' + 'Machine Learning Algorithms
' + 'Neural Networks Tutorial
' + 'Best Public Datasets for Machine Learning
' + 'Neural Network Types
' + 'NLP Tutorial
' + 'Best Data Science Books
' + 'Monte Carlo Simulation Tutorial
' + 'Recommender System Tutorial
' + 'Linear Algebra for Deep Learning Tutorial
' + 'Google Colab Introduction
' + 'Decision Trees in Machine Learning
' + 'Principal Component Analysis (PCA) Tutorial
' + 'Linear Regression from Zero to Hero
'+ '

', /* + '

Join thousands of data leaders on the AI newsletter. It’s free, we don’t spam, and we never share your email address. Keep up to date with the latest work in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

',*/ ]; var replaceText = { '': '', '': '', '
': '
' + ctaLinks + '
', }; Object.keys(replaceText).forEach((txtorig) => { //txtorig is the key in replacetext object const txtnew = replaceText[txtorig]; //txtnew is the value of the key in replacetext object let entryFooter = document.querySelector('article .entry-footer'); if (document.querySelectorAll('.single-post').length > 0) { //console.log('Article found.'); const text = entryFooter.innerHTML; entryFooter.innerHTML = text.replace(txtorig, txtnew); } else { // console.log('Article not found.'); //removing comment 09/04/24 } }); var css = document.createElement('style'); css.type = 'text/css'; css.innerHTML = '.post-tags { display:none !important } .article-cta a { font-size: 18px; }'; document.body.appendChild(css); //Extra //This function adds some accessibility needs to the site. function addAlly() { // In this function JQuery is replaced with vanilla javascript functions const imgCont = document.querySelector('.uw-imgcont'); imgCont.setAttribute('aria-label', 'AI news, latest developments'); imgCont.title = 'AI news, latest developments'; imgCont.rel = 'noopener'; document.querySelector('.page-mobile-menu-logo a').title = 'Towards AI Home'; document.querySelector('a.social-link').rel = 'noopener'; document.querySelector('a.uw-text').rel = 'noopener'; document.querySelector('a.uw-w-branding').rel = 'noopener'; document.querySelector('.blog h2.heading').innerHTML = 'Publication'; const popupSearch = document.querySelector$('a.btn-open-popup-search'); popupSearch.setAttribute('role', 'button'); popupSearch.title = 'Search'; const searchClose = document.querySelector('a.popup-search-close'); searchClose.setAttribute('role', 'button'); searchClose.title = 'Close search page'; // document // .querySelector('a.btn-open-popup-search') // .setAttribute( // 'href', // 'https://medium.com/towards-artificial-intelligence/search' // ); } // Add external attributes to 302 sticky and editorial links function extLink() { // Sticky 302 links, this fuction opens the link we send to Medium on a new tab and adds a "noopener" rel to them var stickyLinks = document.querySelectorAll('.grid-item.sticky a'); for (var i = 0; i < stickyLinks.length; i++) { /* stickyLinks[i].setAttribute('target', '_blank'); stickyLinks[i].setAttribute('rel', 'noopener'); */ } // Editorial 302 links, same here var editLinks = document.querySelectorAll( '.grid-item.category-editorial a' ); for (var i = 0; i < editLinks.length; i++) { editLinks[i].setAttribute('target', '_blank'); editLinks[i].setAttribute('rel', 'noopener'); } } // Add current year to copyright notices document.getElementById( 'js-current-year' ).textContent = new Date().getFullYear(); // Call functions after page load extLink(); //addAlly(); setTimeout(function() { //addAlly(); //ideally we should only need to run it once ↑ }, 5000); }; function closeCookieDialog (){ document.getElementById("cookie-consent").style.display = "none"; return false; } setTimeout ( function () { closeCookieDialog(); }, 15000); console.log(`%c 🚀🚀🚀 ███ █████ ███████ █████████ ███████████ █████████████ ███████████████ ███████ ███████ ███████ ┌───────────────────────────────────────────────────────────────────┐ │ │ │ Towards AI is looking for contributors! │ │ Join us in creating awesome AI content. │ │ Let's build the future of AI together → │ │ https://towardsai.net/contribute │ │ │ └───────────────────────────────────────────────────────────────────┘ `, `background: ; color: #00adff; font-size: large`); //Remove latest category across site document.querySelectorAll('a[rel="category tag"]').forEach(function(el) { if (el.textContent.trim() === 'Latest') { // Remove the two consecutive spaces (  ) if (el.nextSibling && el.nextSibling.nodeValue.includes('\u00A0\u00A0')) { el.nextSibling.nodeValue = ''; // Remove the spaces } el.style.display = 'none'; // Hide the element } }); // Add cross-domain measurement, anonymize IPs 'use strict'; //var ga = gtag; ga('config', 'G-9D3HKKFV1Q', 'auto', { /*'allowLinker': true,*/ 'anonymize_ip': true/*, 'linker': { 'domains': [ 'medium.com/towards-artificial-intelligence', 'datasets.towardsai.net', 'rss.towardsai.net', 'feed.towardsai.net', 'contribute.towardsai.net', 'members.towardsai.net', 'pub.towardsai.net', 'news.towardsai.net' ] } */ }); ga('send', 'pageview'); -->