# print "%s score : %f" % (m_classifiers_name_it, m_cross_validation_score[m_classifiers_name_it]) print "training classifiers:" TraininAllClassifiers(m_classifiers, train_data, train_label, train_data, train_label) save_classifiers(m_classifiers) ########################################### ###### preditct and show the result ####### ########################################### try: notexist predict_res except NameError: print "testing in real test data:" predict_res = PrediectinAllClassifiers(m_classifiers, test_data) else: print "Predict has been extracted!" m_predictMode = ModethePredict(test_data, predict_res) PlotPredictRes(m_predictMode, 'MODE') df = pd.DataFrame(m_predictMode) df = df.T df.to_csv("../prefile.txt", sep=' ', index=False, header=False) # save center and scalar to file m_cent = m_normalizer.robust_scaler.center_ m_scal = m_normalizer.robust_scaler.scale_ m_cent = pd.DataFrame(m_cent) m_scal = pd.DataFrame(m_scal) m_cent.to_csv("../center.txt", sep=' ', index=False, header=False)
train_data, test_data, train_label, test_label = cross_validation.train_test_split( train_data, train_label, test_size=0.1) print "training classifiers:" TraininAllClassifiers(train_data, train_label, test_data, test_label) ########################################### ###### preditct and show the result ####### ########################################### test_naivedata = featureOf_TestinTrain try: notexist predictRes except NameError: print "testing in train data:" predictRes = PrediectinAllClassifiers(test_naivedata) else: print "Predict has been extracted!" m_predictMode = ModethePredict(test_naivedata, predictRes) PlotTestSeqandPredictRes( m_normalized_traindata.loc[121200:149000]['accelerometerX'], m_predictMode, 'MODE') a = m_predictMode test_realdata = featureOf_TestinReal try: notexist predictResinReal except NameError: print "testing in real test data:" predictResinReal = PrediectinAllClassifiers(test_realdata) else:
train_data = train_data.append(featureOf_Train[i].loc[j]) train_label.append(label_numlabel[label_name[i]]) ########################################### ############# normalize data ############## ########################################### print "normalize feature:" m_normalizer = processingFeature.Normalizer("robust", train_data) train_data = m_normalizer.normalizer(train_data) featureOf_TestinReal = m_normalizer.normalizer(featureOf_TestinReal) print "PCA feature:" m_pcaor = processingFeature.PCAor("normal", train_data, 50) train_data = m_pcaor.pcaor(train_data) featureOf_TestinReal = m_pcaor.pcaor(featureOf_TestinReal) train_data, test_data, train_label, test_label = cross_validation.train_test_split( train_data, train_label, test_size=0.1) m_classifiers = load_classifiers() ########################################### ###### preditct and show the result ####### ########################################### test_realdata = featureOf_TestinReal predictResinReal = PrediectinAllClassifiers(m_classifiers, test_realdata) m_predictMode = ModethePredict(test_realdata, predictResinReal) PlotTestSeqandPredictRes(m_normalized_testdata['accelerometerX'], m_predictMode, 'MODE') df = pd.DataFrame(m_predictMode) df = df.T df.to_csv("../prefile", index=False, header=False)
train_data, test_data, train_label, test_label = cross_validation.train_test_split( train_data, train_label, test_size=0.5) TraininAllClassifiers(train_data, train_label, test_data, test_label) ########################################### ###### preditct and show the result ####### ########################################### # no need to reshape test data and predict test_data = featureOfTest try: #notexist predictRes except NameError: predictRes = PrediectinAllClassifiers(test_data) else: print "Predict has been extracted!" # get the mode of different classifiers, present a vote function def ModethePredict(): from scipy.stats import mode predictMode = [] for i in range(len(test_data)): predictMode.append( mode([ #predictRes['LR'][i], predictRes['KNN'] [i], #predictRes['KNN'][i],predictRes['KNN'][i], predictRes['RF'][i], predictRes['GBDT'][i]
for i in range(len(test_data)): predictMode.append( mode([ #predictRes['LR'][i], predictRes['KNN'] [i], #predictRes['KNN'][i],predictRes['KNN'][i], predictRes['RF'][i], predictRes['GBDT'][i] #,predictRes['GBDT'][i] ])[0][0]) return predictMode try: notexist predictRes except NameError: predictRes = PrediectinAllClassifiers(test_naivedata) else: print "Predict has been extracted!" m_predictMode = ModethePredict(test_naivedata, predictRes) PlotTestSeqandPredictRes( m_normalized_traindata.loc[121200:149000]['accelerometerX'], m_predictMode, 'MODE') try: notexist predictResinReal except NameError: print "testing in real test data:" predictResinReal = PrediectinAllClassifiers(test_realdata) else: print "Predict has been extracted!"