{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import cross_val_score, KFold, StratifiedKFold\n", "from sklearn.datasets import load_iris\n", "from sklearn.linear_model import LogisticRegression\n", "\n", "iris = load_iris()\n", "logreg = LogisticRegression(max_iter=1000)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "교차 검증 점수:\n", " [1. 0.96666667 0.93333333 1. 0.93333333 0.96666667\n", " 0.96666667 0.93333333 1. 0.96666667 0.93333333 1.\n", " 1. 0.96666667 0.96666667 0.9 1. 1.\n", " 0.93333333 0.96666667 0.93333333 0.96666667 0.96666667 1.\n", " 0.96666667 1. 0.96666667 0.96666667 0.9 1.\n", " 0.96666667 0.96666667 0.96666667 0.96666667 0.93333333 0.96666667\n", " 0.96666667 1. 1. 0.9 0.96666667 1.\n", " 0.9 0.96666667 0.96666667 0.9 0.96666667 0.96666667\n", " 1. 0.96666667]\n", "교차 검증 평균 점수: 0.965\n" ] } ], "source": [ "from sklearn.model_selection import RepeatedStratifiedKFold\n", "\n", "rskfold = RepeatedStratifiedKFold(random_state=42)\n", "scores = cross_val_score(logreg, iris.data, iris.target, cv=rskfold)\n", "\n", "print(\"교차 검증 점수:\\n\", scores)\n", "print(\"교차 검증 평균 점수: {:.3f}\".format(scores.mean()))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }