def run_pam(args): set_global_seeds(args['seed']) dataset = DataLoader(args['dataset']) X_train, X_test, X_val, y_train, y_test, y_val = dataset.prepare_train_test_val( args) model = Perceptron(feature_dim=X_train.shape[-1], margin=args['margin']) model.fit(X_train, y_train) return model.score(X_test, y_test)
def find_best_margin(args): """ return `best_margin / 0.1` """ set_global_seeds(args['seed']) dataset = DataLoader(args['dataset']) X_train, X_test, X_val, y_train, y_test, y_val = dataset.prepare_train_test_val( args) results = [] for margin in MARGINS: model = Perceptron(feature_dim=X_train.shape[-1], margin=margin) model.fit(X_train, y_train) results.append(model.score(X_val, y_val)) return results