I am building a model that recommends the optimal golf club based on data I have gathered. Since the model prediction should be a category, ie. a golf club, I would assume I would have to use a classifier algorithm. However, I have label encoded the types of golf clubs in an ordinal way from 1-14 (1 being the club with longer distance shots and 14 being the one for shortest shots) and have run both random forest regressor and classifier with scikit-learn and the regressor is more accurate. Why is this?
-
1$\begingroup$ First, it sounds more like a regression problem. Second, how do you judge “better”? $\endgroup$– TimCommented May 6, 2022 at 20:38
-
$\begingroup$ The accuracy score of both differ by 4%. So it is not a big difference. However, looking at how to create a ml algorithm, it says that if the predicted output is a category a classification algorithm should be used. Hence I tried SVM, KNN, Random forest classification, decision tree classifier and NaivesBayes (all classification algorithm) however none give a better accuracy score that the random forest regressor. $\endgroup$– GUILLE DOMINGUEZCommented May 6, 2022 at 20:46
-
$\begingroup$ How did you calculate accuracy for regression? $\endgroup$– TimCommented May 6, 2022 at 21:20
-
$\begingroup$ By using the method .score(X_test, y_test) $\endgroup$– GUILLE DOMINGUEZCommented May 6, 2022 at 21:32
1 Answer
From the comments:
- How did you calculate accuracy for regression?
- By using the method .score(X_test, y_test)
RandomForestRegressor and RandomForestClassifier return completely different metrics when you call the score
functions. Regressor returns coefficient of determination ($R^2$), while for classifier the accuracy. You cannot compare those numbers, it's comparing apples to oranges. There is also no way to calculate accuracy for a regression problem because it doesn't do classification while accuracy is a classification metric (a poor one, by the way).
So the results you observed tell you nothing that allows you to tell that one of the approaches worked better than the another.
-
1$\begingroup$ Ok this is a useful answer. Thanks! What other metric exist to analyse the performance of classifier algorithms? $\endgroup$ Commented May 6, 2022 at 22:30
-
$\begingroup$ @GUILLEDOMINGUEZ there are many metrics, but the basic question is if you want a classification or regression metric? If it’s ordinal regression then stats.stackexchange.com/q/9741/35989 $\endgroup$– TimCommented May 7, 2022 at 5:00