コード例 #1
0
ファイル: learn_model.py プロジェクト: jiejiang/quest
def run(config):
    '''
    Runs the main code of the program. Checks for mandatory parameters, opens
    input files and performs the learning steps.
    '''
    # check if the mandatory parameters are set in the config file
    x_train_path = config.get("x_train", None)
    if not x_train_path:
        msg = "'x_train' option not found in the configuration file. \
        The training dataset is mandatory."
        raise Exception(msg)

    y_train_path = config.get("y_train", None)
    if not y_train_path:
        msg = "'y_train' option not found in the configuration file. \
        The training dataset is mandatory."
        raise Exception(msg)
        
    learning = config.get("learning", None)
    if not learning:
        msg = "'learning' option not found. At least one \
        learning method must be set."
        raise Exception(msg)
    
    # checks for the optional parameters
    x_test_path = config.get("x_test", None)
    y_test_path = config.get("y_test", None)

    separator = config.get("separator", DEFAULT_SEP)
    
    labels_path = config.get("labels", None)
        
    scale = config.get("scale", True)

    log.info("Opening input files ...")
    log.debug("X_train: %s" % x_train_path)
    log.debug("y_train: %s" % y_train_path)
    log.debug("X_test: %s" % x_test_path)
    log.debug("y_test_path: %s" % y_test_path)

    # open feature and response files    
    X_train, y_train, X_test, y_test, labels = \
    open_datasets(x_train_path, y_train_path, x_test_path,
                  y_test_path, separator, labels_path)

    X_eval = None
    x_eval_path = config.get("eval_input", None)
    if x_eval_path:
        X_eval = open_eval_datasets(x_eval_path, separator, X_train.shape[1])

    if scale:
        # preprocess and execute mean removal
        if X_eval is None:
            X_train, X_test = scale_datasets(X_train, X_test)
        else:
            X_train, X_test, X_eval = scale_datasets_with_eval(X_train, X_test, X_eval)

    # fits training data and predicts the test set using the trained model
    y_hat = fit_predict(config, X_train, y_train, X_test, y_test, config.get("ref_thd", None),
                        X_eval=X_eval, eval_output=config.get("eval_output", None), eval_threshold=config.get("eval_threshold", None))
コード例 #2
0
def run(config):
    '''
    Runs the main code of the program. Checks for mandatory parameters, opens
    input files and performs the learning steps.
    '''
    # check if the mandatory parameters are set in the config file
    x_train_path = config.get("x_train", None)
    if not x_train_path:
        msg = "'x_train' option not found in the configuration file. \
        The training dataset is mandatory."

        raise Exception(msg)

    y_train_path = config.get("y_train", None)
    if not y_train_path:
        msg = "'y_train' option not found in the configuration file. \
        The training dataset is mandatory."

        raise Exception(msg)

    learning = config.get("learning", None)
    if not learning:
        msg = "'learning' option not found. At least one \
        learning method must be set."

        raise Exception(msg)

    # checks for the optional parameters
    x_test_path = config.get("x_test", None)
    y_test_path = config.get("y_test", None)

    separator = config.get("separator", DEFAULT_SEP)

    labels_path = config.get("labels", None)

    scale = config.get("scale", True)

    log.info("Opening input files ...")
    log.debug("X_train: %s" % x_train_path)
    log.debug("y_train: %s" % y_train_path)
    log.debug("X_test: %s" % x_test_path)
    log.debug("y_test_path: %s" % y_test_path)

    # open feature and response files
    X_train, y_train, X_test, y_test, labels = \
    open_datasets(x_train_path, y_train_path, x_test_path,
                  y_test_path, separator, labels_path)

    if scale:
        # preprocess and execute mean removal
        X_train, X_test = scale_datasets(X_train, X_test)

    # fits training data and predicts the test set using the trained model
    y_hat = fit_predict(config, X_train, y_train, X_test, y_test,
                        config.get("ref_thd", None))
コード例 #3
0
ファイル: learn_model.py プロジェクト: zouharvi/ptakopet-old
def run(config):
    '''
    Runs the main code of the program. Checks for mandatory parameters, opens
    input files and performs the learning steps.
    '''

    # check if the mandatory parameters are set in the config file
    x_train_path = config.get("x_train")
    y_train_path = config.get("y_train")
    learning = config.get("learning")
    assert x_train_path
    assert y_train_path
    assert learning

    # checks for the optional parameters
    x_test_path = config.get("x_test", None)
    y_test_path = config.get("y_test", None)

    separator = config.get("separator", '\t')
    labels_path = config.get("labels", None)

    scale = config.get("scale", True)

    print("Opening input files ...")
    print("X_train: %s" % x_train_path)
    print("y_train: %s" % y_train_path)
    print("X_test: %s" % x_test_path)
    print("y_test_path: %s" % y_test_path)

    # open feature and response files
    X_train, y_train, X_test, y_test, labels = \
    open_datasets(x_train_path, y_train_path, x_test_path,
                  y_test_path, separator, labels_path)

    if scale:
        # preprocess and execute mean removal
        X_train, X_test = scale_datasets(X_train, X_test)

    # fits training data and predicts the test set using the trained model
    y_hat = fit_predict(config, X_train, y_train, X_test, y_test)
