def main(): CID = opts.cluster if (opts.load != 'none'): CID = opts.load X_train, X_test, Y_train, Y_test, X, X2, X3, enc = f.get_data_pro( testsize=0.4) test_accues = [] for n in range(1, 5): model, history = md.bulid_model_nconv(X_train, X_test, Y_train, Y_test, X, X2, X3, CID, fromfile=opts.load, n_dense=n) test_accues.append(history.history['val_acc'][-1]) print() print(test_accues) # newData = X_test.reshape(X_test.shape[0], 1, 100, 20) # Y_score = model.predict_proba(X_test) # roc.roc_plot( # Y_test, Y_score, 2, filepath=os.path.join('figures', CID + opts.title + 'roc.svg'),fmt='svg',title=opts.title) # Y_de = decode_y(Y_test, features=enc.active_features_) # Y_pred = model.predict(X_test) # Y_depred = decode_y(Y_pred, features=enc.active_features_) # print(classification_report(Y_de, Y_depred)) return
def main(): CID = opts.cluster if (opts.load != 'none'): CID = opts.load X_train, X_test, Y_train, Y_test, X, X2, X3, enc = f.get_data_pro( testsize=0.2) model = bulid_model(X_train, X_test, Y_train, Y_test, X, X2, X3, CID, fromfile=opts.load) newData = X_test.reshape(X_test.shape[0], 1, 100, 20) Y_score = model.predict_proba(X_test) roc.roc_plot(Y_test, Y_score, 2, filepath=os.path.join('figures', CID + opts.title + 'roc.svg'), fmt='svg', title=opts.title) Y_de = decode_y(Y_test, features=enc.active_features_) Y_pred = model.predict(X_test) Y_depred = decode_y(Y_pred, features=enc.active_features_) print(classification_report(Y_de, Y_depred)) return
def main(): CID = opts.cluster if (opts.load != 'none'): CID = opts.load X_train, X_test, Y_train, Y_test, X, X2, X3, enc = f.get_data_pro( testsize=0) X_shape = X_train.shape X_holder = np.zeros(X_shape[0]) Y_inv = decode_y(Y_train) print(X_shape) skf = StratifiedKFold(n_splits=10) skf.get_n_splits(X_train, Y_inv) accues = [] aucs = [] for train_index, test_index in skf.split(X_train, Y_inv): print("TRAIN:", train_index, "TEST:", test_index) x_train, x_test = X_train[train_index], X_train[test_index] y_train, y_test = Y_train[train_index], Y_train[test_index] model = bulid_model(x_train, x_test, y_train, y_test, X, X2, X3, CID, fromfile=opts.load) Y_de = decode_y(y_test, features=enc.active_features_) Y_pred = model.predict(x_test) Y_score = model.predict_proba(x_test) fpr, tpr, th = roc_curve(Y_de, Y_score[:, 1]) Y_depred = decode_y(Y_pred, features=enc.active_features_) accues.append(accuracy_score(Y_depred, Y_de)) aucs.append(auc(fpr, tpr)) print("###########################") print(accues) print(aucs) # model, history = bulid_model( # X_train, X_test, Y_train, Y_test, X, X2, X3, CID, fromfile=opts.load) # #newData = X_test.reshape(X_test.shape[0], 1, 100, 20) # Y_score = model.predict_proba(X_test) # roc.roc_plot( # Y_test, # Y_score, # 2, # filepath=os.path.join('figures', CID + opts.title + 'roc.svg'), # fmt='svg', # title=opts.title) # plt.close() # print(history.history.keys()) # # summarize history for accuracy # plt.plot(history.history['acc']) # plt.plot(history.history['val_acc']) # plt.title('model accuracy') # plt.ylabel('accuracy') # plt.xlabel('epoch') # plt.legend(['train', 'test'], loc='upper left') # plt.savefig(os.path.join('figures', CID + opts.title + 'learning-c.svg'),format='svg') # plt.close() #Y_de = decode_y(Y_test, features=enc.active_features_) #Y_pred = model.predict(X_test) #Y_depred = decode_y(Y_pred, features=enc.active_features_) #print(classification_report(Y_de, Y_depred)) return
def main(): CID = opts.cluster if (opts.load != 'none'): CID = opts.load X_train, X_test, Y_train, Y_test, X, X2, X3, enc = f.get_data_pro( testsize=0.4) Y_inv = decode_y(Y_train) Y_de_test = decode_y(Y_test) ranges = np.linspace(.1, 1.0, 10) test_accues = [] test_aucs = [] tt_acu_max = [] tt_acu_min = [] train_accues = [] train_aucs = [] tn_acu_max = [] tn_acu_min = [] for size in ranges: x_train, x_placeholder, y_train, y_placeholder = train_test_split( X_train, Y_train, test_size=1 - size, random_state=0) #skf = StratifiedKFold(n_splits=10) y_train_dec = decode_y(y_train, features=enc.active_features_) model, history = bulid_model(x_train, X_test, y_train, Y_test, X, X2, X3, CID, fromfile=opts.load) print('Poportion value') print(history.history['val_acc'][-1]) print(history.history['acc'][-1]) #skf.get_n_splits(x_train, y_train_dec) #accues = [] #aucs = [] Y_pred = model.predict(X_test) Y_score = model.predict_proba(X_test) Y_t_pred = model.predict(X_train) Y_t_score = model.predict_proba(X_train) fpr, tpr, thplaceholder = roc_curve(Y_de_test, Y_score[:, 1]) Y_depred = decode_y(Y_pred, features=enc.active_features_) fpr_t, tpr_t, thplaceholder2 = roc_curve(Y_inv, Y_t_score[:, 1]) Y_t_depred = decode_y(Y_t_pred, features=enc.active_features_) test_accues.append(history.history['val_acc'][-1]) tt_acu_max.append(np.max(history.history['val_acc'])) tt_acu_min.append(np.min(history.history['val_acc'])) train_accues.append(history.history['acc'][-1]) tn_acu_max.append(np.max(history.history['acc'])) tn_acu_min.append(np.min(history.history['acc'])) train_aucs.append(auc(fpr_t, tpr_t)) test_aucs.append(auc(fpr, tpr)) print("###########################") print(test_accues) print(test_aucs) print(train_accues) print(train_aucs) print(classification_report(Y_de_test, Y_depred)) plt.figure() plt.title("Learning cuvre to the model") plt.xlabel("Training sample fraction") plt.ylabel("Scores") plt.grid() plt.plot(np.linspace(.1, 1.0, 10), train_accues, 'o-', label="Training accurarcy") plt.fill_between(np.linspace(.1, 1.0, 10), tn_acu_min, tn_acu_max, alpha=0.1) #plt.plot(np.linspace(.1, 1.0, 10),train_aucs,'o-',label="Training auc") plt.plot(np.linspace(.1, 1.0, 10), test_accues, 'o-', label="Testing accurarcy") plt.fill_between(np.linspace(.1, 1.0, 10), tt_acu_min, tt_acu_max, alpha=0.1) #plt.plot(np.linspace(.1, 1.0, 10),test_aucs,'o-',label="Testing auc") plt.legend(loc="best") plt.savefig(os.path.join('figures', CID + opts.title + 'learning_curve.svg'), format='svg') plt.close() # model, history = bulid_model( # X_train, X_test, Y_train, Y_test, X, X2, X3, CID, fromfile=opts.load) # #newData = X_test.reshape(X_test.shape[0], 1, 100, 20) # Y_score = model.predict_proba(X_test) # roc.roc_plot( # Y_test, # Y_score, # 2, # filepath=os.path.join('figures', CID + opts.title + 'roc.svg'), # fmt='svg', # title=opts.title) # plt.close() # print(history.history.keys()) # # summarize history for accuracy # plt.plot(history.history['acc']) # plt.plot(history.history['val_acc']) # plt.title('model accuracy') # plt.ylabel('accuracy') # plt.xlabel('epoch') # plt.legend(['train', 'test'], loc='upper left') # plt.savefig(os.path.join('figures', CID + opts.title + 'learning-c.svg'),format='svg') # plt.close() #Y_de = decode_y(Y_test, features=enc.active_features_) #Y_pred = model.predict(X_test) #Y_depred = decode_y(Y_pred, features=enc.active_features_) #print(classification_report(Y_de, Y_depred)) return