Info

此问题已关闭。 请重新打开它进行编辑或回答。

Multi Variable Categorical Regression

1 次查看(过去 30 天)
Connor Stepkoski
Connor Stepkoski 2020-4-20
关闭: MATLAB Answer Bot 2021-8-20
I'm attempting to build a predictor for attendence at baseball games. Based on 5 variables, 4 of which are categorical. I've tried a multitude of different things and am having no luck. Does anyone have any advice/ideas on how I should go about this?
I've attatched the data I've compsed.
  1 个评论
the cyclist
the cyclist 2020-4-20
It would be helpful to know ...
  • what sorts of things you tried (e.g. which MATLAB functions?)
  • what does "having no luck" mean? Do you have code that crashes? Code that runs, but doesn't result in a "good" model?
  • whether or not you have the Statistics and Machine Learning Toolbox
  • a little bit of info on your level of experience with MATLAB
  • a little bit of info on your level of experience using predictive models (either in MATLAB or other language)

回答(1 个)

the cyclist
the cyclist 2020-4-20
编辑:the cyclist 2020-4-20
The following code fits a binary regression tree to your data:
baseballData = readtable('BaseballData.xlsx'); % Load the data into a table
baseballData.Date = []; % Remove the date, which presumably should not be used for prediction
tree = fitrtree(baseballData,'Attendence'); % Fit the model
You can then predict attendance for a particular set of parameters. Here, I predict attendance for the first row of the table:
predict(tree,baseballData(1,:))
You could also do a simple linear model using
linear = fitlm(baseballData)
Note that for both of these models, the syntax is particularly simple because your response variable happens to be the last variable in the table (which is the default assumption by MATLAB), and because the functions are able to figure out automatically which variables are categorical.
  1 个评论
the cyclist
the cyclist 2020-4-20
Before running this, remove the rows in the table (e.g. row 82) that just has the year and no other data.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by