# -*- coding: utf-8 -*-
#!/usr/bin/python

from featureExtractMethods.feature_compose import featureCompose
from featureExtractMethods.featureSelect import featureSelByRf
from featureExtractMethods.classsifierModel import classifierRF
from featureExtractMethods.getfea import getNewFeat
import numpy as np
import pickle
import os

#运行该文件前，请提前运行gmain_opcode(),feature_extract.sh

#选择特征
fsel = featureCompose()

def featTransform(olist,mname):
    X, T = fsel.getUserSelectFeature(olist)
    # 特征压缩

    # 保存特征的文件路径
    filePath_train = 'featfile\\train_' + mname + '_RF' + '.p'
    filePath_test = 'featfile\\test_' + mname + '_RF' + '.p'
    featureSelByRf(X, T, filePath_train, filePath_test)
    print('DONE Feature Select!')
    del X,T

##############################################
mname0 = 'opghead'
if not os.path.exists('featfile//train_'+mname0 + '_RF.p'):
    featTransform([6,7],mname0)

mname2 = 'opgram'
if not os.path.exists('featfile//train_'+mname2 + '_RF.p'):
    featTransform([6],mname2)

###############################################
selfeatlist = fsel.featSelectForUser()

bbret = False
if 6 in selfeatlist:
    bbret=True
    if 7 in selfeatlist:
        # 新特征读入
        train_ophg = getNewFeat([mname0], ['RF'], 'train', )
        test_ophg = getNewFeat([mname0], ['RF'], 'test', )
    else:
        # 新特征读入
        train_ophg = getNewFeat([mname2], ['RF'], 'train', )
        test_ophg = getNewFeat([mname2], ['RF'], 'test', )
if 7 in selfeatlist and 6 not in selfeatlist:
    blist=[7]
else:
    blist=[]
blist.extend([i for i in selfeatlist if i != 6 and i != 7])
if len(blist)>0:
    train_t, test_t = fsel.getUserSelectFeature(selfeatlist)
    if bbret:
        train_x = np.hstack((train_t,train_ophg))
        test_x = np.hstack((test_t,test_ophg))
    else:
        train_x = train_t
        test_x = test_t
else:
    train_x = train_ophg
    test_x = test_ophg

#数据集类别信息载入
train_y = np.array(pickle.load(open('y.p','rb')))
test_y=np.array(pickle.load(open('yt.p','rb')))

#分类
classifierRF(train_x,train_y,test_x,test_y)


70677966004e4dd438c5a3a8313c7bd22dc76070
<mask token>


def featTransform(olist, mname):
    X, T = fsel.getUserSelectFeature(olist)
    filePath_train = 'featfile\\train_' + mname + '_RF' + '.p'
    filePath_test = 'featfile\\test_' + mname + '_RF' + '.p'
    featureSelByRf(X, T, filePath_train, filePath_test)
    print('DONE Feature Select!')
    del X, T


<mask token>

<mask token>


def featTransform(olist, mname):
    X, T = fsel.getUserSelectFeature(olist)
    filePath_train = 'featfile\\train_' + mname + '_RF' + '.p'
    filePath_test = 'featfile\\test_' + mname + '_RF' + '.p'
    featureSelByRf(X, T, filePath_train, filePath_test)
    print('DONE Feature Select!')
    del X, T


<mask token>
if not os.path.exists('featfile//train_' + mname0 + '_RF.p'):
    featTransform([6, 7], mname0)
<mask token>
if not os.path.exists('featfile//train_' + mname2 + '_RF.p'):
    featTransform([6], mname2)
<mask token>
if 6 in selfeatlist:
    bbret = True
    if 7 in selfeatlist:
        train_ophg = getNewFeat([mname0], ['RF'], 'train')
        test_ophg = getNewFeat([mname0], ['RF'], 'test')
    else:
        train_ophg = getNewFeat([mname2], ['RF'], 'train')
        test_ophg = getNewFeat([mname2], ['RF'], 'test')
if 7 in selfeatlist and 6 not in selfeatlist:
    blist = [7]
else:
    blist = []
blist.extend([i for i in selfeatlist if i != 6 and i != 7])
if len(blist) > 0:
    train_t, test_t = fsel.getUserSelectFeature(selfeatlist)
    if bbret:
        train_x = np.hstack((train_t, train_ophg))
        test_x = np.hstack((test_t, test_ophg))
    else:
        train_x = train_t
        test_x = test_t
else:
    train_x = train_ophg
    test_x = test_ophg
<mask token>
classifierRF(train_x, train_y, test_x, test_y)

<mask token>
fsel = featureCompose()


def featTransform(olist, mname):
    X, T = fsel.getUserSelectFeature(olist)
    filePath_train = 'featfile\\train_' + mname + '_RF' + '.p'
    filePath_test = 'featfile\\test_' + mname + '_RF' + '.p'
    featureSelByRf(X, T, filePath_train, filePath_test)
    print('DONE Feature Select!')
    del X, T


mname0 = 'opghead'
if not os.path.exists('featfile//train_' + mname0 + '_RF.p'):
    featTransform([6, 7], mname0)
mname2 = 'opgram'
if not os.path.exists('featfile//train_' + mname2 + '_RF.p'):
    featTransform([6], mname2)
selfeatlist = fsel.featSelectForUser()
bbret = False
if 6 in selfeatlist:
    bbret = True
    if 7 in selfeatlist:
        train_ophg = getNewFeat([mname0], ['RF'], 'train')
        test_ophg = getNewFeat([mname0], ['RF'], 'test')
    else:
        train_ophg = getNewFeat([mname2], ['RF'], 'train')
        test_ophg = getNewFeat([mname2], ['RF'], 'test')
