Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.


IPython 7.29.0 -- An enhanced Interactive Python.


In [1]:

   ...: """

   ...: Created on Thu Mar 23 09:48:20 2023

   ...:

   ...: @author: sch442

   ...: """

   ...:

   ...: import pandas as pd

   ...: import os

   ...: import numpy as np

   ...: import sklearn

   ...:

   ...:

   ...: import pandas as pd

   ...: from sklearn.model_selection import train_test_split

   ...: from sklearn.svm import SVR

   ...: from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error

   ...: from sklearn.preprocessing import StandardScaler

   ...: from sklearn.decomposition import PCA

   ...:

   ...: import pandas as pd

   ...: from sklearn.model_selection import train_test_split

   ...: from sklearn.svm import SVR

   ...: from sklearn.svm import SVC

   ...: from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error

   ...: from sklearn.preprocessing import StandardScaler

   ...: from sklearn.decomposition import PCA

   ...: from sklearn.metrics import classification_report, accuracy_score

   ...:

   ...:

   ...: import pandas as pd

   ...: import os

   ...: import numpy as np

   ...: import sklearn

   ...:

   ...: df_path=r'C:\Users\marks\Dropbox\research_projects\voice_features\features\feature_gemaps.csv'

   ...:

   ...:

   ...:

   ...: df=pd.read_csv(df_path)

   ...:

   ...: df = df.drop(columns=['Unnamed: 0','file','Participant_ID','PHQ8_Binary','start','end','train_test_dev'])

   ...:

   ...:

   ...:

   ...:

   ...: label = 'PHQ8_Score'

   ...:

   ...:

   ...: X = df.drop(columns=[label])

   ...: y = df[label]

   ...:

   ...:

   ...: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

   ...:

   ...:

   ...: scaler = StandardScaler()

   ...: X_train= scaler.fit_transform(X_train)

   ...:

   ...: X_test= scaler.transform(X_test)

   ...:

   ...:

   ...:

   ...:

   ...:

   ...: pca = PCA(n_components=0.95)

   ...: X_train = pca.fit_transform(X_train)

   ...: X_test = pca.transform(X_test)

   ...:

   ...: c=0.00001

   ...:

   ...:

   ...: svr = SVR(kernel='linear', C=c) # You can experiment with different kernels and parameters

   ...: svr.fit(X_train, y_train)

   ...:

   ...: y_pred = svr.predict(X_test)

   ...:

   ...:

   ...: print('C:',c)

   ...: mse = mean_squared_error(y_test, y_pred)

   ...: print('MSE:',mse)

   ...: print('RMSE',mse**0.5)

   ...: mae= mean_absolute_error(y_test, y_pred)

   ...: print('MAE:',mae)

   ...:

   ...:

   ...:

   ...:

   ...:

   ...: '''

   ...: Predicting Binary label

   ...: '''

   ...:

   ...:

   ...:

   ...:

   ...: df_path=r'C:\Users\marks\Dropbox\research_projects\voice_features\features\feature_gemaps.csv'

   ...:

   ...:

   ...:

   ...: df=pd.read_csv(df_path)

   ...:

   ...:

   ...: df = df.drop(columns=['Unnamed: 0','file','Participant_ID','PHQ8_Score','start','end','train_test_dev'])

   ...:

   ...:

   ...:

   ...:

   ...: label = 'PHQ8_Binary'

   ...:

   ...:

   ...: X = df.drop(columns=[label])

   ...: y = df[label]

   ...:

   ...:

   ...:

   ...: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

   ...:

   ...:

   ...:

   ...: scaler = StandardScaler()

   ...: X_train= scaler.fit_transform(X_train)

   ...: X_test= scaler.transform(X_test)

   ...:

   ...: pca = PCA(n_components=0.95) # Keep 95% of the explained variance

   ...: X_train = pca.fit_transform(X_train)

   ...: X_test = pca.transform(X_test)

   ...:

   ...: c=0.001

   ...:

   ...: svc = SVC(kernel='linear', C=c, class_weight='balanced') # You can experiment with different kernels and parameters

   ...: svc.fit(X_train, y_train)

   ...:

   ...: y_pred = svc.predict(X_test)

   ...:

   ...:

   ...: print('C:',c)

   ...:

   ...:

   ...:

   ...: report = classification_report(y_test, y_pred)

   ...: print("Classification Report:")

   ...: print(report)

C: 1e-05

MSE: 37.962250126693846

RMSE 6.16135132310225

MAE: 4.952147755870551

C: 0.001

Classification Report:

precision recall f1-score support


0 0.76 0.57 0.65 28

1 0.43 0.64 0.51 14


accuracy 0.60 42

macro avg 0.60 0.61 0.58 42

weighted avg 0.65 0.60 0.61 42



In [2]: