I am doing a task on supervised learning. I have two set of data -training and test.
My training data-set is about 2000 records. My test data has 10 records.
When I run the following code, the predict function gives the same value as output.
I am not sure what I am doing wrong... I tried changing the value of gamma and C. Still no luck..
I am wondering if this:
Here is the complete python code:
import pandas as pd
training_data = pd.read_csv("Train_wo_Header.csv") #I read my training data set
data = training_data.ix[:,[0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]] #picking up all rows expect index 2, which is my output
target = training_data.ix[:,[2]]
from sklearn import svm #Code from the URL above
clf = svm.SVC(gamma=0.001, C=100.)
clf.fit(data,target)
test_data = pd.read_csv("test_wo_Header.csv") #this is my test data
clf.predict(test_data[-10:]) #predicting the last 10 values
Here is the output:
array([7734, 7734, 7734, 7734, 7734, 7734, 7734, 7734, 7734, 7734], dtype=int64)
I even tried using LinearSVC. Still no luck. The only difference is that the predicted output is a different value (9240), but same throughout ...
Always giving the same output can have 2 causes :
You didn't seem to convert your Pandas DataFrame to a numpy array, try
clf = svm.SVC()
X = data.values
Y = target.values
assert len(X) == len(Y)
clf.fit(X,Y)
print clf.score(X,Y)
Do the same for your test data and try to print at least the shape of your data and one element of your arrays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With