The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: with cell array of strings as Y
Replies: 8   Last Post: May 8, 2013 4:39 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Alan Weiss

Posts: 1,430
Registered: 11/27/08
Re: with cell array of strings as Y
Posted: May 7, 2013 10:53 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 5/7/2013 10:39 AM, Jay wrote:
> Hello!
> I believe there is either a bug in ClassificationKNN.predict or the
> documentation to is wrong (or both).
> 1.
> The documentation states, that Y is supposed to be a numeric vector,
> however in the example how to construct a KNN classifier 'species' of
> the dataset 'fisheriris' is used as Y which is a cell array of strings.
> 2.
> I have initialized my KNN classifier how it is done in the example,
> using a cell array of strings as Y. My "training" looks like this:
> mdl =,:),classLabels(train,:),
> 'BreakTies', 'nearest', 'NumNeighbors', testParams.k, 'Distance',
> @myDistance);
> If I now use classes = predict(mdl, featMat(test,:));
> I occasionally get errors. I believe this is the case when there are
> actually ties. The error is:
> Conversion to cell from double is not possible.
> Error in ClassificationKNN/predict (line 609)
> label(notNanRows(i)) =
> CNeighbor(notNanRows(i),inner);
> What can I do about it? Is that actually because I used a cell array
> of strings as Y? Do I have to convert my class labels to numbers then?
> 3.
> Also, while I am at it: If I want to see what examples were close to
> an input observation and influenced the classification (so to speak
> the nearest neighbors) I have no chance of doing that, do I? For that
> I would have to switch entirely to knnsearch?
> Thank you!

I am not sure where in the documentation you found your statement 1.
Here's what I see when I look at the current documentation:

Y - Grouping variables of response values with the same number of
elements (rows) as X. Each entry in Y is the response to the data in the
corresponding row of X.

This does not say that the variable must be a numeric vector, but a
grouping variable

As far as your problem 2, I am not sure what is going on. I wonder if
your function myDistance is giving you a problem somehow.

Alan Weiss
MATLAB mathematical toolbox documentation

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.