Skip to content

Commit 92295c1

Browse files
authored
Merge pull request #1108 from Hemav009/ml
Added machine learning in tutorials
2 parents 58e0120 + bdf5443 commit 92295c1

File tree

2 files changed

+146
-65
lines changed

2 files changed

+146
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
id: Machine Learning
3+
title: Introduction to Machine Learning
4+
sidebar_label: An Introduction to Machine Learning
5+
sidebar_position: 8
6+
tags: [ML, Type of Ml, Libraries]
7+
description: "Learn Basics of ML."
8+
---
9+
10+
**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.
11+
12+
#### Key Concepts in Machine Learning
13+
14+
1. **Data**: The foundational component of machine learning. It includes structured data (like databases) and unstructured data (like text, images, videos).
15+
2. **Algorithms**: Set of rules and statistical techniques used to learn patterns from data. Popular algorithms include linear regression, decision trees, and neural networks.
16+
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.
17+
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.
18+
5. **Testing**: Evaluating the performance of a trained model on new, unseen data to ensure it generalizes well.
19+
20+
#### Types of Machine Learning
21+
22+
1. **Supervised Learning**:
23+
24+
- **Definition**: Learning from labeled data, where the outcome is known.
25+
- **Examples**: Spam detection, image classification, and medical diagnosis.
26+
- **Algorithms**: Linear regression, logistic regression, support vector machines, neural networks.
27+
28+
2. **Unsupervised Learning**:
29+
30+
- **Definition**: Learning from unlabeled data, where the system tries to find hidden patterns.
31+
- **Examples**: Customer segmentation, anomaly detection, and clustering.
32+
- **Algorithms**: K-means clustering, hierarchical clustering, association rules.
33+
34+
3. **Semi-supervised Learning**:
35+
- **Definition**: A mix of supervised and unsupervised learning. It uses a small amount of labeled data and a large amount of unlabeled data.
36+
- **Examples**: Web content classification, speech analysis.
37+
4. **Reinforcement Learning**:
38+
- **Definition**: Learning by interacting with an environment. The system takes actions and learns from the feedback (rewards or punishments).
39+
- **Examples**: Game playing (like AlphaGo), robotics, resource management.
40+
- **Algorithms**: Q-learning, deep Q networks, policy gradients.
41+
42+
#### Key Steps in Machine Learning Workflow
43+
44+
1. **Data Collection**: Gathering relevant data from various sources.
45+
2. **Data Preparation**: Cleaning and preprocessing data to make it suitable for modeling. This includes handling missing values, normalizing data, and feature selection.
46+
3. **Choosing a Model**: Selecting an appropriate algorithm based on the problem and data.
47+
4. **Training the Model**: Feeding data into the algorithm to learn patterns.
48+
5. **Evaluating the Model**: Using metrics like accuracy, precision, recall, F1-score, and confusion matrix to assess the model's performance.
49+
6. **Hyperparameter Tuning**: Adjusting the algorithm's parameters to improve performance.
50+
7. **Prediction**: Using the trained model to make predictions on new data.
51+
8. **Deployment**: Integrating the model into a real-world application for use.
52+
53+
#### Popular Tools and Libraries
54+
55+
- **Programming Languages**: Python, R, Julia.
56+
- **Libraries**:
57+
- **Python**: scikit-learn, TensorFlow, Keras, PyTorch, XGBoost.
58+
- **R**: caret, randomForest, nnet.
59+
60+
#### Applications of Machine Learning
61+
62+
1. **Healthcare**: Disease prediction, personalized treatment plans.
63+
2. **Finance**: Fraud detection, algorithmic trading.
64+
3. **Marketing**: Customer segmentation, recommendation systems.
65+
4. **Manufacturing**: Predictive maintenance, quality control.
66+
5. **Transportation**: Self-driving cars, route optimization.
67+
6. **Entertainment**: Content recommendation, sentiment analysis.
68+
69+
### Conclusion
70+
71+
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.

dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md

+75-65
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ id: letter-combinations-of-a-phone-number
33
title: Letter Combinations of a Phone Number (LeetCode)
44
sidebar_label: 0017 Letter Combinations of a Phone Number
55
tags:
6-
- Back Tracking
7-
- Mapping
8-
- String
6+
- Back Tracking
7+
- Mapping
8+
- String
99
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.
10+
sidebar_position: 17
1011
---
1112

1213
## Problem Description
1314

14-
| Problem Statement | Solution Link | LeetCode Profile |
15-
| :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------- |
16-
| [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/) |
15+
| Problem Statement | Solution Link | LeetCode Profile |
16+
| :------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------- |
17+
| [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/) |
1718

1819
### Problem Description
1920

2021
## Problem Statement:
22+
2123
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.
2224

2325
### Examples
@@ -32,7 +34,6 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
3234
- **Input:** `digits = ""`
3335
- **Output:** `[]`
3436

35-
3637
#### Example 3
3738

3839
- **Input:** `2`
@@ -47,9 +48,11 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
4748
### Approach
4849

4950
1. **Mapping Digits to Letters:**
51+
5052
- Define a mapping of digits to their corresponding letters, similar to telephone buttons.
5153

