Example #1
0
def moments_features(path):
    if not os.path.exists(path):
        logger.error(path + " is not exist!")
        return
    im = cv2.imread(path)
    [b, g, r] = cv2.split(im)
    moments = []
    for n in [b, g, r]:
        df = DataFrame(np.array(n.flatten()))
        moments.extend(float(x) for x in [df.mean()[0], df.std()[0], df.skew()[0]])
    return moments
    def test_skew(self):
        from scipy.stats import skew

        string_series = tm.makeStringSeries().rename('series')

        alt = lambda x: skew(x, bias=False)
        self._check_stat_op('skew', alt, string_series)

        # test corner cases, skew() returns NaN unless there's at least 3
        # values
        min_N = 3
        for i in range(1, min_N + 1):
            s = Series(np.ones(i))
            df = DataFrame(np.ones((i, i)))
            if i < min_N:
                assert np.isnan(s.skew())
                assert np.isnan(df.skew()).all()
            else:
                assert 0 == s.skew()
                assert (df.skew() == 0).all()
Example #3
0
def filedata(filename):
    f=open(filename,'r')
    eigen_list = []
    Act_fact = []
    for line in f.readlines():
        line=line.strip().split(" ")
        if '#' in line[0]:
            print(' ')
        else:
            AccXYZ =[[],[],[]]
            Acc = line[-1].split("*")
            for Accxyz in Acc:
                Accxyz=Accxyz.split(",")
                if len(Accxyz) == 3:
                    AccXYZ[0].append(float(Accxyz[0]))
                    AccXYZ[1].append(float(Accxyz[1]))
                    AccXYZ[2].append(float(Accxyz[2]))
            AccXYZ = np.array(AccXYZ)
            num = float(AccXYZ.shape[1])
            df = DataFrame(AccXYZ)
            skew = df.skew(1) #偏度
            kurt = df.kurt(1) #峰度
            mean = AccXYZ.mean(1)#均值
            std = AccXYZ.std(1)#标准差
            fft = np.fft.fft(AccXYZ)#傅里叶
            pass_mean = passmean(AccXYZ,mean)/num#均值穿越次数
            eigen_choose1 = np.append(np.array(skew),np.array(kurt))
            eigen_choose2= np.append(mean,pass_mean)
            eigen_choose3= np.append(std,pow(abs(fft),2).sum(1)/num)
            eigen_choose12 = np.append(eigen_choose1,eigen_choose2)
            eigen_choose = np.append(eigen_choose12,eigen_choose3)
        if  'ACT' in line[0] :
            Act = line[-1].split(",")
            eigen_choose = np.append(eigen_choose,int(Act[-1]))
            eigen_list.append(list(eigen_choose))
    f.close()
    eigen_fact_matrix = avg_data(eigen_list)
    return eigen_fact_matrix