text_plain_output_1.png image_output_1.png
from sklearn.decomposition import PCA

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import confusion_matrix

from sklearn.model_selection import train_test_split, StratifiedKFold

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import StandardScaler

from sklearn.svm import SVC

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sn

dataset = pd.read_csv('../input/predictnav-beta/dataset_beta.csv')
dataset.drop(['ip_hash', 'fecha', 'lang', 'country'], axis=1, inplace=True)
X, y = (dataset.iloc[:, 0:-1].values, dataset.iloc[:, -1].values)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
from sklearn.metrics import confusion_matrix
import seaborn as sn
import matplotlib.pyplot as plt
def showConfusionMat(pipe, X_test, y_test):
    y_pred = pipe.predict(X_test)
    confmat = confusion_matrix(y_true=y_test, y_pred=y_pred)
    df_cm = pd.DataFrame(confmat, ['F', 'T'], ['F', 'T'])
    sn.set(font_scale=1.4)

pipeline_1 = Pipeline([('scl', StandardScaler()), ('pca', PCA(n_components=2)), ('clf', LogisticRegression(random_state=1))])
pipeline_1.fit(X_train, y_train)
from sklearn.svm import SVC
pipeline_svm = Pipeline([('scl', StandardScaler()), ('clf', SVC(kernel='linear', C=0.05, random_state=1))])
pipeline_svm.fit(X_train, y_train)

skf = StratifiedKFold(random_state=1, n_splits=2)
resultados = []
for train, test in skf.split(X_train, y_train):
    pipeline_1.fit(X_train[train], y_train[train])
    resultado = pipeline_1.score(X_train[test], y_train[test])
    resultados.append(resultado)

print('Entrenamiento:')
print(y_train)
print('Test:')
print(y_test)
showConfusionMat(pipeline_1, X_test, y_test)
showConfusionMat(pipeline_svm, X_test, y_test)