data = load_diabetes(as_frame=True) df = data.frame
After that, we separate the features from the target variable. Here, the last column contains the target variable. So, we are dropping the last column named “target” to get the features. And then, we filter the last column to get the target variable.
df_features = df.drop(labels=["target"], axis=1) df_target = df.filter(items=["target"])
Now, we split the dataset into training and test set.
X_train, X_test, y_train, y_test = train_test_split(df_features, df_target["target"], shuffle=True, random_state=1)
Please note that the shuffle=True argument indicates that we shuffle the data before splitting. And random_state argument is used to initialize the pseudo-random number generator that is used to shuffle the data.
regressor = ExtraTreesRegressor(n_estimators=100) regressor.fit(X_train, y_train) y_test_pred = regressor.predict(X_test)
Now, we initialize the ExtraTreesRegressor. Then, we fit the regressor with the training dataset. After that, we can use the regressor to predict the target variable for the test set.
Please note that the n_estimators parameter in the argument specifies the number of decision trees in the forest.
mae = mean_absolute_error(y_test, y_test_pred)
rmse = mean_squared_error(y_test, y_test_pred, squared=False)
print("Mean Absolute Error: ", mae)
print("Root Mean Square Error: ", rmse)
Finally, we need to evaluate the model. We are here calculating the Mean Absolute Error (MAE) and the Root Mean Square Error (RMSE) to evaluate the performance of the model.
The output of the above program will be:
Mean Absolute Error: 44.81918918918918 Root Mean Square Error: 57.83962522307649








































0 Comments