def lead_to_sample(): x, y = load_data() x, y, x_test, y_test = utils.split_data(x, y, conf.train_ratio) x = x.reshape(-1, 5000, 1) y = np.repeat(y, 12) print('x.shape,y.shape', x.shape, y.shape) print('x_test.shape,y_test.shape', x_test.shape, y_test.shape) return x, y, x_test, y_test
def train_model(x, y, model_compiled): scores = [] if not conf.ensemble: print(x.shape, y.shape) x_train, y_train, x_test, y_test = utils.split_data( x, y, train_ratio=conf.train_ratio) ''' print(x_train.shape, y_train.shape, x_test.shape, y_test.shape, '\n', y_train, '\n', y_test) if conf.lead_as_sample: x_train = x_train.reshape(-1, 5000, 1) x_test = x_test.reshape(-1, 5000, 1) y_train = np.repeat(y_train, 12) y_test = np.repeat(y_test, 12) ''' print(x_train.shape, y_train.shape, x_test.shape, y_test.shape, '\n', y_train, '\n', y_test) model = model_compiled score = fit_model(x_train, y_train, x_test, y_test, model, 0) print('F1 score of the model: ', score) else: kf = KFold(n_splits=conf.num_model) # sss = StratifiedShuffleSplit(n_splits=conf.num_model,test_size=1-conf.train_ratio, # random_state=conf.seed,) i = 1 for train_index, test_index in kf.split(x, y): print("TRAIN:", train_index, "TEST:", test_index) x_train, x_test = x[train_index], x[test_index] y_train, y_test = y[train_index], y[test_index] print(x_train.shape, y_train.shape, x_test.shape, y_test.shape, y_test) model = model_compiled score = fit_model(x_train, y_train, x_test, y_test, model, i) scores.append(score) i = i + 1 scores = np.array(scores) print('F1 score of all model: ', scores) print('F1 score mean+/-std: ', "%0.3f (+/- %0.3f)" % (np.mean(scores), np.std(scores)))
Epoch 6/20 96/96 [==============================] - 15s - loss: 0.2773 - acc: 0.9167 - val_loss: 0.3014 - val_acc: 0.9286 Epoch 7/20 96/96 [==============================] - 15s - loss: 0.2409 - acc: 0.9167 - val_loss: 0.2914 - val_acc: 0.9286 Epoch 8/20 96/96 [==============================] - 15s - loss: 0.2181 - acc: 0.9375 - val_loss: 0.2629 - val_acc: 0.9286 ''' method = 'hks' x_data, y_data = read_data(descriptor_dir='shrec11-kp', method=method, descriptor_rows=KP_DESCRIPTOR_ROWS, descriptor_cols=KP_DESCRIPTOR_COLS) (train_x, val_x, train_y, val_y) = split_data(x_data, y_data, split_percentage=0.7) train_x = train_x.reshape((-1, KP_UNITS)) val_x = val_x.reshape((-1, KP_UNITS)) mlp_model = MLP(input_units=KP_UNITS, output_units=OUTPUT_UNITS, hidden_layers=(10000, ), activations=('relu', 'softmax')) scores = mlp_model.train(train_x, train_y, val_x, val_y, epochs=12,
@author: danna.li @date: 2019/4/2 @file: train_tradition.py @description: python -W ignore train_tradition.py """ from common.conf import current_config as conf from tradition.extract_feature import get_all_feature import common.utils as utils import tradition.tradition_model as tradition_model import os signals = utils.load_dataset() labels = utils.load_label() all_feature = get_all_feature(signals) x_train, y_train, x_test, y_test = utils.split_data(all_feature, labels, conf.train_ratio) print(x_train.shape, y_train.shape, x_test.shape, y_test.shape) if __name__ == '__main__': utils.re_create_path(conf.output_dir) save_model = False print('fitting knn model..') result_file = os.path.join(conf.output_dir, 'knn01.txt') tradition_model.do_knn(x_train, y_train, x_test, y_test, save_model, result_file) print('fitting svm model..') result_file = os.path.join(conf.output_dir, 'svm01.txt') tradition_model.do_svm(x_train, y_train, x_test, y_test, save_model, result_file)