combining text and numeric matrices
2 ビュー (過去 30 日間)
古いコメントを表示
My dataset has 6 predictors (all ordinal text values e.g. good, better, best) and 1 response (ordinal numeric value e.g. 1,2,3) column. When I’m trying to combine these into 7 columns for further classification study, I’m shown the following error ’ Error using horzcat Dimensions of matrices being concatenated are not consistent. ’ Any suggestion?
10 件のコメント
Walter Roberson
2018 年 2 月 9 日
Re-read your documentation. For R2015b: https://www.mathworks.com/help/releases/R2015b/stats/mnrfit.html#inputarg_Y
Response values, specified as a column vector or a matrix. Y can be one of the following:
- An n-by-k matrix, where Y(i,j) is the number of outcomes of the multinomial category j for the predictor combinations given by X(i,:). In this case, the number of observations are made at each predictor combination.
- An n-by-1 column vector of scalar integers from 1 to k indicating the value of the response for each observation. In this case, all sample sizes are 1.
- An n-by-1 categorical array indicating the nominal or ordinal value of the response for each observation. In this case, all sample sizes are 1.
回答 (1 件)
Kai Domhardt
2018 年 2 月 7 日
I am going to assume, that your predictors matrix is of type 'm x 6 Cell'.
temp = randi(3,10,6);
predictors = cell(10,6);
predictors(temp==1) = {'good'};
predictors(temp==2) = {'better'};
predictors(temp==3) = {'best'};
response = randi(3,10,1);
This results in:
predictors =
{'good' } {'good' } ...
{'better'} {'best' } ...
... ...
and
response =
1
2
...
When you want to combine them you, need to convert your numerical array 'response' into an cell array to match the type of 'predictors':
combined = [predictors, num2cell(response)];
参考
カテゴリ
Help Center および File Exchange で Classification Trees についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!