# Random Forest

## What is Random Forest?

Random forest is an [ensemble learning](https://en.wikipedia.org/wiki/Ensemble_learning) method/technique for [classification](https://en.wikipedia.org/wiki/Statistical_classification) and [regression](https://en.wikipedia.org/wiki/Regression_analysis) tasks that operates by constructing a multitude of [decision trees](https://en.wikipedia.org/wiki/Decision_tree_learning) at training time.&#x20;

For **classification tasks**, the output of the random forest is the class selected by most trees.\
For **regression tasks**, the mean or average prediction of the individual trees is returned.

***

### Random Forest Classifier

#### Importing:

```python
from sklearn.ensemble import RandomForestClassifier

```

#### Training the module:

```python
clf = RandomForestClassifier(random_state=42)
# Creating a Random Forest classifier object

clf.fit(X_train, y_train)
# Training the classifier on the training data
```

#### Making predictions:

```
y_pred = clf.predict(X_test)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://digitalgarden.batamladen.com/notes/machine-learning/learning-algorythm-types/supervised-ml/random-forest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
