fitcecoc and fitclinear are suitable for categorical data ?

조회 수: 1 (최근 30일)
Gorkem Akgul
Gorkem Akgul 2021년 4월 23일
댓글: Jon Cherrie 2021년 4월 23일
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에서 Support Vector Machine Classification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by