- numpy
- scikit-learn
- pandas
from pyodide.http import open_url
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestClassifier
#---------------------------We need to open these files and then train them with best params------------------------------------
X_train = pd.read_csv(open_url("https://raw.githubusercontent.com/TusharNautiyal-web/Heart-Dissease-Prediction/main/data/X_train.csv"))
X_test = pd.read_csv(open_url("https://raw.githubusercontent.com/TusharNautiyal-web/Heart-Dissease-Prediction/main/data/X_test.csv"))
y_train = pd.read_csv(open_url("https://raw.githubusercontent.com/TusharNautiyal-web/Heart-Dissease-Prediction/main/data/y_train.csv"))
y_test = pd.read_csv(open_url("https://raw.githubusercontent.com/TusharNautiyal-web/Heart-Dissease-Prediction/main/data/y_test.csv"))
X_train = X_train.iloc[:,1:]
y_train = y_train.iloc[:,1:]
X_test = X_test.iloc[:,1:]
y_test = y_test.iloc[:,1:]
#--------------------Fetching Form Values--------------------
def submit(*args,**kwargs):
final_output = Element('prediction')
sex = int(Element('sex').value)
cp = int(Element('cp').value)
trestbps = int(Element('trestbps').value)
age = int(Element('age').value)
oldpeak = float(Element('oldpeak').value)
exang = int(Element('exang').value)
fbs = int(Element('fbs').value)
restecg = int(Element('restecg').value)
thalach = int(Element('thalach').value)
slope = int(Element('slope').value)
thal = int(Element('thal').value)
chol = int(Element('chol').value)
ca = int(Element('ca').value)
# ----------- age -------------
if(age>=28.952 and age<45.0):
age = 1
elif(age>=45 and age<61):
age = 2
elif(age>=61):
age = 0
elif(age<28.952):
age = 1
# --------- Cholestrol -----------
if(chol>=125.562 and chol<272.0):
chol = 0
elif(chol>=272.0 and chol<418.0):
chol = 1
elif(chol>=418.0 and chol<564.0):
chol = 2
elif(chol<125.562):
chol = 0
# --------- old peak -----------
if(oldpeak>= 0 and oldpeak<1.5):
oldpeak = 2
elif(oldpeak>=1.5 and oldpeak<2.55):
oldpeak = 0
elif(oldpeak>=2.55 and oldpeak<7.0):
oldpeak = 1
elif(oldpeak<0):
oldpeak = 2
rf = RandomForestClassifier(n_estimators = 400, min_samples_split = 15, max_depth = 15, min_samples_leaf = 5)
rf.fit(X_train,y_train.values.ravel())
pred = rf.predict([[sex,cp,trestbps,fbs,restecg,thalach,exang,slope,ca,thal,oldpeak,age,chol]])
#----------------Now we will just predict ------------------------------------------.
if pred == 0:
prediction_text = "No Presence of heart dissease"
final_output.write(prediction_text)
else:
prediction_text = "Presence of heart Dissease Please go for a checkup"
final_output.write(prediction_text)