Ejemplo n.º 1
0
def feature_extract(dt):
    
    import tsfresh.feature_extraction.feature_calculators as fc
    
    ft = {
        'abs_energy': fc.abs_energy(dt),
        'sum_values': fc.sum_values(dt),
        'mean': fc.mean(dt),
        'maximum': fc.maximum(dt),
        'minimum': fc.minimum(dt),
        'median': fc.median(dt),
        'quantile_0.1': fc.quantile(dt, 0.1),
        'quantile_0.2': fc.quantile(dt, 0.2),
        'quantile_0.3': fc.quantile(dt, 0.3),
        'quantile_0.4': fc.quantile(dt, 0.4),
        'quantile_0.5': fc.quantile(dt, 0.5),
        'quantile_0.6': fc.quantile(dt, 0.6),
        'quantile_0.7': fc.quantile(dt, 0.7),
        'quantile_0.8': fc.quantile(dt, 0.8),
        'quantile_0.9': fc.quantile(dt, 0.9),
        #
        # TODO:
        # Below functions dont works well -> need to be checked!!
        #
        #'fft_coefficient__coeff_0__attr_real': fc.fft_coefficient(dt {"coeff": 0, "attr": "real"}),
        #'fft_coefficient__coeff_0__attr_imag': fc.fft_coefficient(dt {"coeff": 0, "attr": "imag"}),
        #'fft_coefficient__coeff_0__attr_abs': fc.fft_coefficient(dt {"coeff": 0, "attr": "abs"}),
        #'fft_coefficient__coeff_0__attr_angle': fc.fft_coefficient(dt {"coeff": 0, "attr": "angle"}),
        #
        #=> Mr. Huy just fix this issue with above function fft_ft !!
    }
    
    ft.update(fft_ft(dt))
    
    return ft
Ejemplo n.º 2
0
    def get_sta_features(self, data):
        """
        Calculate the value of 9 kinds of selected statistical features
        :param data:
        :return:
        """
        def _cal_trend(data):
            time_list = np.arange(len(data))
            # create linear regression object
            regr = linear_model.LinearRegression()
            regr.fit(time_list.reshape(-1, 1), np.array(data).reshape(-1, 1))

            return regr.coef_[0][0]

        E = ts.abs_energy(data)
        S = ts.binned_entropy(data, max_bins=5)
        ro = ts.autocorrelation(data, lag=4)
        skewness = ts.skewness(data)
        kurtosis = ts.kurtosis(data)
        trend = _cal_trend(data)
        mean = ts.mean(data)
        min = ts.minimum(data)
        max = ts.maximum(data)

        return [E, S, ro, skewness, kurtosis, trend, mean, min, max]
def TS_feature3(signal):
    max_ts = ts.maximum(signal)
    mean_rs = ts.mean(signal)
    mean_abs_change = ts.mean_abs_change(signal)
    mean_change = ts.mean_change(signal)
    median_ts = ts.median(signal)
    minimum_ts = ts.minimum(signal)
    return max_ts, mean_rs, mean_abs_change, mean_change, median_ts, minimum_ts
Ejemplo n.º 4
0
def time_series_mean(x):
    """
    :param x: the time series to calculate the feature of
    :type x: pandas.Series
    :return: the value of this feature
    :return type: float
    """
    return ts_feature_calculators.mean(x)
Ejemplo n.º 5
0
def scalar_feature_extraction(column):
    retval = np.zeros([1, 10], dtype=float)
    retval[0][0] = tffe.count_above_mean(column.values)
    retval[0][1] = tffe.mean(column.values)
    retval[0][2] = tffe.maximum(column.values)
    retval[0][3] = tffe.median(column.values)
    retval[0][4] = tffe.minimum(column.values)
    retval[0][5] = tffe.sample_entropy(column.values)
    if (isNaN(retval[0][5])):
        retval[0][5] = 0
    retval[0][6] = tffe.skewness(column.values)
    retval[0][7] = tffe.variance(column.values)
    retval[0][8] = tffe.longest_strike_above_mean(column.values)
    retval[0][9] = tffe.longest_strike_below_mean(column.values)
    return retval
