# How do I train Xgboost classifier for ECG Signal data?

I am testing https://www.physionet.org/challenge/2017/sources/ submission.

I like one of the submission code, which use Xgboost to train the classifier. Training data is in .mat file which can be converted to csv format.

In below code, I have pretrained model xgb.bin, using which I can test any input signal. But I Want to train the model using different data and create my own training model.

Here is the code which predicts class name for given input ecg file

def predict(data):

from numpy import genfromtxt
data = genfromtxt('testdata/val.csv', delimiter=',')

features_noise = np.zeros((5, ))

snr, rr_num, var, fr, fr2 = find_noise_features(data)
features_noise[0] = snr
features_noise[1] = rr_num
features_noise[2] = var
features_noise[3] = fr
features_noise[4] = fr2
features = extract_basic_features(data, 30000)
features = np.hstack((features, features_noise.reshape(1, -1)))

mean_ = np.array([15.96300284066109753667, 0.00412371298595770857, 38811.34497233365254942328,
0.48050717744965593115, 0.14397582347542958736])
scale_ = np.array([4.22917401559752281770, 0.00093664880988427878, 62350.76443798459513345733,
0.15396567666240373873, 0.07085474966801086349])
features_noise -= mean_
features_noise /= scale_

prediction = 0
if features_noise[0] < -2.9:
prediction = 3
if features_noise[2] > 6.0:
prediction = 3
if features_noise[3] > 3.0:
prediction = 3
if features_noise[4] < -2.0:
prediction = 3

bst = xgb.Booster({'nthread': 4})

dfeatures = xgb.DMatrix(features)
prediction_prob = bst.predict(dfeatures)
prediction = np.argmax(prediction_prob)

return prediction

def run(data):
prediction = predict(data)
print(prediction)


I want to train this classifer using my own dataset. Above model is trained on https://www.physionet.org/challenge/2017/training2017.zip dataset.

Looking at above code, do you have any clue how can I train the model using Xgboost.

Here is my thought steps

1. Calculate features for all training signal in zip file
2. Calculate feature_noise as it is in above code for all signals
3. Calculate dfeatures features for each signals (Should I calculate it for each signals or for all signal together)
4. Train dfeatures for all signals using Xgboost (How?)
5. Store the xgboost model

Is this correct steps to do?