text_plain_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import accuracy_score

from sklearn.neighbors import KNeighborsClassifier

from sklearn.preprocessing import StandardScaler

from sklearn.svm import SVC

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_valid_std = sc.transform(X_valid)

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
lr = LogisticRegression(C=1000.0, random_state=0)
lr.fit(X_train_std, y_train)
y_pred = lr.predict(X_valid_std)

def classif_func(data_train, label_train, data_valid, label_valid, classif):
    classif.fit(data_train, label_train)
    y_pred = classif.predict(data_valid)
    return ((label_valid != y_pred).sum(), accuracy_score(label_valid, y_pred))

def classif_Kne(data_train, label_train, data_valid, label_valid, k):
    classif = KNeighborsClassifier(k)
    classif.fit(data_train, label_train)
    y_pred = classif.predict(data_valid)
    return ((label_valid != y_pred).sum(), accuracy_score(label_valid, y_pred))

def classif_SVC(data_train, label_train, data_valid, label_valid, k):
    classif = SVC(gamma=2, C=k)
    classif.fit(data_train, label_train)
    y_pred = classif.predict(data_valid)
    return ((label_valid != y_pred).sum(), accuracy_score(label_valid, y_pred))

for i in range(1, 30):
    print(i, classif_SVC(X_train_std, y_train, X_valid_std, y_valid, i))