Repository: mlpack/mlpack

Issue #1710: ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Created: 2019-02-07T11:53:53Z
Issue description

>>>import pandas as pd
>>> import numpy as np
>>> import mlpack
>>> 
>>> df = pd.read_csv('housingdata.csv',header=None)
>>> 
>>> X = df.iloc[:,5]
>>> y = df.iloc[:,13]
>>> 
>>> output= mlpack.linear_regression(X,y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mlpack/linear_regression.pyx", line 119, in mlpack.linear_regression.linear_regression
  File "/home/nimish/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 1121, in __nonzero__
    .format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
>>> X = pd.DataFrame(X)
>>> y = pd.DataFrame(y)
>>> output= mlpack.linear_regression(X,y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mlpack/linear_regression.pyx", line 119, in mlpack.linear_regression.linear_regression
  File "/home/nimish/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 1121, in __nonzero__
    .format(self.__class__.__name__))
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Your environment

version of mlpack:3.0.4
operating system:Ubuntu

I have build mlpack from source.

Duplicate issue #1722: preprocess_split error , using sample code
Created: 2019-02-18T05:19:39Z
When I try python code like wrote in page
http://mlpack.org/docs/mlpack-3.0.4/doxygen/python_quickstart.html
I save these code in test.py ,and download http://www.mlpack.org/datasets/covertype-small.csv.gz into same dir.
df = pd.read_csv('covertype-small.csv.gz')
but I got the error:
File "test.py", line 12, in 
output = mlpack.preprocess_split(input=dataset,input_labels=labels,test_ratio=0.3)
File "mlpack/preprocess_split.pyx", line 104, in mlpack.preprocess_split.preprocess_split
File "mlpack/arma_numpy.pyx", line 63, in mlpack.arma_numpy.numpy_to_mat_s
ValueError: Buffer has wrong number of dimensions (expected 2, got 1)

the labels processed fail.
print(labels)
0        7
1        2
2        2
3        1
4        1
5        2
6        1
7        2
8        3
9        6
10       2
11       3
12       2
13       1
14       2
15       1
16       1
17       2
18       2
19       2
20       2
21       2
22       1
23       2
24       1
25       2
26       2
27       2
28       5
29       2
..
99970    2
99971    1
99972    1
99973    3
99974    1
99975    1
99976    1
99977    1
99978    1
99979    2
99980    2
99981    2
99982    2
99983    1
99984    2
99985    1
99986    1
99987    2
99988    5
99989    2
99990    1
99991    1
99992    1
99993    2
99994    2
99995    1
99996    1
99997    1
99998    1
99999    1
Name: label, Length: 100000, dtype: int64
>>> import mlpack >>> X=[[1,2],[2,3]]
>>> mlpack.preprocess_split(input=X,test_ratio=0.5,verbose=True) [INFO ] Training data contains 1 points.
[INFO ] Test data contains 1 points. {'test': array([[1., 2.]]), 'test_labels': array([], shape=(0, 0), dtype=int64), 'training': array([[2., 3.]]), 'training_labels': array([], shape=(0, 0), dtype=int64)}
>>> y=[4,5] >>> mlpack.preprocess_split(input=X,input_labels=y,test_ratio=0.5,verbose=True)
Traceback (most recent call last):  File "", line 1, in 
File "mlpack/preprocess_split.pyx", line 104, in mlpack.preprocess_split.preprocess_split File "mlpack/arma_numpy.pyx", line 63, in mlpack.arma_numpy.numpy_to_mat_s
ValueError: Buffer has wrong number of dimensions (expected 2, got 1) >>> y=[[4],[5]]
>>> mlpack.preprocess_split(input=X,input_labels=y,test_ratio=0.5,verbose=True) [INFO ] Training data contains 1 points.
[INFO ] Test data contains 1 points. {'test': array([[2., 3.]]), 'test_labels': array([[5]]), 'training': array([[1., 2.]]), 'training_labels': array([[4]])}
>>>

Closing comment (2019-02-18T16:37:34Z): I think that this is a duplicate of #1710.  Once that is addressed you should be able to pass in a two-dimensional matrix to a one-dimensional parameter (and vice versa).  Until then, @MuLx10's solution should work. 👍