# Do random forests work better than multinomial logistic regression for prrediction of categorical non-binary variables? Why?

I posted another question that was well received. I am posting this new question because it was suggested by other members of Cross Validated. Here is the link of the original question that I posted: In R Linear Regression , a categorical variable is changed to numeric to build a model. Would that trick work to predict a categorical variable?

Do Random Forests work better than Multinomial Logistic Regression for Prediction of Categorical Non-Binary Variables? Why?

In the previous question was suggested that Multinomial Logistic Regression works better for inference and that Random Forest works better for prediction. One of the goals of this question is to learn more about that answer.

Also, I would like to learn the R code for Multinomial Logistic Regression. In the other question, I published a R code for Linear Regression that worked well, in the sense that I got no warnings, but the results had no sense according to @RobertLong This question is a follow up of the previous question. That is why you do not see too much code.

The data is in the following link: Data for this question

I am trying to predict the last column called classe.

So, at this point, I only have few lines of code.

library(caTools)
set.seed(123)

split= sample.split(dataset\$classe, SplitRatio = 7/10)
training_set = subset(dataset, split==TRUE)
testing_set = subset(dataset, split==FALSE)


@Sycorax wrote that we cannot generalize. I agree and disagree at the same time. I agree with his idea that everything depends on the kind of problem. However, I disagree because my question has some particular features that affect the algorithm performance. I am a beginner, but I am reading the book "Practical machine Learning in R," written by Fred Nwanganga and Mike Chapple. They mention that every algorithm has weaknesses and strengths. As we are predicting a non-binary categorical variable, that affects which one is the best algorithm for that purpose. Additionally, I read that some algorithms do not work well with "a large" number of continuous features I did not find what "large" means. Also, for this question we have a particular dataset with 52 numeric variables. I counted manually around 30 integer variables. In this question, I would think that we are analyzing this particular dataset, and by extension, datasets similar to this one.

@jluchman asked me a great question: what better means? I am just a beginner, but correct me if I am wrong. In my perspective, linear regression gives us ideas that can be explained easier than results that are obtained with other methods. However, I just bought some new books, and I am seeing that many authors are skipping multinomial logistic regression for this type of problems and they are going more with naive Bayes, random forests, etc. However, I still need to check some linear regression books.

New contributor
Beginner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• Multinomial logistic regression is machine learning… – astel 2 days ago
• You might want to review how multinomial logistic regression relates to logistic regression before you dive into more sophisticated machine learning models. – Dave 2 days ago
• Random forest is better for problems where random forest does better. Multinomial logistic regression is better for problems where multinomial logisitc regression is better. If you've found that one is better/worse on your problem, then perhaps we can conclude certain properties about your problem, the available data, the choice of features, or the choice of hyper-parameters, but any categorical statements about the utility of the methods across all problems would be overstated. – Sycorax 2 days ago
• "However, I disagree because my question has some particular features that affect the algorithm performance." This is what I mean when I say "If you've found that one is better/worse on your problem, then perhaps we can conclude certain properties about your problem, the available data, the choice of features, or the choice of hyper-parameters" -- at most, you've found that one method works better for your problem than an alternative. – Sycorax yesterday
• One thing that could help to answer the question is a sense for what "better" means for the use of the model? Are you seeking to find an easy to explain model for a specific audience? Are you seeking to find a predictive function that predicts as well as possible for some production application? I anticipate the best tool for the job likely depends on what the need for the model is. – jluchman 23 hours ago