<jupyter_start><jupyter_text>GridSearch com Pipeline apenas com dados dos canais selecionadosExplorando busca em grade para determinar melhor parâmetro `C` do classificador apenas com os melhores canais já selecionados previamente. Importando bibliotecas<jupyter_code>import numpy as np
import pandas as pd

from seaborn import scatterplot
from sklearn.svm import SVC
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV, GroupKFold

# lista de str ['01', '02', ..., '24']
file_range = ['{:0>2}'.format(chb) for chb in range(1, 25)]

def dataframe_from_chb(chb_number:str) -> pd.DataFrame:
    df = pd.read_csv(f'./chb{chb_number}/chb{chb_number}_com_dwt.csv')
    df['chb'] = chb_number
    return df<jupyter_output><empty_output><jupyter_text>Organizando dados<jupyter_code>chb_df = pd.concat([dataframe_from_chb(file) for file in file_range], ignore_index=True)

some_6_channels = ['2', '3', '6', '7', '14', '15']

# Filtrando colunas do chb que são referentes aos canais em some_6_channels
columns_from_6_channels = [column for column in chb_df.columns if column.split('-')[-1] in some_6_channels]

chb_groups = chb_df.pop('chb').values
chb_y = chb_df.pop('target').values
chb_X = chb_df[columns_from_6_channels].values

pipe = make_pipeline(StandardScaler(), SVC(cache_size=500))

folds = GroupKFold(n_splits=len(np.unique(chb_groups))).split(chb_X, chb_y, chb_groups)

C_grid = {'svc__C':np.linspace(0, 2, 9)[1:]}<jupyter_output><empty_output><jupyter_text>Busca em Grade<jupyter_code>gs = GridSearchCV(
    estimator=pipe,
    param_grid=C_grid,
    cv=folds
).fit(
    X=chb_X,
    y=chb_y,
    groups=chb_groups
)

pd.DataFrame(gs.cv_results_).to_csv('./csvs/09-pipe-gs-svc-oneVSall_with_some_6channels.csv', index=False)
columns = ['rank_test_score', 'param_svc__C', 'mean_test_score', 'std_test_score']

cv_results_df = pd.read_csv('./csvs/09-pipe-gs-svc-oneVSall_with_some_6channels.csv')[columns]

cv_results_df.style.background_gradient(cmap='Blues', subset=['mean_test_score']).hide_index()
scatterplot(
    data=cv_results_df,
    x='param_svc__C',
    y='mean_test_score'
)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup