<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import make_classification
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
# roc curve function

def roc_curve_fig(fpr, tpr):  # false positive rate(민감도), true positive rate(특이도)
  plt.plot(fpr, tpr, color='yellow', label='ROC')
  plt.plot([0,1], [0,1], color='darkblue', linestyle='--')
  plt.xlabel('False Positive Rate')
  plt.ylabel('True Positive Rate')
  plt.title('ROC CURVE')
  plt.legend()
  plt.show()
# number of sample = 1000

data_X, class_label = make_classification(n_samples=1000, n_classes=2, weights=[1,1], random_state=1)
train_X, test_X, train_y, test_y = train_test_split(data_X, class_label,
                                                    test_size = 0.2,
                                                    random_state = 1)
# 모델 생성

model = RandomForestClassifier()

model.fit(train_X, train_y)
# 모델 예측

prob = model.predict_proba(test_X)    # 퍼센트
prob[:, 1]    # positive class
probs = prob[:, 1]    # positive class
# AUC

auc = roc_auc_score(test_y, probs)
fpr, tpr, thresholds = roc_curve(test_y, probs)
roc_curve_fig(fpr, tpr)
auc<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10277777777777777, 'fraction_numerical': 0.014583333333333334, 'mean_word_length': 3.901360544217687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '360452', 'license': 'Apache-2.0', 'n_tokens_mistral': 538, 'n_tokens_neox': 524, 'n_words': 122, 'path': 'ROC_Curve.ipynb', 'repo_name': 'rhapis97/Practice_AI', 'size': '1440'}