application_vnd.jupyter.stderr_output_1.png
from spektral.layers import GCNConv

from spektral.layers import GCNConv

from tensorflow.keras.callbacks import EarlyStopping

from tensorflow.keras.layers import Input, Dropout, Dense,Reshape,GlobalMaxPool1D,MaxPool1D

from tensorflow.keras.models import Model

from tensorflow.keras.optimizers import Adam

import numpy as np

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import tensorflow as tf

import tensorflow.keras.backend as K

import warnings

import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.spatial.distance import squareform
from scipy.cluster.hierarchy import dendrogram, linkage
import warnings
warnings.filterwarnings('ignore')
from scipy.cluster.hierarchy import dendrogram
from sklearn.cluster import AgglomerativeClustering
from matplotlib import pyplot as plt
pro = pd.read_csv('/kaggle/input/amp-parkinsons-disease-progression-prediction/train_proteins.csv')
train = pd.read_csv('/kaggle/input/amp-parkinsons-disease-progression-prediction/train_clinical_data.csv')
test_proteins = pd.read_csv('/kaggle/input/amp-parkinsons-disease-progression-prediction/example_test_files/test_proteins.csv')
pro1 = pro.pivot(index=['visit_id', 'visit_month', 'patient_id'], columns='UniProt', values='NPX').reset_index().rename_axis(None, axis=1)
pro3 = pro1.dropna(thresh=1000, axis=1)
FEATURES_ALL = pro3.iloc[:, 3:].columns.tolist()
pro4 = pro3.dropna()
pro5 = pro4.copy()
for i in FEATURES_ALL:
    pro5.loc[:, i] = (pro4.loc[:, i] - pro4.loc[:, i].mean(axis=0)) / pro4.loc[:, i].std(axis=0)
pro6 = train.merge(pro5, how='left', on='visit_id').dropna(subset=['Q92823']).rename(columns={'patient_id_x': 'patient_id', 'visit_month_x': 'visit_month'})
pro6
pro7 = pro6[pro6['visit_month'] <= 36]
FEATURES_PPI = ['O00584', 'O14773', 'O60888', 'O94919', 'P00441', 'P00734', 'P00736', 'P00738', 'P00746', 'P00747', 'P00748', 'P00751', 'P01008', 'P01009', 'P01011', 'P01023', 'P01024', 'P01033', 'P01344', 'P01621', 'P01717', 'P01834', 'P01857', 'P01859', 'P01860', 'P01876', 'P01877', 'P02452', 'P02652', 'P02656', 'P02679', 'P02747', 'P02749', 'P02750', 'P02751', 'P02753', 'P02760', 'P02763', 'P02765', 'P02766', 'P02768', 'P02787', 'P02790', 'P04004', 'P04156', 'P04180', 'P04196', 'P04207', 'P04211', 'P04216', 'P04217', 'P04275', 'P04433', 'P05067', 'P05090', 'P05155', 'P05156', 'P05546', 'P06681', 'P06727', 'P07195', 'P07225', 'P07339', 'P07711', 'P07858', 'P07998', 'P08294', 'P08493', 'P08697', 'P09486', 'P10451', 'P10643', 'P13521', 'P13611', 'P16070', 'P18065', 'P19652', 'P19823', 'P24592', 'P25311', 'P35542', 'P36222', 'P39060', 'P40925', 'P41222', 'P43251', 'P43652', 'P49908', 'P51884', 'P54289', 'P61626', 'P80748', 'P98160', 'Q13283', 'Q13451', 'Q14118', 'Q14508', 'Q14515', 'Q14624', 'Q16270', 'Q16610', 'Q6UXB8', 'Q7Z5P9', 'Q8IWV7', 'Q8N2S1', 'Q8NBJ4', 'Q92520', 'Q92876', 'Q96PD5', 'Q9BY67', 'Q9NQ79', 'Q9Y646', 'Q9Y6R7']
SUPPLYMENT_FEATURE = ['P00450', 'P10451', 'P01033', 'P01008', 'P02647', 'P01024', 'Q92876']
FEATURES_PPI = list(set(SUPPLYMENT_FEATURE) | set(FEATURES_PPI))
data = pro7[FEATURES_PPI]
corr = data.corr()
corr
adjoint = corr
adjoint

