Practical 4
Practical 4
import numpy as np
df=pd.read_csv("diabetes.csv")
df.head()
1 1 85 66 29 0 26.6
2 8 183 64 0 0 23.3
3 1 89 66 23 94 28.1
df['Outcome'].value_counts()
Outcome
0 500
1 268
Name: count, dtype: int64
x = df.drop('Outcome',axis=1)
y = df['Outcome']
KNeighborsClassifier()
y_pred=knn.predict(x_test)
y_pred
array([0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1,
1,
1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0,
0,
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0,
1,
0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1,
0,
0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1,
0,
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1,
0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1,
0,
1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1,
0,
0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1,
1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1,
1,
0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1], dtype=int64)
Confusion Matrix:
[[113 30]
[ 29 59]]
Accuracy: 74.45887445887446 %
error_rate = 1 - accuracy
print("Error Rate:", error_rate)
Precision: 0.6629213483146067
Recall: 0.6704545454545454