fitcecoc and fitclinear are suitable for categorical data ?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Jon Cherrie
le 23 Avr 2021
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?
Réponses (0)
Voir également
Catégories
En savoir plus sur Support Vector Machine Classification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!