pro1 = pro.pivot(index=['visit_id', 'visit_month', 'patient_id'], columns='UniProt', values='NPX').reset_index().rename_axis(None, axis=1)
pro3 = pro1.dropna(thresh=1000, axis=1)
FEATURES_ALL = pro3.iloc[:, 3:].columns.tolist()
FEATURES_DLE = list(set(FEATURES_ALL) - set(FEATURES_PPI))
for i in FEATURES_ALL:
    pro3.loc[:, i] = pro3.loc[:, i].fillna(pro3.loc[:, i].median())
pro4 = pro3.dropna()
pro5 = pro4.copy()
for i in FEATURES_ALL:
    pro5.loc[:, i] = (pro4.loc[:, i] - pro4.loc[:, i].mean(axis=0)) / pro4.loc[:, i].std(axis=0)
pro6 = train.merge(pro5, how='left', on='visit_id').dropna(subset=['Q92823']).rename(columns={'patient_id_x': 'patient_id', 'visit_month_x': 'visit_month'})
pro6.drop(FEATURES_DLE, axis=1, inplace=True)
finaldata = pro6
finaldata = finaldata.dropna()
finaldata = finaldata.reset_index()
finaldata.visit_month = finaldata.visit_month.astype('float')
finaldata

target = ['updrs_1', 'updrs_2', 'updrs_3', 'updrs_4']
x = finaldata[FEATURES_PPI]
y = finaldata[target]

adjoint1 = np.array(adjoint)[np.newaxis, :, :]
adjoint2 = np.repeat(adjoint1, len(finaldata), 0)
x1 = x.values[:, :, np.newaxis]

from spektral.layers import GCNConv
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Input, Dropout, Dense, Reshape, GlobalMaxPool1D, MaxPool1D
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import EarlyStopping
from spektral.layers import GCNConv
from spektral.utils import normalized_adjacency
import tensorflow.keras.backend as K
tf.keras.utils.set_random_seed(1234)
tf.random.set_seed(1234)
def smape_loss(y_true, y_pred):
    epsilon = 0.1
    y_true = y_true + 1
    y_pred = y_pred + 1
    numer = K.abs(y_pred - y_true)
    denom = K.maximum(K.abs(y_true) + K.abs(y_pred) + epsilon, 0.5 + epsilon)
    smape = numer / (denom / 2) * 100
    smape = tf.where(tf.math.is_nan(smape), tf.zeros_like(smape), smape)
    return smape
def calculate_smape(y_true, y_pred):
    y_true, y_pred = (np.array(y_true), np.array(y_pred))
    numer = np.round(np.abs(y_pred - y_true), 0)
    denom = np.round(np.abs(y_true) + np.abs(y_pred), 0)
    return 1 / len(y_true) * np.sum(np.nan_to_num(numer / (denom / 2))) * 100
def build_model():
    X_in = Input(shape=(len(adjoint), 1))
    A_in = Input((len(adjoint), len(adjoint)), sparse=True)
    X_1 = GCNConv(116, activation='relu')([X_in, A_in])
    X_2 = GlobalMaxPool1D()(X_1)
def build_model():
    X_in = Input(shape=(len(adjoint), 1))
    A_in = Input((len(adjoint), len(adjoint)), sparse=True)
    X_1 = GCNConv(256, activation='relu')([X_in, A_in])
    X_2 = GlobalMaxPool1D()(X_1)
    X_3 = Dense(256, activation='relu')(X_2)
    X_3 = Dropout(0.3)(X_3)
    X_4 = Dense(256, activation='relu')(X_3)
    X_5 = Dense(150, activation='relu')(X_4)
    X_6 = Dense(150, activation='relu')(X_5)
    X_6 = Dropout(0.3)(X_6)
    X_7 = Dense(128, activation='relu')(X_6)
    X_7 = Dropout(0.3)(X_7)
    X_8 = Dense(128, activation='relu')(X_7)
    X_8 = Dropout(0.3)(X_8)
    output = Dense(4, activation='linear')(X_7)
    model = Model(inputs=[X_in, A_in], outputs=output)
    return model
model = build_model()
optimizer = Adam(learning_rate=0.005)
early_stopping = EarlyStopping(patience=10, restore_best_weights=True)
model.compile(optimizer=optimizer, loss=smape_loss)
model.summary()