SVM using scikit

by: Geet Sameer, 8 years ago


[CODE]
import pandas as pd
import numpy as np
from sklearn import svm, preprocessing
FEATURES = ['WAGE'']
def Build_Data_Set():
df = pd.read_csv("IT_new1.csv")
df = df.reindex(np.random.permutation(df.index))
df = df.replace("NaN",0).replace("N/A",0)
X = np.array(df[FEATURES].values)
y = df['Outcome'].values.tolist()
        X = preprocessing.scale(X)
return X,y


def Analysis():
test_size = 1000
X,y = Build_Data_Set()
print(len(X))
clf = svm.SVC(kernel="linear", C= 1.0)
clf.fit(X[:-test_size],y[:-test_size])

correct_count = 0
for x in range(1,test_size + 1):
if clf.predict(X[-x])[0] == y[-x]:
correct_count += 1

print("Accuracy:", (correct_count/test_size) * 100)


Build_Data_Set()
Analysis()
[/CODE]


Explanation : Wage is numerical column
ERROR: C:UsersHPAnaconda2libsite-packagessklearnutilsvalidation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)

Please tell me how to get rid of this error



You must be logged in to post. Please login or register an account.



Check out this tutorial towards the end where we talk specifically on this error: https://pythonprogramming.net/k-nearest-neighbors-application-machine-learning-tutorial/

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.