def build_model(training_data, config): ''' Build model from the config and training data ''' m_type = config[c.CLSFR_TYPE] if m_type == c.DT_WITH_IG: # for decision tree # load thresholds threshs = loader.load_arrays(config[c.THRESHS]) tree = Tree.Tree() tree.build(utils.split_on_ig, training_data[0], training_data[1], threshs, config[c.TERM_CON], int(config[c.TERM_THRESH])) return tree elif m_type == c.REGRESSION_TREE: # for regression tree # load thresholds threshs = loader.load_arrays(config[c.THRESHS]) tree = Tree.Tree() tree.build(utils.split_on_mse, training_data[0], training_data[1], threshs, config[c.TERM_CON], float(config[c.TERM_THRESH])) return tree elif m_type == c.REGRESSION: # for linear regression reg_model = rmodel.Regression() reg_model.build(training_data[0], training_data[1]) return reg_model
import EM as em import DataLoader as loader import numpy as np GAUSS2 = 'data/2gaussian.txt' GAUSS3 = 'data/3gaussian.txt' path = GAUSS3 k = 3 x = np.matrix(loader.load_arrays(path)) x = np.transpose(x) label, model, llh = em.em(x, k) print model