<jupyter_start><jupyter_text>importing data<jupyter_code>import pandas as pd
import numpy as nm
data=pd.read_csv('diabetes.csv')
data.head()
data.shape
data['Outcome'].unique()
data.describe()<jupyter_output><empty_output><jupyter_text>Representing the Data<jupyter_code>import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(20,25))
plotnumber=1
for column in data:
    if plotnumber<=9:
        ax=plt.subplot(3,3,plotnumber)
        sns.histplot(data[column],kde=True)
        plt.xlabel(column,fontsize=20)
    plotnumber += 1
plt.show()<jupyter_output><empty_output><jupyter_text>Fitting Data<jupyter_code>data['BMI']=data['BMI'].replace(0,data['BMI'].mean())
data['Age']=data['Age'].replace(0,data['Age'].mean())
data['BloodPressure']=data['BloodPressure'].replace(0,data['BloodPressure'].mean())
data['Glucose']=data['Glucose'].replace(0,data['Glucose'].mean())
data['SkinThickness']=data['SkinThickness'].replace(0,data['SkinThickness'].mean())
data['Insulin']=data['Insulin'].replace(0,data['Insulin'].mean())
x=data.drop(columns=['Outcome'])
y=data['Outcome']
from sklearn.preprocessing import StandardScaler
scale=StandardScaler()
x=scale.fit_transform(x)<jupyter_output><empty_output><jupyter_text>Splitting Data<jupyter_code>from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.15,random_state=100)
print(x_train.shape)
print(x_test.shape)
print(y_train.shape)
print(x_test.shape)<jupyter_output>(652, 8)
(116, 8)
(652,)
(116, 8)<jupyter_text>Training KNN<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV
knn=KNeighborsClassifier()
param_grid={'algorithm':['auto', 'ball_tree','kd_tree','brute'], 'leaf_size':[2,3,5,6,8,10,12,14],
    'n_neighbors':[3,5,7,9,11,13,15,17,19]}
gridsearch=GridSearchCV(knn,param_grid)
gridsearch.fit(x_train,y_train)
gridsearch.best_params_
knn=KNeighborsClassifier(algorithm='auto', leaf_size=2, n_neighbors=15)
knn.fit(x_train,y_train)
knn.score(x_train,y_train)<jupyter_output><empty_output><jupyter_text>Predicting<jupyter_code>pred=knn.predict(x_test)
pred
knn.score(x_test,y_test)
from sklearn.metrics import accuracy_score,confusion_matrix
print(accuracy_score(pred,y_test))
print(confusion_matrix(pred,y_test))<jupyter_output>[[62 21]
 [13 20]]
{'fraction_non_alphanumeric': 0.16488680051260146, 'fraction_numerical': 0.031610422896198205, 'mean_word_length': 12.157303370786517, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '611841', 'license': 'Apache-2.0', 'n_tokens_mistral': 982, 'n_tokens_neox': 914, 'n_words': 98, 'path': 'Session 2 - Diabetes/K_Nearest_Neighbour.ipynb', 'repo_name': 'ShashankPatel0111/VOIS-AI-Workshop-Projects', 'size': '2341'}