Sobes.tech
Junior — Middle

Rääkige mulle RandomForestist: kuidas see on üles ehitatud, kuidas see erineb tavalisest puude baggingust.

sobes.tech AI

Vastus AI-lt

RandomForest is an ensemble machine learning method that builds multiple decision trees and combines their predictions to improve the model's quality and stability.

Main features of RandomForest:

  • Each tree is trained on a random sample of the original data with replacement (bagging).
  • During the construction of each tree, at each node, a random subset of features is selected, and the best one is chosen for splitting.

Differences from traditional tree bagging:

  • In traditional bagging, trees are built on random data subsets, but the feature used for splitting is the entire feature set.
  • In RandomForest, additional randomness is introduced in feature selection at each node, reducing correlation between trees and increasing generalization ability.

Python example using sklearn:

from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier(n_estimators=100, max_features='sqrt')
model.fit(X_train, y_train)
predictions = model.predict(X_test)

Here, the parameter max_features='sqrt' sets a random subset of features for each split.