<jupyter_start><jupyter_text>populate data in X(indipendent variable) and y(dependent variable)<jupyter_code>X=dataset.iloc[:,:-1].values
y=dataset.iloc[:,8].values
sb.countplot(dataset['Outcome'],label='count')
print(dataset.groupby('Outcome').size())
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(dataset.loc[:,dataset.columns !='Outcome'],dataset['Outcome'],stratify=dataset['Outcome'],random_state=66)
from sklearn.neighbors import KNeighborsClassifier
training_accuracy=[]
test_accuracy=[]
# try n_neighbors from 1 to 10
neighbors_settings=range(1,11)
for n_neighbors in neighbors_settings:
    # build the model
    knn=KNeighborsClassifier(n_neighbors=n_neighbors)
    knn.fit(X_train,y_train)
    # record trainning set accuracy
    training_accuracy.append(knn.score(X_train,y_train))
    # record test set accuracy
    test_accuracy.append(knn.score(X_test,y_test))
plt.plot(neighbors_settings,training_accuracy,label='training accuracy')
plt.plot(neighbors_settings,test_accuracy,label='test accuracy')
plt.ylabel("Accuracy")
plt.xlabel("n_neighbors")
plt.legend()
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(dataset.loc[:,dataset.columns !='Outcome'],dataset['Outcome'],stratify=dataset['Outcome'],random_state=66)
from sklearn.neighbors import KNeighborsClassifier
training_accuracy=[]
test_accuracy=[]
# try n_neighbors from 1 to 9
neighbors_settings=range(1,10)
for n_neighbors in neighbors_settings:
    # build the model
    knn=KNeighborsClassifier(n_neighbors=n_neighbors)
    knn.fit(X_train,y_train)
    # record trainning set accuracy
    training_accuracy.append(knn.score(X_train,y_train))
    # record test set accuracy
    test_accuracy.append(knn.score(X_test,y_test))
plt.plot(neighbors_settings,training_accuracy,label='training accuracy')
plt.plot(neighbors_settings,test_accuracy,label='test accuracy')
plt.ylabel("Accuracy")
plt.xlabel("n_neighbors")
plt.legend()
knn=KNeighborsClassifier(n_neighbors=9)
knn.fit(X_train,y_train)
print('Accuracy of K-NN classifier on training set:{:.2f}'.format(knn.score(X_train,y_train)))
print('Accuracy of K-NN classifier on testining set:{:.2f}'.format(knn.score(X_test,y_test)))

# python script for confusion matrix creation
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
actual=y_test
predicted=knn.predict(X_test)
results=confusion_matrix(actual,predicted)
print('Confusion Matrix:')
print(results)
print('Accuracy Score:',accuracy_score(actual,predicted))
print('Report:')
print(classification_report(actual,predicted))
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
def plot_roc_curve(fpr , tpr):
    plt.plot(fpr,tpr,color='orange',label='ROC')
    plt.plot([0,1],[0,1],color='blue',linestyle='--')
    plt.xlabel('False positive rate')
    plt.ylabel('True positive rate')
    plt.title('Reciever operating characteristic(ROC) curve')
    plt.legend()
    plt.show()
probs=knn.predict_proba(X_test)
probs
probs=probs[:,1]
probs
auc=roc_auc_score(y_test,probs)
print('AUC: %.2f'% auc)
fpr,tpr,thresholds=roc_curve(y_test,probs)
plot_roc_curve(fpr,tpr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1266707168894289, 'fraction_numerical': 0.007897934386391251, 'mean_word_length': 8.771513353115727, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '635424', 'license': 'MIT', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1168, 'n_words': 180, 'path': 'KNN-k-nearest neighbors.ipynb', 'repo_name': 'KARTHIK-GAMAPALA/Diabetes_study', 'size': '3292'}