fitcecoc and fitclinear are suitable for categorical data ?

1 次查看(过去 30 天)
Hi,
I'm a newbie in Machine Learning and i'm trying to create a model on a kaggle dataset below.
The thing is i'd like to use k-fold crossvalidation on my model but i cannot use fifcecoc and fitclinear functions because they only accept numerical values whereas i also have some categorical ones.
Is there a way to use them with categorical data or i need to use cvpartition for k-fold crossvalidation due to the fact that my dataset not completely numerical ?
Also can i use regularization with categorical variables ?
  1 个评论
Jon Cherrie
Jon Cherrie 2021-4-23
You should be able to use fitcecoc with categorical predictors and k-fold cross-validation. Here is an example using the "carbig" data and k=5 folds:
load carbig.mat
t = table(Acceleration,Cylinders,Displacement,Horsepower,Mfg,Model_Year,MPG,Origin,Weight);
t.Mfg = categorical(cellstr(t.Mfg));
t.Cylinders = categorical(t.Cylinders);
t.Origin = categorical(cellstr(t.Origin));
m = fitcecoc(t,"Cylinders","KFold",5)
In this cases I get warning about unique class values (which I think means I have more folds than this data will tolerate), but I can see the categorical predictors in the output:
>> m
m =
ClassificationPartitionedECOC
CrossValidatedModel: 'ECOC'
PredictorNames: {'Acceleration' 'Displacement' 'Horsepower' 'Mfg' 'Model_Year' 'MPG' 'Origin' 'Weight'}
CategoricalPredictors: [4 7]
ResponseName: 'Cylinders'
NumObservations: 406
KFold: 5
Partition: [1×1 cvpartition]
ClassNames: [3 4 5 6 8]
ScoreTransform: 'none'
If this example, doesn't work for you, can you share some code and an error message?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Classification Ensembles 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by