Ejemplo n.º 6
0
def feature_extraction(cgm_glucose):

    n = len(cgm_glucose[0])
    chunk_size = n // 4

    rows = []

    for row in cgm_glucose:
        val = []

        # Feature set 1 : Mean
        for i in range(0, 30, 6):
            val.append(fc.mean(row[i:i + 6]))

        # Feature set 2: Sum of reoccurring data points
        for i in range(0, 30, 6):
            val.append(fc.sum_of_reoccurring_data_points(row[i:i + 6]))

        # Computing the top 5 fft coefficients
        fft_coefficients = fft(row, n=6)[1:]
        fft_coefficients_real = [value.real for value in fft_coefficients]
        val += fft_coefficients_real
        # val.extend(fft_coefficients_real)

        # Feature set 4: Polyfit
        x = np.linspace(0, 1, len(row))
        y = row
        val.extend(poly.polyfit(x, y, 3)[:-1])

        rows.append(val)

    feature_matrix = pd.DataFrame(StandardScaler().fit_transform(rows))
    # Transform data to training dimensional space

    pca_components = pd.read_csv("pca_components.csv", header=None)
    transformedData = np.dot(feature_matrix, np.transpose(pca_components))

    # Run all 4 classfication algorithms on test data

    classify_test_data(transformedData)
Ejemplo n.º 7
0
def main():  #purely for testing     #calculates the AUC score
    df = pd.read_csv("feature_data.csv")
    feature_scalar = preprocessing.MinMaxScaler()
    feature_scalar.fit(df)
    transformed_df = pd.DataFrame(feature_scalar.transform(df))
    joblib.dump(feature_scalar, "feature_scaler.save")
    average = tffe.mean(transformed_df[185])
    transformed_df = downsampling(transformed_df)
    l2_auc = make_l2_model(transformed_df)
    drop_auc = make_drop_model(transformed_df)
    l1_auc = make_l1_model(transformed_df)

    data = [[l1_auc, l2_auc, drop_auc]]
    auc_df = pd.DataFrame(data, columns=['l1_auc', 'l2_auc', 'drop_auc'])
    auc_df.to_csv("auc.csv", index=False)
    print(average)  #'''
    '''
    df = pd.read_csv("feature_data.csv")
    feature_scalar = preprocessing.MinMaxScaler()
    feature_scalar.fit(df)
    joblib.dump(feature_scalar, "feature_scaler.save")#'''

    #'''
    #df = pd.read_csv("feature_data.csv")
    '''df = pd.read_csv("trashdb.csv")
    df = df.drop("Date", axis=1)
    df = df.drop("charttime", axis=1)
    scaler = preprocessing.MinMaxScaler()
    #prcol.fit(df["Val1"])
    scaler.fit(df)
    print(scaler.data_max_)
    joblib.dump(scaler, "scaler.save")#'''
    '''df = pd.read_csv("trashdb.csv")
    df = df.drop("Date", axis=1)
    df = df.drop("charttime", axis=1)
    scaler = joblib.load("scaler.save")
    transformed_df = scaler.transform(df)
    print(transformed_df[9])#'''
    return
Ejemplo n.º 8
0
def extract_features(data):
    day = 24 * 60

    return list(
        numpy.nan_to_num(
            numpy.array([
                feature.symmetry_looking(data, [{
                    'r': 0.3
                }])[0][1],
                feature.variance_larger_than_standard_deviation(data).bool(),
                feature.ratio_beyond_r_sigma(data, 2),
                feature.has_duplicate_max(data),
                feature.has_duplicate_min(data),
                feature.has_duplicate(data),
                feature.agg_autocorrelation(numpy.array(data.value),
                                            [{
                                                'f_agg': 'mean',
                                                'maxlag': day
                                            }])[0][1],
                feature.partial_autocorrelation(data, [{
                    'lag': day
                }])[0][1],
                feature.abs_energy(numpy.array(data.value)),
                feature.mean_change(data),
                feature.mean_second_derivative_central(data),
                feature.median(data),
                float(feature.mean(data)),
                float(feature.standard_deviation(data)),
                float(feature.longest_strike_below_mean(data)),
                float(feature.longest_strike_above_mean(data)),
                int(feature.number_peaks(data, 10)),
                feature.linear_trend(numpy.array(data.value), [{
                    'attr': 'rvalue'
                }])[0][1],
                feature.c3(data, day),
                float(feature.maximum(data)),
                float(feature.minimum(data))
            ])))
