-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetectingdiabeteswithxgboost&knn.py
65 lines (57 loc) · 1.68 KB
/
detectingdiabeteswithxgboost&knn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import xgboost as xgb
from sklearn.neighbors import KNeighborsClassifier
data = pd.read_csv("Dataset/diabetes.csv")
data.head()
X = data.drop("Outcome", axis=1)
y = data["Outcome"]
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=42)
model = xgb.XGBClassifier(random_state=42)
model.fit(X_train,y_train)
patient_data = {
"Pregnancies": None,
"Glucose": None,
"BloodPressure": None,
"SkinThickness": None,
"Insulin": None,
"BMI": None,
"DiabetesPedigreeFunction": None,
"Age": None
}
for feature in patient_data:
patient_data[feature] = float(input("Enter {} for the patient:".format(feature)))
patient_df = pd.DataFrame(patient_data, index=[0])
prediction = model.predict(patient_df)
print("\nPatient Data:")
print(patient_df)
if prediction[0] == 1:
print("Diabetes Detected")
else:
print("Normal")
X = data.drop("Outcome", axis=1)
y = data["Outcome"]
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=42)
model = KNeighborsClassifier()
model.fit(X_train,y_train)
patient_data = {
"Pregnancies": None,
"Glucose": None,
"BloodPressure": None,
"SkinThickness": None,
"Insulin": None,
"BMI": None,
"DiabetesPedigreeFunction": None,
"Age": None
}
for feature in patient_data:
patient_data[feature] = float(input("Enter {} for the patient:".format(feature)))
patient_df = pd.DataFrame(patient_data, index=[0])
prediction = model.predict(patient_df)
print("\nPatient Data:")
print(patient_df)
if prediction[0] == 1:
print("Diabetes Detected")
else:
print("Normal")