コード例 #4
0
def run(config):
	'''
	Runs the main code of the program. Checks for mandatory parameters, opens
	input files and performs the learning steps.
	'''
	# check if the mandatory parameters are set in the config file
	x_train_path = config.get("x_train", None)
	if not x_train_path:
		msg = "'x_train' option not found in the configuration file. \
		The training dataset is mandatory."
		raise Exception(msg)

	y_train_path = config.get("y_train", None)
	if not y_train_path:
		msg = "'y_train' option not found in the configuration file. \
		The training dataset is mandatory."
		raise Exception(msg)
		
	learning = config.get("learning", None)
	if not learning:
		msg = "'learning' option not found. At least one \
		learning method must be set."
		raise Exception(msg)
	
	# checks for the optional parameters
	x_test_path = config.get("x_test", None)
	y_test_path = config.get("y_test", None)

	separator = config.get("separator", DEFAULT_SEP)
	
	labels_path = config.get("labels", None)

	log.info("Opening input files ...")

	# open feature and response files
	X_train, y_train, X_test, y_test, labels = open_datasets(x_train_path, y_train_path, x_test_path, y_test_path, separator, labels_path, tostring=True)
	log.info("Opened input files.")

	# fits training data and predicts the test set using the trained model
	y_hat = fit_predict(config, X_train, y_train, X_test, y_test, config.get("ref_thd", None))
コード例 #5
0
def run(config):
    '''
    Runs the main code of the program. Checks for mandatory parameters, opens
    input files and performs the learning steps.
    '''
    # check if the mandatory parameters are set in the config file
    x_train_path = config.get("x_train", None)
    if not x_train_path:
        msg = "'x_train' option not found in the configuration file. \
        The training dataset is mandatory."
        raise Exception(msg)

    y_train_path = config.get("y_train", None)
    if not y_train_path:
        msg = "'y_train' option not found in the configuration file. \
        The training dataset is mandatory."
        raise Exception(msg)
        
    learning = config.get("learning", None)
    if not learning:
        msg = "'learning' option not found. At least one \
        learning method must be set."
        raise Exception(msg)
    
    # checks for the optional parameters
    x_test_path = config.get("x_test", None)
    y_test_path = config.get("y_test", None)

    # output file
    output_file_path = config.get("output", None)

    separator = config.get("separator", DEFAULT_SEP)
    
    labels_path = config.get("labels", None)
        
    scale = config.get("scale", True)

    log.debug("Opening input files ...")
    log.debug("X_train: %s" % x_train_path)
    log.debug("y_train: %s" % y_train_path)
    log.debug("X_test: %s" % x_test_path)
    log.debug("y_test_path: %s" % y_test_path)
    
    
    # open feature and response files    
    X_train, y_train, X_test, y_test, labels = \
    open_datasets(x_train_path, y_train_path, x_test_path,
                  y_test_path, separator, labels_path)

    if scale:
        # preprocess and execute mean removal
        X_train, X_test = scale_datasets(X_train, X_test)

    
    predict_only = config.get("predict_only", False)
    if predict_only:
            feats_lines = []
            line = raw_input()
            X_test = read_features_test(line, '\t')
            y_test = 2
            log.debug(X_test)
            y_hat = fit_predict_only(config, X_test, y_test)
    else:
    # fits training data and predicts the test set using the trained model
            y_hat = fit_predict(config, X_train, y_train, X_test, y_test)
コード例 #6
0
def run(config):
    '''
    Runs the main code of the program. Checks for mandatory parameters, opens
    input files and performs the learning steps.
    '''
    # check if the mandatory parameters are set in the config file
    x_train_path = config.get("x_train", None)
    if not x_train_path:
        msg = "'x_train' option not found in the configuration file. \
        The training dataset is mandatory."
        raise Exception(msg)

    y_train_path = config.get("y_train", None)
    if not y_train_path:
        msg = "'y_train' option not found in the configuration file. \
        The training dataset is mandatory."
        raise Exception(msg)
        
    learning = config.get("learning", None)
    if not learning:
        msg = "'learning' option not found. At least one \
        learning method must be set."
        raise Exception(msg)
    
    # checks for the optional parameters
    x_test_path = config.get("x_test", None)
    y_test_path = config.get("y_test", None)

    # output file
    output_file_path = config.get("output", None)

    separator = config.get("separator", DEFAULT_SEP)
    
    labels_path = config.get("labels", None)
        
    scale = config.get("scale", True)

    log.debug("Opening input files ...")
    log.debug("X_train: %s" % x_train_path)
    log.debug("y_train: %s" % y_train_path)
    log.debug("X_test: %s" % x_test_path)
    log.debug("y_test_path: %s" % y_test_path)
    
    
    # open feature and response files    
    X_train, y_train, X_test, y_test, labels = \
    open_datasets(x_train_path, y_train_path, x_test_path,
                  y_test_path, separator, labels_path)

    if scale:
        # preprocess and execute mean removal
        X_train, X_test = scale_datasets(X_train, X_test)

    
    predict_only = config.get("predict_only", False)
    if predict_only:
            feats_lines = []
            line = raw_input()
            toks = tuple(line.strip().split('\t'))
            cols = []
            for t in toks:
                if t != '':
                    try:
                        cols.append(float(t))
                    except ValueError as e:
                        log.error("error")
        #log.error("%s line %s: %s" % (e, line_num, t))
            
            
            feats_lines.append(cols)
            X_test = np.asarray(feats_lines)
            y_test = 2
            log.debug(X_test)
            y_hat = fit_predict_only(config, X_test, y_test)
    else:
    # fits training data and predicts the test set using the trained model
            y_hat = fit_predict(config, X_train, y_train, X_test, y_test)