ecg-classify icon indicating copy to clipboard operation
ecg-classify copied to clipboard

I cant read the data in feature extraction step at ECG-classify

Open ryulistiani opened this issue 3 years ago • 0 comments

Hello, thanks for your code it's mean a lot to help my project.

I tried to implement your code with polysomnography data. it's work until I try to implement Model Fitting, I try to solve the problem, but when I check the Feature Extraction step, I found the code cant process the data, the plot in 'if not' didn't show, here the code I mean

lst = list()

for i in DS1: rec_index = i

# Tweak the use_filter param
lst = extract_features("slpdb/" + rec_index, length_qrs, length_stt, ar_order_qrs=3, ar_order_stt=3, use_filter=True)
df = pd.DataFrame(lst)

#I try to print the code but the output is null [ ]

if not df.empty and not df[df["type"] == "VEB"].empty and not df[df["type"] == "N"].empty: n_pre_rr = df[df["type"] == "N"]["pre-RR"] veb_pre_rr = df[df["type"] == "VEB"]["pre-RR"] n_post_rr = df[df["type"] == "N"]["post-RR"] veb_post_rr = df[df["type"] == "VEB"]["post-RR"]

    fig1 = plt.figure()
    ax1 = fig1.add_subplot(121, title="Record {} | Pre-RR")
    ax1.scatter(n_pre_rr, c="c", label="Normal")
    ax1.scatter(veb_pre_rr, c="r", label="VEB")
    
    

    n_qrs_ar_array = series2arCoeffs(df[df["type"] == "N"]["QRS_ar_coeffs"])
    veb_qrs_ar_array = series2arCoeffs(df[df["type"] == "VEB"]["QRS_ar_coeffs"])
    n_stt_ar_array = series2arCoeffs(df[df["type"] == "N"]["ST/T_ar_coeffs"])
    veb_stt_ar_array = series2arCoeffs(df[df["type"] == "VEB"]["ST/T_ar_coeffs"])

    fig = plt.figure(figsize=(20, 5))

    ax1 = fig.add_subplot(141, title="Record {} | QRS | a0 vs a1".format(rec_index))
    plt.ylim(-2.5, 0.5)
    plt.xlim(0.8, 2.6)
    ax1.scatter(x=n_qrs_ar_array[:, 0], y=n_qrs_ar_array[:, 1], c='c', label="Normal")
    ax1.scatter(x=veb_qrs_ar_array[:, 0], y=veb_qrs_ar_array[:, 1], c='r', label="VEB")
    plt.legend(loc="best")

    ax2 = fig.add_subplot(142, title="Record {} | QRS | a1 vs a2".format(rec_index))
    plt.ylim(-0.6, 0.8)
    plt.xlim(-2.5, 0.5)
    ax2.scatter(x=n_qrs_ar_array[:, 1], y=n_qrs_ar_array[:, 2], c='c', label="Normal")
    ax2.scatter(x=veb_qrs_ar_array[:, 1], y=veb_qrs_ar_array[:, 2], c='r', label="VEB")
    plt.legend(loc="best")

    ax3 = fig.add_subplot(143, title="Record {} | ST/T | a0 vs a1".format(rec_index))
    plt.ylim(-3, 0.5)
    plt.xlim(0.5, 3)
    ax3.scatter(x=n_stt_ar_array[:, 0], y=n_stt_ar_array[:, 1], c='c', label="Normal")
    ax3.scatter(x=veb_stt_ar_array[:, 0], y=veb_stt_ar_array[:, 1], c='r', label="VEB")
    plt.legend(loc="best")

    ax4 = fig.add_subplot(144, title="Record {} | ST/T | a1 vs a2".format(rec_index))
    plt.ylim(-0.6, 1)
    plt.xlim(-3, 0.5)
    ax4.scatter(x=n_stt_ar_array[:, 1], y=n_stt_ar_array[:, 2], c='c', label="Normal")
    ax4.scatter(x=veb_stt_ar_array[:, 1], y=veb_stt_ar_array[:, 2], c='r', label="VEB")
    plt.legend(loc="best")

else:
    print("Record {} : At least one empty category : VEB or N.".format(rec_index)

What should I do to solve the code?

Thanks for your help

ryulistiani avatar Apr 15 '21 09:04 ryulistiani