Ejemplo n.º 9
0
def feature_extraction():
    cgm_glucose_levels_no_meal = pd.read_csv("preprocessed_Nomeal.csv")
    cgm_glucose_levels_meal = pd.read_csv("preprocessed_mealData.csv")

    cgm_glucose = np.concatenate(
        (cgm_glucose_levels_meal.values, cgm_glucose_levels_no_meal.values),
        axis=0)

    n = len(cgm_glucose[0])
    chunk_size = n // 4

    rows = []

    for row in cgm_glucose:
        val = []

        # Feature set 1 : Windowed Mean
        for i in range(0, 30, 6):
            val.append(fc.mean(row[i:i + 6]))

        # Feature set 2: Windowed Variance
        # for i in range(0,30,6):
        #     val.append(fc.variance(row[i:i+6]))
        for i in range(0, 30, 6):
            val.append(fc.sum_of_reoccurring_data_points(row[i:i + 6]))

        # Computing the top 5 fft coefficients
        fft_coefficients = fft(row, n=6)[1:]
        fft_coefficients_real = [value.real for value in fft_coefficients]
        val += fft_coefficients_real

        #val.append(np.sqrt(np.mean(row[24:]**2)))

        # Feature set 4: Polyfit

        x = np.linspace(0, 1, len(row))
        y = row
        val.extend(poly.polyfit(x, y, 3)[:-1])

        rows.append(val)

        # for i in range(0, 30, 6):
        #     val.append(fc.change_quantiles(row[i:i + 6],))

    feature_matrix = pd.DataFrame(StandardScaler().fit_transform(rows))
    labels = [1] * len(cgm_glucose_levels_meal)
    label_no = [0] * len(cgm_glucose_levels_no_meal)
    labels.extend(label_no)
    labels = np.array(labels)

    feature_matrix_meal = feature_matrix.iloc[:len(cgm_glucose_levels_meal
                                                   ), :].values
    feature_matrix_no_meal = feature_matrix.iloc[
        len(cgm_glucose_levels_meal):, :].values

    pca = PCA()
    pca.fit(feature_matrix_meal)
    # print("PCA explained variance: ")
    # print(pca.explained_variance_ratio_)

    # Saving new dim-space
    pd.DataFrame(pca.components_[:5]).to_csv("pca_components.csv",
                                             header=None,
                                             index=None)

    transformedData = np.dot(feature_matrix_meal,
                             np.transpose(pca.components_[:5]))
    transformedData_no_meal = np.dot(feature_matrix_no_meal,
                                     np.transpose(pca.components_[:5]))

    transformedData = np.concatenate(
        (transformedData, transformedData_no_meal))

    return transformedData, labels
Ejemplo n.º 10
0
 def DCMean(self,x):
     x=self.butter_lowpass_filter(x,1,200)
     return fc.mean(x)
Ejemplo n.º 11
0
 def ACAbsMean(self, x):
     x=self.butter_bandpass_filter(x,0.1,20,200)
     return fc.mean(np.absolute(x))
