diff --git a/docs/Machine Learning/An-Introduction -to-Machine-Learning.md b/docs/Machine Learning/An-Introduction -to-Machine-Learning.md new file mode 100644 index 000000000..f51c486c5 --- /dev/null +++ b/docs/Machine Learning/An-Introduction -to-Machine-Learning.md @@ -0,0 +1,71 @@ +--- +id: Machine Learning +title: Introduction to Machine Learning +sidebar_label: An Introduction to Machine Learning +sidebar_position: 8 +tags: [ML, Type of Ml, Libraries] +description: "Learn Basics of ML." +--- + +**Machine Learning (ML)** is a subset of artificial intelligence (AI) that focuses on developing systems that can learn from and make decisions based on data. Unlike traditional programming, where specific rules and instructions are coded, machine learning enables systems to learn patterns and make decisions with minimal human intervention. + +#### Key Concepts in Machine Learning + +1. **Data**: The foundational component of machine learning. It includes structured data (like databases) and unstructured data (like text, images, videos). +2. **Algorithms**: Set of rules and statistical techniques used to learn patterns from data. Popular algorithms include linear regression, decision trees, and neural networks. +3. **Models**: The output of the machine learning process. A model is trained on data and can make predictions or decisions based on new data. +4. **Training**: The process of feeding data into a machine learning algorithm to learn patterns. This involves adjusting the algorithm's parameters to minimize errors. +5. **Testing**: Evaluating the performance of a trained model on new, unseen data to ensure it generalizes well. + +#### Types of Machine Learning + +1. **Supervised Learning**: + + - **Definition**: Learning from labeled data, where the outcome is known. + - **Examples**: Spam detection, image classification, and medical diagnosis. + - **Algorithms**: Linear regression, logistic regression, support vector machines, neural networks. + +2. **Unsupervised Learning**: + + - **Definition**: Learning from unlabeled data, where the system tries to find hidden patterns. + - **Examples**: Customer segmentation, anomaly detection, and clustering. + - **Algorithms**: K-means clustering, hierarchical clustering, association rules. + +3. **Semi-supervised Learning**: + - **Definition**: A mix of supervised and unsupervised learning. It uses a small amount of labeled data and a large amount of unlabeled data. + - **Examples**: Web content classification, speech analysis. +4. **Reinforcement Learning**: + - **Definition**: Learning by interacting with an environment. The system takes actions and learns from the feedback (rewards or punishments). + - **Examples**: Game playing (like AlphaGo), robotics, resource management. + - **Algorithms**: Q-learning, deep Q networks, policy gradients. + +#### Key Steps in Machine Learning Workflow + +1. **Data Collection**: Gathering relevant data from various sources. +2. **Data Preparation**: Cleaning and preprocessing data to make it suitable for modeling. This includes handling missing values, normalizing data, and feature selection. +3. **Choosing a Model**: Selecting an appropriate algorithm based on the problem and data. +4. **Training the Model**: Feeding data into the algorithm to learn patterns. +5. **Evaluating the Model**: Using metrics like accuracy, precision, recall, F1-score, and confusion matrix to assess the model's performance. +6. **Hyperparameter Tuning**: Adjusting the algorithm's parameters to improve performance. +7. **Prediction**: Using the trained model to make predictions on new data. +8. **Deployment**: Integrating the model into a real-world application for use. + +#### Popular Tools and Libraries + +- **Programming Languages**: Python, R, Julia. +- **Libraries**: + - **Python**: scikit-learn, TensorFlow, Keras, PyTorch, XGBoost. + - **R**: caret, randomForest, nnet. + +#### Applications of Machine Learning + +1. **Healthcare**: Disease prediction, personalized treatment plans. +2. **Finance**: Fraud detection, algorithmic trading. +3. **Marketing**: Customer segmentation, recommendation systems. +4. **Manufacturing**: Predictive maintenance, quality control. +5. **Transportation**: Self-driving cars, route optimization. +6. **Entertainment**: Content recommendation, sentiment analysis. + +### Conclusion + +Machine learning is a rapidly evolving field with vast applications across various industries. By enabling systems to learn from data and make informed decisions, it is transforming how we interact with technology and solving complex problems more efficiently. diff --git a/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md b/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md index 26cf596b7..76a29c9c4 100644 --- a/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md +++ b/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md @@ -3,21 +3,23 @@ id: letter-combinations-of-a-phone-number title: Letter Combinations of a Phone Number (LeetCode) sidebar_label: 0017 Letter Combinations of a Phone Number tags: - - Back Tracking - - Mapping - - String + - Back Tracking + - Mapping + - String description: The problem requires generating all letter combinations corresponding to given digits (2-9). The solution utilizes backtracking to explore all combinations efficiently, employing a recursive approach in Java. +sidebar_position: 17 --- ## Problem Description -| Problem Statement | Solution Link | LeetCode Profile | -| :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------- | -| [Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) | [Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) | [gabaniyash846](https://leetcode.com/u/gabaniyash846/) | +| Problem Statement | Solution Link | LeetCode Profile | +| :------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------- | +| [Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) | [Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) | [gabaniyash846](https://leetcode.com/u/gabaniyash846/) | ### Problem Description ## Problem Statement: + Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. ### Examples @@ -32,7 +34,6 @@ Given a string containing digits from 2-9 inclusive, return all possible letter - **Input:** `digits = ""` - **Output:** `[]` - #### Example 3 - **Input:** `2` @@ -47,9 +48,11 @@ Given a string containing digits from 2-9 inclusive, return all possible letter ### Approach 1. **Mapping Digits to Letters:** + - Define a mapping of digits to their corresponding letters, similar to telephone buttons. 2. **Backtracking Function:** + - Define a recursive backtracking function to generate all possible combinations. - The function takes four parameters: - `index`: The current index in the digits string. @@ -59,6 +62,7 @@ Given a string containing digits from 2-9 inclusive, return all possible letter - After the recursive call, we remove the last character from the combination (backtracking). 3. **Base Case:** + - If the length of the current combination is equal to the length of the input digits string, we add the combination to the result list. 4. **Main Function:** @@ -153,6 +157,7 @@ public class Solution { ``` #### CPP: + ```cpp #include #include @@ -208,40 +213,41 @@ int main() { ``` #### JavaScript + ```js /** * @param {string} digits * @return {string[]} */ -var letterCombinations = function(digits) { - if (digits.length === 0) return []; - - const digitToLetters = { - '2': 'abc', - '3': 'def', - '4': 'ghi', - '5': 'jkl', - '6': 'mno', - '7': 'pqrs', - '8': 'tuv', - '9': 'wxyz' - }; - - const combinations = []; - - const backtrack = (index, path) => { - if (index === digits.length) { - combinations.push(path); - return; - } - const letters = digitToLetters[digits.charAt(index)]; - for (let letter of letters) { - backtrack(index + 1, path + letter); - } - }; - - backtrack(0, ''); - return combinations; +var letterCombinations = function (digits) { + if (digits.length === 0) return []; + + const digitToLetters = { + 2: "abc", + 3: "def", + 4: "ghi", + 5: "jkl", + 6: "mno", + 7: "pqrs", + 8: "tuv", + 9: "wxyz", + }; + + const combinations = []; + + const backtrack = (index, path) => { + if (index === digits.length) { + combinations.push(path); + return; + } + const letters = digitToLetters[digits.charAt(index)]; + for (let letter of letters) { + backtrack(index + 1, path + letter); + } + }; + + backtrack(0, ""); + return combinations; }; // Example usage: @@ -249,39 +255,40 @@ console.log(letterCombinations("23")); // Output: ["ad","ae","af","bd","be","bf" ``` #### TypeScript + ```ts class Solution { - private digitToLetters: { [key: string]: string } = { - '2': 'abc', - '3': 'def', - '4': 'ghi', - '5': 'jkl', - '6': 'mno', - '7': 'pqrs', - '8': 'tuv', - '9': 'wxyz' + private digitToLetters: { [key: string]: string } = { + "2": "abc", + "3": "def", + "4": "ghi", + "5": "jkl", + "6": "mno", + "7": "pqrs", + "8": "tuv", + "9": "wxyz", + }; + + letterCombinations(digits: string): string[] { + const combinations: string[] = []; + + const backtrack = (index: number, path: string): void => { + if (index === digits.length) { + combinations.push(path); + return; + } + const letters = this.digitToLetters[digits.charAt(index)]; + for (let letter of letters) { + backtrack(index + 1, path + letter); + } }; - letterCombinations(digits: string): string[] { - const combinations: string[] = []; - - const backtrack = (index: number, path: string): void => { - if (index === digits.length) { - combinations.push(path); - return; - } - const letters = this.digitToLetters[digits.charAt(index)]; - for (let letter of letters) { - backtrack(index + 1, path + letter); - } - }; - - if (digits.length !== 0) { - backtrack(0, ''); - } - - return combinations; + if (digits.length !== 0) { + backtrack(0, ""); } + + return combinations; + } } // Example usage: @@ -294,9 +301,11 @@ console.log(solution.letterCombinations("23")); // Output: ["ad","ae","af","bd", Here's a step-by-step algorithm for generating all possible letter combinations of a given string of digits using backtracking: 1. **Define a mapping of digits to letters:** + - Create a map where each digit from 2 to 9 is mapped to its corresponding letters on a telephone keypad. 2. **Define a backtracking function:** + - The function will take the following parameters: - `index`: The current index in the digits string. - `path`: The current combination of letters. @@ -305,6 +314,7 @@ Here's a step-by-step algorithm for generating all possible letter combinations - After the recursive call, remove the last character from the combination (backtracking). 3. **Base Case:** + - If the length of the current combination is equal to the length of the input digits string, add the combination to the result list. 4. **Main Function:** @@ -312,4 +322,4 @@ Here's a step-by-step algorithm for generating all possible letter combinations - Call the backtracking function with the initial index set to 0 and an empty string as the initial combination. - Return the list of combinations. -This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking. \ No newline at end of file +This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.