knn array type error

10 views
Skip to first unread message

entropy

unread,
Apr 14, 2010, 1:33:34 AM4/14/10
to mlpy-general
Ciao! Nice python package. Thanks!
I'm trying to implement a simple Knn learning algorithm with mlpy. The
initial setup was easy, but I've hit a wall with the following error
when using the Knn.predict() method:

TypeError: array cannot be safely cast to required type

I followed the "simple example" and setup training and testing data,
then ran Knn.compute. Next, the algorithm chokes on
Knn.predict(test_data). Any help would be very much appreciated.

thanks,
-Jesse

Davide Albanese

unread,
Apr 14, 2010, 4:40:01 AM4/14/10
to mlpy-general
Jasse,
could you show to me the output of ">>> print test_data.dtype"?

Jesse Berwald

unread,
Apr 14, 2010, 10:30:20 AM4/14/10
to mlpy-g...@googlegroups.com
The data is orginally int32, but I convert to float prior to calling
knn.compute() or knn.predict(). So here is the output:

In [11]: test_data.dtype
Out[11]: dtype('int32')

In [12]: test_data = asarray(tm, dtype=float)

In [13]: test_data.dtype
Out[13]: dtype('float64')

The last instance of test_data is what I have been working with. I
have tried to downcast to float32 in case nncore can't handle float64
on my 32-bit laptop. Same error. (In fact, same error on 32 and 64 bit
machines, actually.)

thanks for your help,
-Jesse

> --
> You received this message because you are subscribed to the Google Groups "mlpy-general" group.
> To post to this group, send email to mlpy-g...@googlegroups.com.
> To unsubscribe from this group, send email to mlpy-general...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mlpy-general?hl=en.
>
>

--
PhD Candidate
Department of Mathematics
Montana State University
Bozeman, MT

Davide Albanese

unread,
Apr 16, 2010, 4:48:53 PM4/16/10
to mlpy-general
Trunk version should fix the problem: $ svn checkout https://mlpy.fbk.eu/svn/trunk

Davide
> > For more options, visit this group athttp://groups.google.com/group/mlpy-general?hl=en.

Jesse Berwald

unread,
Apr 16, 2010, 5:32:32 PM4/16/10
to mlpy-g...@googlegroups.com
Grazie tanto!
Reply all
Reply to author
Forward
0 new messages