Ejemplo n.º 1
0
def multiclass_cartree_modular(train=traindat,test=testdat,labels=label_traindat,ft=feattypes):	
	try:
		from modshogun import RealFeatures, MulticlassLabels, CSVFile, CARTree, PT_MULTICLASS
	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))

	# CART Tree formation with 5 fold cross-validation pruning
	c=CARTree(ft,PT_MULTICLASS,5,True)
	c.set_labels(train_labels)
	c.train(feats_train)

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

	return c,output
Ejemplo n.º 2
0
def multiclass_cartree_modular(train=traindat,
                               test=testdat,
                               labels=label_traindat,
                               ft=feattypes):
    try:
        from modshogun import RealFeatures, MulticlassLabels, CSVFile, CARTree, PT_MULTICLASS
    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))

    # CART Tree formation with 5 fold cross-validation pruning
    c = CARTree(ft, PT_MULTICLASS, 5, True)
    c.set_labels(train_labels)
    c.train(feats_train)

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

    return c, output