-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
41 lines (26 loc) · 967 Bytes
/
models.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
import pandas as pd
from sklearn import tree
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
diabetes_db = pd.read_csv("diabetes_train.csv")
diagnosis = diabetes_db["Outcome"]
db_train = diabetes_db.drop("Outcome", axis=1)
def create_decision_tree_model():
clf = tree.DecisionTreeClassifier()
clf.fit(db_train.values, diagnosis)
return clf
def create_knn_model():
neigh = KNeighborsClassifier(n_neighbors=2)
neigh.fit(db_train.values, diagnosis)
return neigh
def create_neural_network_model():
clf = MLPClassifier(activation="logistic", random_state=1, max_iter=3000)
clf.fit(db_train.values, diagnosis)
return clf
def predict_diabetes_diagnosis(model, values):
measurements = list(values.dict().values())
result = model.predict([measurements])
if result[0] == 1:
return "Diagnosed with diabetes"
else:
return "Don't have diabetes"