5254
2. **Backtracking Function:**
55+
5356
- Define a recursive backtracking function to generate all possible combinations.
5457
- The function takes four parameters:
5558
- `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
5962
- After the recursive call, we remove the last character from the combination (backtracking).
6063

6164
3. **Base Case:**
65+
6266
- 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.
6367

6468
4. **Main Function:**
@@ -153,6 +157,7 @@ public class Solution {
153157
```
154158

155159
#### CPP:
160+
156161
```cpp
157162
#include <iostream>
158163
#include <vector>
@@ -208,80 +213,82 @@ int main() {
208213
```
209214
210215
#### JavaScript
216+
211217
```js
212218
/**
213219
* @param {string} digits
214220
* @return {string[]}
215221
*/
216-
var letterCombinations = function(digits) {
217-
if (digits.length === 0) return [];
218-
219-
const digitToLetters = {
220-
'2': 'abc',
221-
'3': 'def',
222-
'4': 'ghi',
223-
'5': 'jkl',
224-
'6': 'mno',
225-
'7': 'pqrs',
226-
'8': 'tuv',
227-
'9': 'wxyz'
228-
};
229-
230-
const combinations = [];
231-
232-
const backtrack = (index, path) => {
233-
if (index === digits.length) {
234-
combinations.push(path);
235-
return;
236-
}
237-
const letters = digitToLetters[digits.charAt(index)];
238-
for (let letter of letters) {
239-
backtrack(index + 1, path + letter);
240-
}
241-
};
242-
243-
backtrack(0, '');
244-
return combinations;
222+
var letterCombinations = function (digits) {
223+
if (digits.length === 0) return [];
224+
225+
const digitToLetters = {
226+
2: "abc",
227+
3: "def",
228+
4: "ghi",
229+
5: "jkl",
230+
6: "mno",
231+
7: "pqrs",
232+
8: "tuv",
233+
9: "wxyz",
234+
};
235+
236+
const combinations = [];
237+
238+
const backtrack = (index, path) => {
239+
if (index === digits.length) {
240+
combinations.push(path);
241+
return;
242+
}
243+
const letters = digitToLetters[digits.charAt(index)];
244+
for (let letter of letters) {
245+
backtrack(index + 1, path + letter);
246+
}
247+
};
248+
249+
backtrack(0, "");
250+
return combinations;
245251
};
246252
247253
// Example usage:
248254
console.log(letterCombinations("23")); // Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
249255
```
250256

251257
#### TypeScript
258+
252259
```ts
253260
class Solution {
254-
private digitToLetters: { [key: string]: string } = {
255-
'2': 'abc',
256-
'3': 'def',
257-
'4': 'ghi',
258-
'5': 'jkl',
259-
'6': 'mno',
260-
'7': 'pqrs',
261-
'8': 'tuv',
262-
'9': 'wxyz'
261+
private digitToLetters: { [key: string]: string } = {
262+
"2": "abc",
263+
"3": "def",
264+
"4": "ghi",
265+
"5": "jkl",
266+
"6": "mno",
267+
"7": "pqrs",
268+
"8": "tuv",
269+
"9": "wxyz",
270+
};
271+
272+
letterCombinations(digits: string): string[] {
273+
const combinations: string[] = [];
274+
275+
const backtrack = (index: number, path: string): void => {
276+
if (index === digits.length) {
277+
combinations.push(path);
278+
return;
279+
}
280+
const letters = this.digitToLetters[digits.charAt(index)];
281+
for (let letter of letters) {
282+
backtrack(index + 1, path + letter);
283+
}
263284
};
264285

265-
letterCombinations(digits: string): string[] {
266-
const combinations: string[] = [];
267-
268-
const backtrack = (index: number, path: string): void => {
269-
if (index === digits.length) {
270-
combinations.push(path);
271-
return;
272-
}
273-
const letters = this.digitToLetters[digits.charAt(index)];
274-
for (let letter of letters) {
275-
backtrack(index + 1, path + letter);
276-
}
277-
};
278-
279-
if (digits.length !== 0) {
280-
backtrack(0, '');
281-
}
282-
283-
return combinations;
286+
if (digits.length !== 0) {
287+
backtrack(0, "");
284288
}
289+
290+
return combinations;
291+
}
285292
}
286293

287294
// Example usage:
@@ -294,9 +301,11 @@ console.log(solution.letterCombinations("23")); // Output: ["ad","ae","af","bd",
294301
Here's a step-by-step algorithm for generating all possible letter combinations of a given string of digits using backtracking:
295302

296303
1. **Define a mapping of digits to letters:**
304+
297305
- Create a map where each digit from 2 to 9 is mapped to its corresponding letters on a telephone keypad.
298306

299307
2. **Define a backtracking function:**
308+
300309
- The function will take the following parameters:
301310
- `index`: The current index in the digits string.
302311
- `path`: The current combination of letters.
@@ -305,11 +314,12 @@ Here's a step-by-step algorithm for generating all possible letter combinations
305314
- After the recursive call, remove the last character from the combination (backtracking).
306315

307316
3. **Base Case:**
317+
308318
- If the length of the current combination is equal to the length of the input digits string, add the combination to the result list.
309319

310320
4. **Main Function:**
311321
- Initialize an empty list to store the combinations.
312322
- Call the backtracking function with the initial index set to 0 and an empty string as the initial combination.
313323
- Return the list of combinations.
314324

315-
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
325+
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.

0 commit comments

Comments
 (0)