def test_counting(self): ballots = [ {'Awesome': 2}, {'Slice': 1, 'Awesome': 1}, {'Awesome': 2}, {'Slice': 2}, {'Bluesy': 1}, {} ] winners = cv.run_cv(ballots, 1) self.assertEqual(winners, ['Awesome']) winners = cv.run_cv(ballots, 2) self.assertSetEqual(set(winners), set(['Awesome', 'Slice'])) winners = cv.run_cv(ballots, 3) self.assertSetEqual(set(winners), set(['Awesome', 'Slice', 'Bluesy']))
def test_radio_values(self): ballots = [{ 'Blueberry': 1, 'Strawberry': 0, 'Banana': 0 }, { 'Blueberry': 1, 'Strawberry': 0, 'Banana': 0 }, { 'Blueberry': 1, 'Strawberry': 0, 'Banana': 0 }, { 'Blueberry': 0, 'Strawberry': 1, 'Banana': 0 }, { 'Blueberry': 0, 'Strawberry': 1, 'Banana': 0 }, { 'Blueberry': 0, 'Strawberry': 1, 'Banana': 0 }] winners = cv.run_cv(ballots, 1) self.assertSetEqual(set(winners), set(['Strawberry', 'Blueberry']))
def test_counting(self): ballots = [{ 'Awesome': 2 }, { 'Slice': 1, 'Awesome': 1 }, { 'Awesome': 2 }, { 'Slice': 2 }, { 'Bluesy': 1 }, {}] winners = cv.run_cv(ballots, 1) self.assertEqual(winners, ['Awesome']) winners = cv.run_cv(ballots, 2) self.assertSetEqual(set(winners), set(['Awesome', 'Slice'])) winners = cv.run_cv(ballots, 3) self.assertSetEqual(set(winners), set(['Awesome', 'Slice', 'Bluesy']))
def test_radio_values(self): ballots = [ {'Blueberry': 1, 'Strawberry': 0, 'Banana': 0}, {'Blueberry': 1, 'Strawberry': 0, 'Banana': 0}, {'Blueberry': 1, 'Strawberry': 0, 'Banana': 0}, {'Blueberry': 0, 'Strawberry': 1, 'Banana': 0}, {'Blueberry': 0, 'Strawberry': 1, 'Banana': 0}, {'Blueberry': 0, 'Strawberry': 1, 'Banana': 0} ] winners = cv.run_cv(ballots, 1) self.assertSetEqual(set(winners), set(['Strawberry', 'Blueberry']))
if hasattr(flags, 'cpu') and flags.cpu: os.environ["CUDA_VISIBLE_DEVICES"] = "" elif hasattr(flags, 'gpu') and flags.gpu is not None: os.environ["CUDA_VISIBLE_DEVICES"] = ','.join( str(i) for i in flags.gpu) if flags.command_name == 'train': import training training.run_train(flags) elif flags.command_name == 'test': import testing testing.run_test(flags) elif flags.command_name == 'cv': import cv cv.run_cv(flags) elif flags.command_name == 'plot': import plotting plotting.run_plot(flags) elif flags.command_name == 'new': import util util.run_new(flags) elif flags.command_name == 'explore': import explore explore.run_explore(flags) elif flags.command_name == 'tftest': import tftesting tftesting.run_tftest(flags) else: parser.print_help()
def test_simple_tie(self): ballots = [ {'Awesome': 5, 'Slice': 5} ] winners = cv.run_cv(ballots, 1) self.assertSetEqual(set(winners), set(['Awesome', 'Slice']))
def test_simple(self): ballots = [ {'Awesome': 5} ] winners = cv.run_cv(ballots, 1) self.assertEqual(winners, ['Awesome'])
def test_empty(self): for ballots in [[], [{}, {}]]: winners = cv.run_cv(ballots, 2) self.assertEqual(winners, [])
def test_simple_tie(self): ballots = [{'Awesome': 5, 'Slice': 5}] winners = cv.run_cv(ballots, 1) self.assertSetEqual(set(winners), set(['Awesome', 'Slice']))
def test_simple(self): ballots = [{'Awesome': 5}] winners = cv.run_cv(ballots, 1) self.assertEqual(winners, ['Awesome'])
def main(): if len(sys.argv) - 1 < NUM_REQ_ARGS: print(REQ_MESSAGE) return model_name = str(sys.argv[1]) data_path = str(sys.argv[2]) pickle_path = str(sys.argv[3]) num_folds = None if model_name not in AVAILABLE_MODELS: print("Unrecognized model: ", model_name, "\nAvailable models are", ", ".join(AVAILABLE_MODELS)) return model_class = getattr(sys.modules[__name__], model_name) labels = model_class.supervised if labels: if len(sys.argv) - 1 < NUM_REQ_ARGS + 1: print(REQ_MESSAGE) return num_folds = int(sys.argv[NUM_REQ_ARGS + 1]) hyperparam_df = model_class.hyperparam_df hyperparam_df = get_hyperparam_selections(hyperparam_df) data = shuffle(pandas.read_csv(data_path)) while True: reducer = input("Select dimensionality reducer from the list: " + ", ".join(AVAILABLE_DIM_REDUCERS) + " or press enter to skip: ") if reducer and str(reducer) in AVAILABLE_DIM_REDUCERS: reducer_class = getattr(sys.modules[__name__], reducer) reducer_hdf = get_hyperparam_selections(reducer_class.recuder_hdf) model=model_class(hyperparam_df, reducer_class, reducer_hdf) break elif not reducer: # they don't want to set a reducer model=model_class(hyperparam_df, None, None) break data = model.encode_categorical(data) if labels: print("Using column '"+ str(data.columns[-1]) + "' as labels.\n") data_y = data.iloc[:,-1].values.tolist() data.drop(data.columns[[-1]], axis=1, inplace=True) data_X = data.values.tolist() if num_folds > 0: cv.run_cv(data_X, num_folds, data_y, len(set(data_y)), model) model.fit((data_X, data_y)) # the final model to be saved else: if data.columns[-1].lower() == 'class': data.drop(data.columns[[-1]], axis=1, inplace=True) data_X = data.values.tolist() model.fit(data_X) pickle.dump(model, open(pickle_path, "wb" ))