# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
from pathlib import Path
import numpy  as np
from sklearn.model_selection import train_test_split

from pandas_ods_reader import read_ods
from sklearn.model_selection import cross_val_score
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import plot_confusion_matrix
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
from sklearn.metrics import roc_curve,auc
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.feature_selection import f_classif
from sklearn.feature_selection import VarianceThreshold
from sklearn.feature_selection import SelectKBest, SelectPercentile
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor,RandomForestClassifier
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
from sklearn.feature_selection import SelectFromModel

this_dir = Path.cwd()

dataset_file = this_dir / "pd_speech_features.ods"

df = pd.read_excel(dataset_file, header=[0, 1], engine="odf")

df.drop(columns=['Basic Info'], inplace=True)


def normalize_data(x):
    return((x-np.min(x))/max(x)-min(x))


data = df.to_numpy(dtype=np.float32)
features, labels = data[:, :-1], data[:, -1]

x_train,x_test,y_train,y_test=train_test_split(features,labels,test_size=0.3,random_state=0)

#using ridge Regularization\
df.head()

y_train.shape,x_train.shape

import statsmodels.api as sm

# logml=sm.GLM(y_train,(sm.add_constant(x_train))),family=sm.families.Bionomial())

# +
logml=sm.GLM(y_train,(sm.add_constant(x_train)),family=sm.families.Binomial())

logml.fit().summary()
# -



df.head()

df1_exp=df

plt.figure(figsize=(30,10))
sns.heatmap(df1_exp["Baseline Features"].corr(),annot=True)

round(df1_exp['Baseline Features'].corr(),3)

form_data=pd.read_csv("pd_speech_features2.csv")

form_data.drop(['id','gender'],axis=1)

form_data.drop(columns=['locAbsJitter','rapJitter','ddpJitter','ppq5Jitter','locShimmer','apq5Shimmer','meanNoiseToHarmHarmonicity','numPeriodsPulses','meanPeriodPulses','apq11Shimmer'],axis=1)

form_data.drop(columns=['GQ_std_cycle_closed','tqwt_medianValue_dec_5','tqwt_medianValue_dec_16','tqwt_medianValue_dec_16','tqwt_medianValue_dec_20',
                        'tqwt_medianValue_dec_24','tqwt_medianValue_dec_25','tqwt_meanValue_dec_5','tqwt_meanValue_dec_5'
                        ,'tqwt_meanValue_dec_30','tqwt_meanValue_dec_35','tqwt_meanValue_dec_23','tqwt_meanValue_dec_27',
                        'tqwt_meanValue_dec_31',
                        'tqwt_meanValue_dec_16','tqwt_meanValue_dec_11'])

plt.figure(figsize=(30,10))
sns.heatmap(df1_exp["Intensity Parameters"].corr(),annot=True)


def normalize_data(x):
    return((x-np.min(x))/max(x)-min(x))


form_data.apply(normalize_data)

data = form_data.to_numpy(dtype=np.float32)
features, labels = data[:, :-1], data[:, -1]

x_train,x_test,y_train,y_test=train_test_split(features,labels,test_size=0.3,random_state=0)
x_train.shape,y_train.shape

from sklearn.linear_model import LogisticRegression
clf=LogisticRegression(tol=0.1)#tolerence is 0.1
clf.fit(x_train,y_train) 

y_pred=clf.predict(x_test)

a=cross_val_score(clf,x_train,y_train,cv=2,scoring="accuracy")#cross_validation

a.mean()*100

print(classification_report(y_test,y_pred))

print(f"confusion_matrix:\n{confusion_matrix(y_test,y_pred)}")


logistic_fpr,logistic_tpr,threshold=roc_curve(y_test,y_pred)
auc_logistic=auc(logistic_fpr,logistic_tpr)
plt.figure(figsize=(5,5),dpi=100)
plt.plot(logistic_fpr,logistic_tpr,marker=".",label="Logistic(auc=%0.3f)"%auc_logistic)
plt.xlabel("False Positive Rate-->")
plt.ylabel("True Positive Rate-->")
plt.legend()
plt.show()



StarcoderdataJupyterScriptsDedupFiltered