I am new to this so any help is appriciated, this code was given to me by my prof when I asked for an example, I had hoped for a working model...
from numpy import loadtxt
import numpy as np
from sklearn import svm
from sklearn.metrics import accuracy_score, f1_score
from sklearn.feature_selection import SelectPercentile, f_classif
Read data
data = loadtxt('running.txt')
label = loadtxt('walking.txt')
X = data
y = label
Define walking status as 0, running status as 1
print('Class labels:', np.unique(y))
Random pick 50% data as test data and leave the rest as train data
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)
Use sklearn to select 50% features
selector = SelectPercentile(f_classif, 50)
selector.fit(X_train, y_train)
X_train_transformed = selector.transform(X_train)
X_test_transformed = selector.transform(X_test)
Apply support vector machine algorithm
clf = svm.SVC(kernel="rbf", C=1)
clf.fit(X_train_transformed, y_train)
SVC(C=1, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',max_iter=-1,probability=False, random_state=None, shrinking=True,tol=0.001, verbose=False)
pred=clf.predict(X_test_transformed)
print("Accuracy is %.4f and the f1-score is %.4f " %
(accuracy_score(pred, y_test), f1_score(y_test, pred)))
Traceback (most recent call last): File "", line 1, in File "C:\Users\praym\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile execfile(filename, namespace) File "C:\Users\praym\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/praym/OneDrive/School/Information Structres/Assignment4.py", line 18, in selector.fit(X_train, y_train) File "C:\Users\praym\Anaconda3\lib\site-packages\sklearn\feature_selection\univariate_selection.py", line 322, in fit X, y = check_X_y(X, y, ['csr', 'csc']) File "C:\Users\praym\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 515, in check_X_y y = column_or_1d(y, warn=True) File "C:\Users\praym\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 551, in column_or_1d raise ValueError("bad input shape {0}".format(shape)) ValueError: bad input shape (10, 90)