ANN

CODE:

import pandas as pd 
from sklearn import datasets
from sklearn.model_selection import train_test_split 
from sklearn.linear_model import LinearRegression  
import numpy as np  
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasRegressor

def clean_dataset(df):
    assert isinstance(df, pd.DataFrame), "df needs to be a pd.DataFrame"
    df.dropna(inplace=True)
    indices_to_keep = ~df.isin([np.nan, np.inf, -np.inf]).any(1)
    return df[indices_to_keep].astype(np.float64)


def baseline_model():
  # create model
 model = Sequential()
 model.add(Dense(20, input_dim=7, kernel_initializer='normal', activation='relu'))
 model.add(Dense(40, kernel_initializer='normal', activation='relu'))
 model.add(Dense(2, kernel_initializer='normal'))
 # Compile model
 model.compile(loss='mean_squared_error', optimizer='adam')
 return model


dataset = pd.read_csv('Total.csv',names = ['alpha','PIR', 'ptt', 'bpmax' ,'bpmin', 'hrfinal', 'ih', 'il', 'meu'])

X = dataset[['alpha','PIR', 'ptt', 'hrfinal', 'ih', 'il', 'meu']]

y = dataset[['bpmax','bpmin']]
#X2 = dataset2[['Ptt','ih','il','hr','v','w']]
#test = datset2[['firstaxis_1','firstaxis_2','firstaxis_3','secondaxis_1','secondaxis_2','secondaxis_3','thirdaxis_1','thirdaxis_2','thirdaxis_3','eigen1','eigen2','eigen3','firstaxis_len','secondaxis_len','thirdaxis_len','c1','c2','c3','mer_ecc','eq_ecc','age']]


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) 
#print X_test

from sklearn.preprocessing import StandardScaler
sc_X=StandardScaler()
x_train=sc_X.fit_transform(X_train)
x_test=sc_X.transform(X_test)


estimator = KerasRegressor(build_fn=baseline_model, epochs=1000, batch_size=10, verbose=2)


estimator.fit(x_train, y_train)
y_pred = estimator.predict(x_test)
#print y_test
#print regressor.coef_
# print('Coefficients: \n', regressor.coef_)
# # The mean squared error
from sklearn import metrics  

print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))  
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))  
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))



7 features :

1000 epochs:

20-40-2 :

('Mean Absolute Error:', 8.4142662593968414)

('Mean Squared Error:', 201.26948545687782)

('Root Mean Squared Error:', 14.186947714602947)


bpmax:

  • ('Mean Absolute Error:', 13.330091516706679)
  • ('Mean Squared Error:', 330.57535151277852)
  • ('Root Mean Squared Error:', 18.181731257302715)
  • Variance score: 0.65

bpmin:

  • ('Mean Absolute Error:', 3.9213835690685812)
  • ('Mean Squared Error:', 98.93170145346383)
  • ('Root Mean Squared Error:', 9.9464416478187729)
  • Variance score: 0.87

3 features:

  • 1000 epochs

8-16-2:

  • ('Mean Absolute Error:', 20.85615428872044)
  • ('Mean Squared Error:', 693.78752406024773)
  • ('Root Mean Squared Error:', 26.33984669773626)
  • Variance score: 0.16


bpmax:

  • ('Mean Absolute Error:', 20.09110755707712)
  • ('Mean Squared Error:', 643.03394666124677)
  • ('Root Mean Squared Error:', 25.358114020195721)
  • Variance score: 0.32


bpmin:

  • ('Mean Absolute Error:', 21.303049514195063)
  • ('Mean Squared Error:', 721.77391485986027)
  • ('Root Mean Squared Error:', 26.865850346859677)
  • Variance score: 0.02