You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contrib/machine-learning/Random_Forest.md
+52-45Lines changed: 52 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
-
Random Forest
1
+
# Random Forest
2
+
2
3
Random Forest is a versatile machine learning algorithm capable of performing both regression and classification tasks. It is an ensemble method that operates by constructing a multitude of decision trees during training and outputting the average prediction of the individual trees (for regression) or the mode of the classes (for classification).
3
4
4
-
Table of Contents
5
+
## Table of Contents
5
6
Introduction
6
7
How Random Forest Works
7
8
Advantages and Disadvantages
@@ -13,51 +14,54 @@ Hyperparameter Tuning
13
14
Regression Example
14
15
Conclusion
15
16
References
16
-
Introduction
17
+
18
+
## Introduction
17
19
Random Forest is an ensemble learning method used for classification and regression tasks. It is built from multiple decision trees and combines their outputs to improve the model's accuracy and control over-fitting.
18
20
19
-
How Random Forest Works
20
-
Bootstrap Sampling:
21
-
Random subsets of the training dataset are created with replacement. Each subset is used to train an individual tree.
22
-
Decision Trees:
23
-
Multiple decision trees are trained on these subsets.
24
-
Feature Selection:
25
-
At each split in the decision tree, a random selection of features is chosen. This randomness helps create diverse trees.
26
-
Voting/Averaging:
21
+
## How Random Forest Works
22
+
### 1. Bootstrap Sampling:
23
+
*Random subsets of the training dataset are created with replacement. Each subset is used to train an individual tree.
24
+
### 2. Decision Trees:
25
+
*Multiple decision trees are trained on these subsets.
26
+
### 3. Feature Selection:
27
+
*At each split in the decision tree, a random selection of features is chosen. This randomness helps create diverse trees.
28
+
### 4. Voting/Averaging:
27
29
For classification, the mode of the classes predicted by individual trees is taken (majority vote).
28
30
For regression, the average of the outputs of the individual trees is taken.
29
-
Detailed Working Mechanism
30
-
Step 1: Bootstrap Sampling: Each tree is trained on a random sample of the original data, drawn with replacement (bootstrap sample). This means some data points may appear multiple times in a sample while others may not appear at all.
31
-
Step 2: Tree Construction: Each node in the tree is split using the best split among a random subset of the features. This process adds an additional layer of randomness, contributing to the robustness of the model.
32
-
Step 3: Aggregation: For classification tasks, the final prediction is based on the majority vote from all the trees. For regression tasks, the final prediction is the average of all the tree predictions.
33
-
Advantages and Disadvantages
34
-
Advantages
35
-
Robustness: Reduces overfitting and generalizes well due to the law of large numbers.
36
-
Accuracy: Often provides high accuracy because of the ensemble method.
37
-
Versatility: Can be used for both classification and regression tasks.
38
-
Handles Missing Values: Can handle missing data better than many other algorithms.
39
-
Feature Importance: Provides estimates of feature importance, which can be valuable for understanding the model.
40
-
Disadvantages
41
-
Complexity: More complex than individual decision trees, making interpretation difficult.
42
-
Computational Cost: Requires more computational resources due to multiple trees.
43
-
Training Time: Can be slow to train compared to simpler models, especially with large datasets.
44
-
Hyperparameters
45
-
Key Hyperparameters
46
-
n_estimators: The number of trees in the forest.
47
-
max_features: The number of features to consider when looking for the best split.
48
-
max_depth: The maximum depth of the tree.
49
-
min_samples_split: The minimum number of samples required to split an internal node.
50
-
min_samples_leaf: The minimum number of samples required to be at a leaf node.
51
-
bootstrap: Whether bootstrap samples are used when building trees. If False, the whole dataset is used to build each tree.
52
-
Tuning Hyperparameters
31
+
### Detailed Working Mechanism
32
+
*#### Step 1: Bootstrap Sampling:
33
+
Each tree is trained on a random sample of the original data, drawn with replacement (bootstrap sample). This means some data points may appear multiple times in a sample while others may not appear at all.
34
+
*#### Step 2: Tree Construction:
35
+
Each node in the tree is split using the best split among a random subset of the features. This process adds an additional layer of randomness, contributing to the robustness of the model.
36
+
#### Step 3: Aggregation:
37
+
For classification tasks, the final prediction is based on the majority vote from all the trees. For regression tasks, the final prediction is the average of all the tree predictions.
38
+
### Advantages and Disadvantages
39
+
#### Advantages
40
+
* Robustness: Reduces overfitting and generalizes well due to the law of large numbers.
41
+
* Accuracy: Often provides high accuracy because of the ensemble method.
42
+
* Versatility: Can be used for both classification and regression tasks.
43
+
* Handles Missing Values: Can handle missing data better than many other algorithms.
44
+
* Feature Importance: Provides estimates of feature importance, which can be valuable for understanding the model.
45
+
#### Disadvantages
46
+
* Complexity: More complex than individual decision trees, making interpretation difficult.
47
+
* Computational Cost: Requires more computational resources due to multiple trees.
48
+
* Training Time: Can be slow to train compared to simpler models, especially with large datasets.
49
+
### Hyperparameters
50
+
#### Key Hyperparameters
51
+
* n_estimators: The number of trees in the forest.
52
+
* max_features: The number of features to consider when looking for the best split.
53
+
* max_depth: The maximum depth of the tree.
54
+
* min_samples_split: The minimum number of samples required to split an internal node.
55
+
* min_samples_leaf: The minimum number of samples required to be at a leaf node.
56
+
* bootstrap: Whether bootstrap samples are used when building trees. If False, the whole dataset is used to build each tree.
57
+
##### Tuning Hyperparameters
53
58
Hyperparameter tuning can significantly improve the performance of a Random Forest model. Common techniques include Grid Search and Random Search.
54
59
55
-
Code Examples
56
-
Classification Example
60
+
### Code Examples
61
+
#### Classification Example
57
62
Below is a simple example of using Random Forest for a classification task with the Iris dataset.
0 commit comments