Python: questions about format in SVM coding
Question: I want to use svm to do supervised machine learning. My project is: Given
Obama's several speeches, and Romney's several speeches, the classifier can
decide which speaker spoke this speech when we input an unknown speech.

The code on the site wrote like this: SVC, NuSVC and LinearSVC take as input
two arrays: an array **X** of size **[n_samples, n_features]** holding the
training samples, and an array **Y** of **integer values** , **size
[n_samples]** , holding the class labels for the training samples:

    
    
    >>> from sklearn import svm
    >>> X = [[0, 0], [1, 1]]
    >>> y = [0, 1]
    >>> clf = svm.SVC()
    >>> clf.fit(X, y)  
    SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3,
    gamma=0.0, kernel='rbf', max_iter=-1, probability=False, random_state=None,
    shrinking=True, tol=0.001, verbose=False)
    

After being fitted, the model can then be used to predict new values:

    
    
    >>> clf.predict([[2., 2.]])
    array([1])
    

**My question** : **1.In my project, in**

    
    
    X = [[0, 0], [1, 1]]
    

Should I replace the first number in each square bracket with label ‘Obama’ or
'Romeny'.

**2.And how about**

    
    
    y = [0, 1]
    

The component should be replaced by 'Obama' or 'Romney', either? But it should
be integer number based on the code annotation above.

**3.And about the content in the clf.predict()**

    
    
    clf.predict([[2., 2.]])
    

Shouldn't be just your extracted feature of your input, then the classifier
decide which category(obama or romney) it belongs to. Why there is two
component?


Answer: Question #1: No. Your X should contain the information you want to use to
predict who gave the speech. Presumably this will be dervied somehow from the
text of the speech. Take a look at [the text feature
extraction](http://scikit-
learn.org/stable/modules/feature_extraction.html#text-feature-extraction) for
some ideas.

Question #2: Yes, because y is what you want to predict, and you want to
predict whether it was Obama or Romney.

Question #3: There are two components because in that example the input has
two features. Your data may have any number of features. If you're using text
data to predict something, you will usually have a lot of features (in the
simplest case, one feature per distinct word in the texts, although you may
trim this down by eliminating some words, like frequent function words such as
"the").

