-
Notifications
You must be signed in to change notification settings - Fork 0
/
platinum.py
133 lines (110 loc) · 4.05 KB
/
platinum.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
"""Platinum.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/145WJ3RSeRgwJuxBRNI_5-3N7gNDcra_F
# Platinum heart & liver disease predictor
Class 12 CS project by Aryan Patil, Priyansh Mishra and Rithwik Anand
"""
#github.com/realaryanpatil/Platinum
"""### This program requires datasets to work. Please download liver.csv and heart.csv from the [repository](https://github.com/realaryanpatil/Platinum) """
import pandas as pd
def trainheart(q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11):
dataset = pd.read_csv('medical.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
result = classifier.predict(sc.transform([[q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11]]))
output = int(result)
if output == 1:
a1 = "The patient is at a high risk of heart failure."
else:
a1 = "The patient is at a low risk of heart failure."
print(a1)
def livertrain(q1,q2,q3,q4,q5,q6,q7,q8,q9,q10):
dataset = pd.read_csv('liver.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
result = classifier.predict(sc.transform([[q1,q2,q3,q4,q5,q6,q7,q8,q9,q10]]))
output = int(result)
if output == 1:
a1 = "The patient is at a high risk of liver disease."
else:
a1 = "The patient is at a low risk of liver disease."
print(a1)
question = input("""Welcome to Platinum Argos [V1.0], A Naive Bayes classification system to detect heart/liver disease.
Please select your choice below:
[1] Heart failure risk analysis
[2] Liver disease risk analysis
--------------------------------------------------------------------------------------------------
:""")
if question == '1' or question == 'heart':
print('---------------------------------------heart-----------------------------------------------')
r1 = input("Patient age: ")
r2 = input("Is the patient suffering from anemia? (y/n): ")
if r2 == 'y':
r2 = 1
else:
r2 = 0
r3 = input("Creatine Phosphokinase levels (in micrograms per litre): ")
r4 = input("Is the patient suffering from diabetes? (y/n): ")
if r4 == 'y':
r4 = 1
else:
r4 = 0
r5 = input("Ejection Fraction (in %): ")
r6 = input("Is the patient suffering from hypertension? (y/n): ")
if r6 == 'y':
r6 = 1
else:
r6 = 0
r7 = input("Number of platelets: ")
r8 = input("Serum Creatine levels: ")
r9 = input("Serum Sodium levels: ")
r10 = input("Gender (m/f): ")
if r10 == 'm':
r10 = 1
else:
r10 = 0
r11 = input("Does the patient smoke? (y/n): ")
if r11 == 'y':
r11 = 1
else:
r11 = 0
trainheart(r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11)
elif question == "2" or question == "liver":
print('---------------------------------------liver-----------------------------------------------')
r1 = input("Patient age: ")
r2 = input("Patient gender (m/f): ")
if r2 == 'm':
r2 = 1
else:
r2 = 0
r3 = input("Total Bilirubin: ")
r4 = input("Direct Bilirubin: ")
r5 = input("Alkaline Phosphotase: ")
r6 = input("Alamine Aminotransferase:")
r7 = input("Aspartate Aminotransferase: ")
r8 = input("Total Protiens: ")
r9 = input("Albumin levels: ")
r10 = input("Albumin and Globulin Ratio: ")
livertrain(r1,r2,r3,r4,r5,r6,r7,r8,r9,r10)
else:
print("Wrong input. Please try again.")