Computer scienceData scienceInstrumentsScikit-learnTraining ML models with scikit-learnClassification in scikit-learn

Random forest in scikit-learn

Accuracy calculation

Report a typo

To get a more objective evaluation of the RF model used in the topic, we can make another train and test sets and calculate the metric again.

In order to do it, follow these steps:

  1. Load the iris flower dataset.

  2. Split data into train and test sets using train_test_split function with the following parameters: test_size=0.4 , random_state=182.

  3. Create an instance of RandomForestClassifier model with the following parameters: n_estimators=15, max_features=2, oob_score=True, random_state=127. Then, fit it on the train set.

  4. Get the accuracy score of your model by calling the .score() method on the test data.

Insert the output in the answer field. Round it to three digits after the decimal point.

Tip: To load and split the dataset, just copy the code below:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=182)
Enter a number
___

Create a free account to access the full topic