<jupyter_start><jupyter_text>Importing Libraries<jupyter_code>import numpy as np
import pandas as pd
import matplotlib as plt
import seaborn as sns
import matplotlib.pyplot as plt<jupyter_output>/usr/local/lib/python3.6/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
  import pandas.util.testing as tm<jupyter_text>Data Wrangling<jupyter_code>data = pd.read_csv('dataset.csv')

data.head(5)
print("(Rows, columns): " + str(data.shape))
data.columns 
data.nunique(axis=0)# returns the number of unique values for each variable.
#summarizes the count, mean, standard deviation, min, and max for numeric variables.
data.describe().transpose()
# Display the Missing Values

print(data.isna().sum())
# calculate correlation matrix

corr = data.corr()
plt.subplots(figsize=(15,10))
sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, annot=True, cmap=sns.diverging_palette(220, 20, as_cmap=True))
sns.heatmap(corr, xticklabels=corr.columns,
            yticklabels=corr.columns, 
            annot=True,
            cmap=sns.diverging_palette(220, 20, as_cmap=True))<jupyter_output><empty_output><jupyter_text>Filtering data by positive & negative Heart Disease patient<jupyter_code># Filtering data by POSITIVE Heart Disease patient
pos_data = data[data['target']==1]
pos_data.describe()
# Filtering data by NEGATIVE Heart Disease patient
pos_data = data[data['target']==0]
pos_data.describe()<jupyter_output><empty_output><jupyter_text>Assign the 13 features to X, & the last column to our classification predictor, y<jupyter_code>X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values<jupyter_output><empty_output><jupyter_text>Split: the data set into the Training set and Test set<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.2, random_state = 1)<jupyter_output><empty_output><jupyter_text>Normalize: Standardizing the data a mean of 0 and a standard deviation of 1.<jupyter_code>from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)<jupyter_output><empty_output><jupyter_text>Modeling /Training Model 1: K-NN (K-Nearest Neighbors)<jupyter_code>from sklearn.metrics import classification_report 
from sklearn.neighbors import KNeighborsClassifier

model1 = KNeighborsClassifier() # get instance of model
model1.fit(x_train, y_train) # Train/Fit model 

y_pred1 = model1.predict(x_test) # get y predictions
print(classification_report(y_test, y_pred1)) # output accuracy<jupyter_output>precision    recall  f1-score   support

           0       0.78      0.70      0.74        30
           1       0.74      0.81      0.77        31

    accuracy                           0.75        61
   macro avg       0.76      0.75      0.75        61
weighted avg       0.76      0.75      0.75        61<jupyter_text>Making the Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred1)
print(cm)
accuracy_score(y_test, y_pred1)
TN = cm[0][0]
FN = cm[1][0]
TP = cm[1][1]
FP = cm[0][1]

specificity = (TN/TN+FP)

print ('Specificity = ', specificity)

senstivity = (TP/TP+FN)

print ('Senstivity = ', senstivity)<jupyter_output>Senstivity =  7.0
{'fraction_non_alphanumeric': 0.10395314787701318, 'fraction_numerical': 0.02957540263543192, 'mean_word_length': 4.636963696369637, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '506466', 'license': 'MIT', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1166, 'n_words': 274, 'path': 'Data Science/DSA_Project_on_KNN.ipynb', 'repo_name': 'mahnoor1999/learn2code', 'size': '3415'}