def main():
    dirname = os.path.realpath('.')
    excelF = dirname + '\\Summary.xlsx'
    myworkbook = openpyxl.load_workbook(excelF)
    worksheet = myworkbook['SummaryPatients']

    file = 1
    for filename in glob.glob(dirname + "\*.txt"):

        data = open(filename, 'r')

        totalData = {}

        time = []
        totalForceL = []
        totalForceR = []
        id = []
        for line in data:
            tempForce = line.split()
            id.append(1)
            time.append(float(tempForce[0]))
            totalForceL.append(float(tempForce[17]))
            totalForceR.append(float(tempForce[18]))

        totalData["id"] = id
        totalData["time"] = time
        totalData["totalForceL"] = totalForceL
        totalData["totalForceR"] = totalForceR

        dataPandas = pd.DataFrame.from_dict(totalData)

        extracted_features = {}
        #extract_featuresL = extract_features(dataPandas, column_id="id", column_kind=None, column_value=None)

        worksheet['A' + str(file + 1)] = file
        if 'Pt' in filename:
            worksheet['B' + str(file + 1)] = 1
        else:
            worksheet['B' + str(file + 1)] = 0

        worksheet['C' + str(file + 1)] = tf.abs_energy(
            totalData["totalForceL"])
        worksheet['D' + str(file + 1)] = tf.abs_energy(
            totalData["totalForceR"])
        worksheet['E' + str(file + 1)] = tf.kurtosis(totalData["totalForceL"])
        worksheet['F' + str(file + 1)] = tf.kurtosis(totalData["totalForceR"])
        worksheet['G' + str(file + 1)] = tf.skewness(totalData["totalForceL"])
        worksheet['H' + str(file + 1)] = tf.skewness(totalData["totalForceR"])
        worksheet['I' + str(file + 1)] = tf.median(totalData["totalForceL"])
        worksheet['J' + str(file + 1)] = tf.median(totalData["totalForceR"])
        worksheet['K' + str(file + 1)] = tf.mean(totalData["totalForceL"])
        worksheet['L' + str(file + 1)] = tf.mean(totalData["totalForceR"])
        worksheet['M' + str(file + 1)] = tf.variance(totalData["totalForceL"])
        worksheet['N' + str(file + 1)] = tf.variance(totalData["totalForceR"])

        temp = tf.fft_aggregated(totalData["totalForceL"],
                                 [{
                                     "aggtype": "centroid"
                                 }, {
                                     "aggtype": "variance"
                                 }, {
                                     "aggtype": "skew"
                                 }, {
                                     "aggtype": "kurtosis"
                                 }])
        int = 0
        for list in temp:
            if int == 0:
                worksheet['O' + str(file + 1)] = list[1]
            if int == 1:
                worksheet['P' + str(file + 1)] = list[1]
            if int == 2:
                worksheet['Q' + str(file + 1)] = list[1]
            if int == 3:
                worksheet['R' + str(file + 1)] = list[1]
            int += 1

        temp2 = tf.fft_aggregated(totalData["totalForceR"],
                                  [{
                                      "aggtype": "centroid"
                                  }, {
                                      "aggtype": "variance"
                                  }, {
                                      "aggtype": "skew"
                                  }, {
                                      "aggtype": "kurtosis"
                                  }])
        int = 0
        for list in temp2:
            if int == 0:
                worksheet['S' + str(file + 1)] = list[1]
            if int == 1:
                worksheet['T' + str(file + 1)] = list[1]
            if int == 2:
                worksheet['U' + str(file + 1)] = list[1]
            if int == 3:
                worksheet['V' + str(file + 1)] = list[1]
            int += 1

        file += 1

    myworkbook.save(excelF)
