<jupyter_start><jupyter_text>Grid Searc SVC 3Explorando `GridSearchCV` para diferentes valores de `gamma`. Importando bibliotecas<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns

from matplotlib import pyplot as plt
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split, GridSearchCV<jupyter_output><empty_output><jupyter_text>Carregando dados<jupyter_code># Carregando DataFrame
chainDF = pd.read_csv('./corrente.csv')

targetS = chainDF.pop('classe')

# Carregando Rótulos das características
feature_names = chainDF.columns

# Carregando rótulos das classes
target_names = ['Normal', 'HI-1', 'HI-2', 'HI-3', 'LI-1', 'LI-2', 'LI-3']

# Definindo variáveis
X, y = chainDF.to_numpy(), targetS.to_numpy()

# Separando dados
X_pre_train, X_pre_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Pré-processando dados
sc = StandardScaler().fit(X_pre_train)

X_train = sc.transform(X_pre_train)
X_test = sc.transform(X_pre_test)<jupyter_output><empty_output><jupyter_text>Realizando busca em grade<jupyter_code>gammaGrid = ['scale', 'auto'] + [1/(2 ** gamma) for gamma in np.arange(0, 10)]

gammaGS = GridSearchCV(
    estimator=SVC(),
    cv=15,
    param_grid={
        'gamma':gammaGrid,
        'decision_function_shape':['ovo'],
        'cache_size':[1000]}
).fit(
    X_train,
    y_train
)

gammaDF = pd.DataFrame(gammaGS.cv_results_)
gammaDF[['param_gamma', 'mean_test_score', 'std_test_score', 'rank_test_score']].sort_values(by='rank_test_score')
plt.xticks(rotation='vertical')
plt.scatter(x=np.array(gammaGrid), y=gammaDF[['mean_test_score']])
gamma2GS = GridSearchCV(
    estimator=SVC(),
    cv=15,
    param_grid={
        'gamma':np.linspace(0.25, 1),
        'decision_function_shape':['ovo'],
        'cache_size':[1000]}
).fit(
    X_train,
    y_train
)

gamma2DF = pd.DataFrame(gamma2GS.cv_results_)
gamma2DF[['param_gamma', 'mean_test_score', 'std_test_score', 'rank_test_score']].sort_values(by='rank_test_score')
plt.scatter(x=np.linspace(0.25, 1), y=gamma2DF[['mean_test_score']])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14048059149722736, 'fraction_numerical': 0.018946395563770795, 'mean_word_length': 6.052117263843648, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '250251', 'license': 'MIT', 'n_tokens_mistral': 852, 'n_tokens_neox': 834, 'n_words': 144, 'path': 'ML/f01-chain/04-gs-svc3.ipynb', 'repo_name': 'newtmagalhaes/Machine-Learning', 'size': '2164'}