On the one hand, people say pandas goes along great with scikit-learn. For example, pandas series objects fit well with sklearn models in this video. On the other hand, there is sklearn-pandas providing a bridge between Scikit-Learn’s machine learning methods and pandas-style Data Frames which means there is a need for such libraries. Moreover, some people, for example, convert pandas data frames to numpy array for fitting a model.
I wonder whether it's possible to combine pandas and scikit-learn without any additional methods and libraries. My problem is that whenever I fit my data set to sklearn models in the following way:
import numpy as np
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn.svm import SVC
d = {'x': np.linspace(1., 100., 20), 'y': np.linspace(1., 10., 20)}
df = pd.DataFrame(d)
train, test = train_test_split(df, test_size = 0.2)
trainX = train['x']
trainY = train['y']
lin_svm = SVC(kernel='linear').fit(trainX, trainY)
I receive an error:
ValueError: Unknown label type: 19 10.000000
0 1.000000
17 9.052632
18 9.526316
12 6.684211
11 6.210526
16 8.578947
14 7.631579
10 5.736842
7 4.315789
8 4.789474
2 1.947368
13 7.157895
1 1.473684
6 3.842105
3 2.421053
Name: y, dtype: float64
As far as I understand that's because of the data structure. However, there are few examples on the internet using similar code without any problems.