Ejemplo n.º 13
0
def main():
    dirname = os.path.realpath('.')
    filename = dirname + '\\GaPt07_01.txt'

    data = open(filename, 'r')

    totalData = {}

    time = []
    totalForceL = []
    totalForceR = []
    id = []
    for line in data:
        tempForce = line.split()
        id.append(1)
        time.append(float(tempForce[0]))
        totalForceL.append(float(tempForce[17]))
        totalForceR.append(float(tempForce[18]))

    totalData["id"] = id
    totalData["time"] = time
    totalData["totalForceL"] = totalForceL
    totalData["totalForceR"] = totalForceR

    dataPandas = pd.DataFrame.from_dict(totalData)

    extracted_features = {}

    #extract_featuresL = extract_features(dataPandas, column_id="id", column_kind=None, column_value=None)
    extracted_features["absEnergyL"] = tf.abs_energy(totalData["totalForceL"])
    extracted_features["absEnergyR"] = tf.abs_energy(totalData["totalForceR"])
    extracted_features["kurtosisL"] = tf.kurtosis(totalData["totalForceL"])
    extracted_features["kurtosisR"] = tf.kurtosis(totalData["totalForceR"])
    extracted_features["skewnessL"] = tf.skewness(totalData["totalForceL"])
    extracted_features["skewnessR"] = tf.skewness(totalData["totalForceR"])
    extracted_features["medianL"] = tf.median(totalData["totalForceL"])
    extracted_features["medianR"] = tf.median(totalData["totalForceR"])
    extracted_features["meanL"] = tf.mean(totalData["totalForceL"])
    extracted_features["meanR"] = tf.mean(totalData["totalForceR"])
    extracted_features["varianceL"] = tf.variance(totalData["totalForceL"])
    extracted_features["varianceR"] = tf.variance(totalData["totalForceR"])

    temp = tf.fft_aggregated(totalData["totalForceL"], [{
        "aggtype": "centroid"
    }, {
        "aggtype": "variance"
    }, {
        "aggtype": "skew"
    }, {
        "aggtype": "kurtosis"
    }])
    int = 0
    for list in temp:
        if int == 0:
            extracted_features["fftCentroidL"] = list
        if int == 1:
            extracted_features["fftVarianceL"] = list
        if int == 2:
            extracted_features["fftSkewL"] = list
        if int == 3:
            extracted_features["fftKurtosisL"] = list
        int += 1

    temp2 = tf.fft_aggregated(totalData["totalForceR"], [{
        "aggtype": "centroid"
    }, {
        "aggtype": "variance"
    }, {
        "aggtype": "skew"
    }, {
        "aggtype": "kurtosis"
    }])
    int = 0
    for list in temp2:
        if int == 0:
            extracted_features["fftCentroidR"] = list
        if int == 1:
            extracted_features["fftVarianceR"] = list
        if int == 2:
            extracted_features["fftSkewR"] = list
        if int == 3:
            extracted_features["fftKurtosisR"] = list
        int += 1
Ejemplo n.º 14
0
def feature_vector_communicate_ind(trimmed_data, column_name, iscommunicate=False, test=False):

    r = trimmed_data[column_name]
    if column_name == 'rightWrist_x':
        normRawColumn = universal_normalization(r, trimmed_data, x_norm=True)
    else:
        normRawColumn = universal_normalization(r, trimmed_data, x_norm=False)
    normRawColumn = general_normalization(normRawColumn)

    diffNormRawData = np.diff(normRawColumn)

    zeroCrossingArray = np.array([])
    maxDiffArray = np.array([])

    # Fast Fourier Transform
    fftArray = np.array([])
    fftVal = []
    fft_coefficients = fft(diffNormRawData, n=6)[1:]
    fft_coefficients_real = [value.real for value in fft_coefficients]
    fftVal += fft_coefficients_real
    fftArray = np.append(fftArray, fftVal)

    # Windowed Mean for each second of the video
    windowedVal = np.array([])
    for i in range(0,diffNormRawData.shape[0],30):
        windowedVal = np.append(windowedVal, fc.mean(diffNormRawData[i:i+30]))

    # Other features
    if diffNormRawData[0] > 0:
        initSign = 1
    else:
        initSign = 0

    windowSize = 5

    for x in range(1, len(diffNormRawData)):

        if diffNormRawData[x] > 0:
            newSign = 1
        else:
            newSign = 0

        if initSign != newSign:
            zeroCrossingArray = np.append(zeroCrossingArray, x)
            initSign = newSign
            maxIndex = np.minimum(len(diffNormRawData), x + windowSize)
            minIndex = np.maximum(0, x - windowSize)

            maxVal = np.amax(diffNormRawData[minIndex:maxIndex])
            minVal = np.amin(diffNormRawData[minIndex:maxIndex])

            maxDiffArray = np.append(maxDiffArray, (maxVal - minVal))

    index = np.argsort(-maxDiffArray)

    featureVector = np.array([])
    featureVector = np.append(featureVector, fftArray)
    featureVector = np.append(featureVector, windowedVal)
    featureVector = np.append(featureVector, maxDiffArray[index[0:5]])

    if TRIM_DATA_SIZE_COMMUNICATE - 1 > featureVector.shape[0]:
        featureVector = np.pad(featureVector, (0, TRIM_DATA_SIZE_COMMUNICATE - featureVector.shape[0] - 1), 'constant')
    featureVector = featureVector[:TRIM_DATA_SIZE_COMMUNICATE - 1]
    if not test:
        if iscommunicate:
            featureVector = np.append(featureVector, 1)
        else:
            featureVector = np.append(featureVector, 0)
    return featureVector
