<jupyter_start><jupyter_text>모형 최적화  Scikit-Learn 의 모형 하이퍼 파라미터 튜닝 도구  - Validation Curve<jupyter_code>from sklearn.datasets import load_digits
from sklearn.svm import SVC
from sklearn.model_selection import validation_curve

digits = load_digits()
X, y = digits.data, digits.target
param_range = np.logspace(-6, -1, 10)
train_scores, test_scores = \
        validation_curve(SVC(), X, y,
                        param_name='gamma', param_range=param_range, cv=10,
                        scoring='accuracy', n_jobs=2)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)

mpl.rcParams["font.family"] = 'DejaVu Sans'
plt.semilogx(param_range, train_scores_mean, label="Training score", color="r")
plt.fill_between(param_range, train_scores_mean - train_scores_std,
                 train_scores_mean + train_scores_std, alpha=0.2, color="r")
plt.semilogx(param_range, test_scores_mean,
             label="Cross-validation score", color="g")
plt.fill_between(param_range, test_scores_mean - test_scores_std,
                 test_scores_mean + test_scores_std, alpha=0.2, color="g")
plt.legend(loc="best")
plt.title("Validation Curve with SVM")
plt.xlabel("$\gamma$")
plt.ylabel("Score")
plt.ylim(0.0, 1.1)
plt.show()<jupyter_output><empty_output><jupyter_text>- GridSearchCV<jupyter_code>from sklearn.datasets import load_boston<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12216288384512683, 'fraction_numerical': 0.012683578104138851, 'mean_word_length': 4.9015748031496065, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '596779', 'license': 'MIT', 'n_tokens_mistral': 600, 'n_tokens_neox': 571, 'n_words': 95, 'path': 'ML/14_Parameter_tuning _and_Model_optimization.ipynb', 'repo_name': 'sejinkim/TIL', 'size': '1498'}