def regression_chaidtree_modular(num_train=500,
                                 num_test=50,
                                 x_range=15,
                                 noise_var=0.2,
                                 ft=feattypes):
    try:
        from modshogun import RealFeatures, RegressionLabels, CSVFile, CHAIDTree, PT_REGRESSION
        from numpy import random
    except ImportError:
        print("Could not import Shogun and/or numpy modules")
        return

    random.seed(1)

    # form training dataset : y=x with noise
    X_train = random.rand(1, num_train) * x_range
    Y_train = X_train + random.randn(num_train) * noise_var

    # form test dataset
    X_test = array([[float(i) / num_test * x_range for i in range(num_test)]])

    # wrap features and labels into Shogun objects
    feats_train = RealFeatures(X_train)
    feats_test = RealFeatures(X_test)
    train_labels = RegressionLabels(Y_train[0])

    # CHAID Tree formation
    c = CHAIDTree(2, feattypes, 50)
    c.set_labels(train_labels)
    c.train(feats_train)

    # Regress on test data
    output = c.apply_regression(feats_test).get_labels()

    return c, output
def multiclass_chaidtree_modular(train=traindat,
                                 test=testdat,
                                 labels=label_traindat,
                                 ft=feattypes):
    try:
        from modshogun import RealFeatures, MulticlassLabels, CSVFile, CHAIDTree
    except ImportError:
        print("Could not import Shogun modules")
        return

    # wrap features and labels into Shogun objects
    feats_train = RealFeatures(CSVFile(train))
    feats_test = RealFeatures(CSVFile(test))
    train_labels = MulticlassLabels(CSVFile(labels))

    # CHAID Tree formation with nominal dependent variable
    c = CHAIDTree(0, feattypes, 10)
    c.set_labels(train_labels)
    c.train(feats_train)

    # Classify test data
    output = c.apply_multiclass(feats_test).get_labels()

    return c, output