Ejemplo n.º 15
0
def logistic_feature_extraction(column):
    retval = np.zeros([1, 1], dtype=float)
    retval[0][0] = tffe.mean(column.values)
    return retval
Ejemplo n.º 16
0
    li = []
    if row[0] - time_begin < threshold:
        rank[int(row[23])] = rank[int(row[23])] + 1
        i = 0
        while i < 23:
            li.append(row[i])
            i = i + 1
        # tem_row = np.asarray(li)
        tem_row.append(li)
        list_row = np.asarray(tem_row)
        cnt = cnt + 1
    else:
        flag.append(rank.index(max(rank)))  # 求出窗口内标记出现最多的标签,作为最后窗口的标记label
        list_row = pd.DataFrame(list_row)
        # res_row = abs_energy(list_row.iloc[:, 0])
        res_row = mean(list_row)
        res.append(res_row)
        time_begin = row[0]
        cnt = 1
        rank = [0] * 9
        tem_row = []

res = pd.DataFrame(np.asarray(res))
flag = pd.DataFrame(np.asarray(flag))
result = pd.concat((res, flag), axis=1)
print(res.shape, flag.shape, result.shape)
result.to_csv("label.csv",
              index=False,
              header=[
                  'time', 'acc_x', 'acc_y', 'acc_z', 'gy_x', 'gy_y', 'gy_z',
                  'm_x', 'm_y', 'm_z', 'o_w', 'o_x', 'o_y', 'o_z', 'g_x',
Ejemplo n.º 17
0
    def extract_feats(self, eda_data, file_id=None):
        """
        eda_data is a dict, dict{'data': DataFrame, 'file_id': str, 'category_id': int}
        """
        data = eda_data.to_frame()
        # file_id = eda_data['file_id']
        file_name = osp.splitext(file_id)[0]
        if self.phase != 'test':
            try:
                file_label = int(file_name.split('_')[-2])
            except IndexError:
                print('{}文件命名有误!'.format(file_id))

        data = down_sample(data, interval=cfg.EDA.DOWN_SAMPLE)
        look_back = cfg.EDA.LOOK_BACK
        features_dict = {
            'mean': [],
            'maximum': [],
            'minimum': [],
            'max-min': []
        }

        im_index = 0

        data_fragments = []
        color_list = []

        learn_max_min = []

        num = len(range(0, len(data) - look_back, int(look_back * 0.9)))

        for i in range(0, len(data) - look_back, int(look_back * 0.9)):
            a = data[i:(i + look_back)]
            data_fragments.append(a)
            # 转置(或transpose)之后可能会出现某一维shape为1(如一行转成一列)
            # 因此需要去掉多余维度,否则可能会带来一些切片问题x[np.argmax(x)]越界问题
            # x = a.values.transpose((1, 0))    # 等同于.T
            x = a.values.T
            x = np.squeeze(x)
            feature_dict = {}

            if cfg.EDA.FEATS_MEAN:
                mean = ts_feature.mean(x)
                # mean_change只能按行处理,
                # 内部用的np.diff函数并没有指定axis,
                # 所以只有一列时,np.diff是空,最后得到nan
                mean_change = ts_feature.mean_change(x)
                feature_dict['mean'] = float('%.6f' % mean)
                feature_dict['mean_change'] = float('%.6f' % mean_change)
                features_dict['mean'].append(mean)

            if cfg.EDA.FEATS_MAX_MIN:
                # maximum = ts_feature.maximum(x)
                # minimum = ts_feature.minimum(x)
                max_index = np.argmax(x)
                maximum = x[max_index]
                min_index = np.argmin(x)
                minimum = x[min_index]
                feature_dict['maximum'] = float('%.6f' % maximum)
                feature_dict['minimum'] = float('%.6f' % minimum)
                features_dict['maximum'].append(maximum)
                features_dict['minimum'].append(minimum)
                features_dict['max-min'].append(maximum - minimum)
                if maximum - minimum > 1:
                    if max_index > min_index:
                        color_list.append(1)
                    else:
                        color_list.append(2)
                else:
                    color_list.append(0)

            if cfg.EDA.FEATS_LEARN and im_index < num // 2:
                max_index = np.argmax(x)
                maximum = x[max_index]
                min_index = np.argmin(x)
                minimum = x[min_index]
                learns = []
                for max_min_threshold in np.arange(2., 0., -0.1):
                    if maximum - minimum > max_min_threshold and max_index > min_index:
                        learns.append(1)
                    else:
                        learns.append(0)
                learn_max_min.append(learns)

            if cfg.DRAW.EDA_FRAGMENTS:
                save = osp.join(
                    cfg.DRAW.PATH,
                    'eda/' + file_name + '/' + str(im_index) + '.png')
                draw_dataframe(a,
                               save, ('EDA', ),
                               im_size=(20, 10),
                               show_value=feature_dict)

            im_index += 1

        if cfg.EDA.FEATS_LEARN:
            learn_max_min = np.array(learn_max_min)
            learn_max_min_sum = np.sum(learn_max_min, axis=0)
            position = np.where(learn_max_min_sum > 0)[0]  # 此函数返回的是一个元组
            if self.phase != 'test':
                if file_label == 0:
                    if len(position) > 0:
                        features_dict['unfear_TH'] = 0.1 * (20 - position[0] +
                                                            1)
                    else:
                        features_dict['unfear_TH'] = 0.1
                    features_dict['fear_TH'] = features_dict['unfear_TH'] + 0.2
                else:
                    if len(position) > 0:
                        features_dict['fear_TH'] = 0.1 * (20 - position[0] - 1)
                    else:
                        features_dict['fear_TH'] = 0.3
                    features_dict['unfear_TH'] = features_dict['fear_TH'] - 0.2
                    features_dict['unfear_TH'] = 0.1 \
                        if features_dict['unfear_TH'] < 0.1 \
                        else features_dict['unfear_TH']
                print('{}: {}, fear_TH: {}, unfear_TH: {}'.format(
                    file_id, learn_max_min_sum, features_dict['fear_TH'],
                    features_dict['unfear_TH']))

        if cfg.EDA.STAT_FILES_MEAN:
            mean = ts_feature.mean(data.values)
            if self.phase != 'test':
                if file_label == 1:
                    self.stat_files_mean['fear'].append(mean)
                elif file_label == 0:
                    self.stat_files_mean['nomal'].append(mean)

        if cfg.DRAW.EDA_FEATURES:
            features = pd.DataFrame(features_dict)
            save = osp.join(cfg.DRAW.PATH,
                            'eda/' + file_name + '/' + str(im_index) + '.png')
            draw_dataframe(features,
                           save, ('mean', 'maximum', 'minimum', 'max-min'),
                           im_size=(40, 10))

        if cfg.DRAW.EDA_WHOLE:
            if cfg.EDA.FEATS_MAX_MIN:  # 使用到的color_list是根据此特征计算
                # 使用不同颜色标注片段
                save = osp.join(
                    cfg.DRAW.PATH,
                    'eda/' + file_name + '/' + str(im_index) + '.png')
                draw_dataframe_list(data_fragments,
                                    color_list,
                                    save, ('EDA', ),
                                    im_size=(im_index, 10),
                                    tick_spacing=100)
            save = osp.join(cfg.DRAW.PATH,
                            'eda/' + file_name + '/' + str(im_index) + '.png')
            draw_dataframe(data, save, ('EDA', ), im_size=(im_index, 10))

        for feat in features_dict:
            features_dict[feat] = np.array(features_dict[feat])
        return features_dict
def get_mean(arr):
    res = np.array([mean(arr)])
    res = np.nan_to_num(res)
    return res