"""This module contains necessary function needed"""
# Import necessary modules
import numpy as np
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
import streamlit as st
@st.cache()
def load_data():
"""This function returns the preprocessed data"""
# Load the Diabetes dataset into DataFrame.
df = pd.read_csv('https://raw.githubusercontent.com/DataMinati/Streamlit-Database/main/Parkinsson%20disease.csv')
# Rename the column names in the DataFrame.
df.rename(columns = {"MDVP:Fo(Hz)": "AVFF",}, inplace = True)
df.rename(columns = {"MDVP:Fhi(Hz)": "MAVFF",}, inplace = True)
df.rename(columns = {"MDVP:Flo(Hz)": "MIVFF",}, inplace = True)
# Perform feature and target split
X = df[["AVFF", "MAVFF", "MIVFF","Jitter:DDP","MDVP:Jitter(%)","MDVP:RAP","MDVP:APQ","MDVP:PPQ","MDVP:Shimmer","Shimmer:DDA","Shimmer:APQ3","Shimmer:APQ5","NHR","HNR","RPDE","DFA","D2","PPE"]]
y = df['status']
return df, X, y
@st.cache()
def train_model(X, y):
"""This function trains the model and return the model and model score"""
# Create the model
model = DecisionTreeClassifier(
ccp_alpha=0.0, class_weight=None, criterion='entropy',
max_depth=4, max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_samples_leaf=1,
min_samples_split=2, min_weight_fraction_leaf=0.0,
random_state=42, splitter='best'
)
# Fit the data on model
model.fit(X, y)
# Get the model score
score = model.score(X, y)
# Return the values
return model, score
def predict(X, y, features):
# Get model and model score
model, score = train_model(X, y)
# Predict the value
prediction = model.predict(np.array(features).reshape(1, -1))
return prediction, score