if 7 in selfeatlist and 6 not in selfeatlist:
    blist = [7]
else:
    blist = []
blist.extend([i for i in selfeatlist if i != 6 and i != 7])
if len(blist) > 0:
    train_t, test_t = fsel.getUserSelectFeature(selfeatlist)
    if bbret:
        train_x = np.hstack((train_t, train_ophg))
        test_x = np.hstack((test_t, test_ophg))
    else:
        train_x = train_t
        test_x = test_t
else:
    train_x = train_ophg
    test_x = test_ophg
train_y = np.array(pickle.load(open('y.p', 'rb')))
test_y = np.array(pickle.load(open('yt.p', 'rb')))
classifierRF(train_x, train_y, test_x, test_y)

from featureExtractMethods.feature_compose import featureCompose
from featureExtractMethods.featureSelect import featureSelByRf
from featureExtractMethods.classsifierModel import classifierRF
from featureExtractMethods.getfea import getNewFeat
import numpy as np
import pickle
import os
fsel = featureCompose()


def featTransform(olist, mname):
    X, T = fsel.getUserSelectFeature(olist)
    filePath_train = 'featfile\\train_' + mname + '_RF' + '.p'
    filePath_test = 'featfile\\test_' + mname + '_RF' + '.p'
    featureSelByRf(X, T, filePath_train, filePath_test)
    print('DONE Feature Select!')
    del X, T


mname0 = 'opghead'
if not os.path.exists('featfile//train_' + mname0 + '_RF.p'):
    featTransform([6, 7], mname0)
mname2 = 'opgram'
if not os.path.exists('featfile//train_' + mname2 + '_RF.p'):
    featTransform([6], mname2)
selfeatlist = fsel.featSelectForUser()
bbret = False
if 6 in selfeatlist:
    bbret = True
    if 7 in selfeatlist:
        train_ophg = getNewFeat([mname0], ['RF'], 'train')
        test_ophg = getNewFeat([mname0], ['RF'], 'test')
    else:
        train_ophg = getNewFeat([mname2], ['RF'], 'train')
        test_ophg = getNewFeat([mname2], ['RF'], 'test')
if 7 in selfeatlist and 6 not in selfeatlist:
    blist = [7]
else:
    blist = []
blist.extend([i for i in selfeatlist if i != 6 and i != 7])
if len(blist) > 0:
    train_t, test_t = fsel.getUserSelectFeature(selfeatlist)
    if bbret:
        train_x = np.hstack((train_t, train_ophg))
        test_x = np.hstack((test_t, test_ophg))
    else:
        train_x = train_t
        test_x = test_t
else:
    train_x = train_ophg
    test_x = test_ophg
train_y = np.array(pickle.load(open('y.p', 'rb')))
test_y = np.array(pickle.load(open('yt.p', 'rb')))
classifierRF(train_x, train_y, test_x, test_y)

# -*- coding: utf-8 -*-
#!/usr/bin/python

from featureExtractMethods.feature_compose import featureCompose
from featureExtractMethods.featureSelect import featureSelByRf
from featureExtractMethods.classsifierModel import classifierRF
from featureExtractMethods.getfea import getNewFeat
import numpy as np
import pickle
import os

#运行该文件前，请提前运行gmain_opcode(),feature_extract.sh

#选择特征
fsel = featureCompose()

def featTransform(olist,mname):
    X, T = fsel.getUserSelectFeature(olist)
    # 特征压缩

    # 保存特征的文件路径
    filePath_train = 'featfile\\train_' + mname + '_RF' + '.p'
    filePath_test = 'featfile\\test_' + mname + '_RF' + '.p'
    featureSelByRf(X, T, filePath_train, filePath_test)
    print('DONE Feature Select!')
    del X,T

##############################################
mname0 = 'opghead'
if not os.path.exists('featfile//train_'+mname0 + '_RF.p'):
    featTransform([6,7],mname0)

mname2 = 'opgram'
if not os.path.exists('featfile//train_'+mname2 + '_RF.p'):
    featTransform([6],mname2)

###############################################
selfeatlist = fsel.featSelectForUser()

bbret = False
if 6 in selfeatlist:
    bbret=True
    if 7 in selfeatlist:
        # 新特征读入
        train_ophg = getNewFeat([mname0], ['RF'], 'train', )
        test_ophg = getNewFeat([mname0], ['RF'], 'test', )
    else:
        # 新特征读入
        train_ophg = getNewFeat([mname2], ['RF'], 'train', )
        test_ophg = getNewFeat([mname2], ['RF'], 'test', )
if 7 in selfeatlist and 6 not in selfeatlist:
    blist=[7]
else:
    blist=[]
blist.extend([i for i in selfeatlist if i != 6 and i != 7])
if len(blist)>0:
    train_t, test_t = fsel.getUserSelectFeature(selfeatlist)
    if bbret:
        train_x = np.hstack((train_t,train_ophg))
        test_x = np.hstack((test_t,test_ophg))
    else:
        train_x = train_t
        test_x = test_t
else:
    train_x = train_ophg
    test_x = test_ophg

#数据集类别信息载入
train_y = np.array(pickle.load(open('y.p','rb')))
test_y=np.array(pickle.load(open('yt.p','rb')))

#分类
classifierRF(train_x,train_y,test_x,test_y)

