0
$\begingroup$

The product manager wants to know if you can develop a model to predict the number of views a listing will receive based on the boat's features. She would consider using your model if, on average, the predictions were only 50% off of the true number of views a listing would receive.

(please interpret the bold sentence!!)

The data used in this: https://www.kaggle.com/datasets/karthikbhandary2/boat-sales

I tried using the RandomForestRegressor() model along with RandomizedSearchCV.

param = [
    {'n_estimators': [100, 200, 300, 400, 450, 500, 600, 700, 800, 900, 1000], 
     'max_depth': [3, 4, 6, 8, 10, 12,14,16,18,20], 
     'max_leaf_nodes': [15, 20, 25,30,35,40]}, 
]

rf = RandomForestRegressor(random_state=42)
rs_rf = RandomizedSearchCV(rf, param, cv = 4, n_jobs = -1, verbose = 1)
rs_rf.fit(X_train, y_train)

I tried using RMSE like this:

rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print(rmse)

I got the result as 483887.72666891955

My question is whether I am doing this right or not?

$\endgroup$
5
  • $\begingroup$ If you want to see how much the prediction is off from the actual value as a percentage you should look into using the mean average percentage error (MAPE). $\endgroup$
    – Oxbowerce
    Commented Mar 19, 2022 at 11:39
  • $\begingroup$ How can I do that? So RMSE is not the metric to use? $\endgroup$ Commented Mar 19, 2022 at 11:40
  • $\begingroup$ If you are mainly interested in the model's error as a percentage of the actual value then no. $\endgroup$
    – Oxbowerce
    Commented Mar 19, 2022 at 11:58
  • $\begingroup$ So I should go with MAPE? And How can I implement it? Can you submit it as an answer?? $\endgroup$ Commented Mar 19, 2022 at 12:04
  • $\begingroup$ Now it is returning 1.2265745506841434, after using the mean_average_percentage_error. $\endgroup$ Commented Mar 19, 2022 at 13:02

1 Answer 1

1
$\begingroup$

If you want to see how much the prediction is off from the actual value as a percentage you should look into using the mean average percentage error (MAPE). The scikit-learn library has this loss implemented in the metrics package. You can simply call the mean_absolute_percentage_error function instead of the mean_squared_error you're currently using:

mean_absolute_percentage_error(y_true, y_pred)
$\endgroup$
6
  • $\begingroup$ Now it is returning 1.2265745506841434, after using the mean_average_percentage_error. $\endgroup$ Commented Mar 19, 2022 at 13:07
  • $\begingroup$ So how can I interpret 1.2265 as? Is it 1% or what? Can you tell me @Oxbowerce $\endgroup$ Commented Mar 19, 2022 at 14:02
  • $\begingroup$ A value of 1.2265 means that on average, your model's predictings are off by 122.65% from the actual values the model is trying to predict. $\endgroup$
    – Oxbowerce
    Commented Mar 19, 2022 at 14:22
  • $\begingroup$ Can you give me some advice on how to improve it? $\endgroup$ Commented Mar 19, 2022 at 14:25
  • $\begingroup$ Not really, as this is really dependent on the type of problem you are working on. In general, try to really understand the data you're working with, see what features are correlated with what you're trying to predict, and see if feature engineering can help create more meaningful features for your model to use. $\endgroup$
    – Oxbowerce
    Commented Mar 19, 2022 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.