elif dec_name == 'quadratic': feat_calc = soil.QuadraticSurfaceCalculator( 2, np.array([X[:, 0].min(), X[:, 0].max(), X[:, 1].min(), X[:, 1].max()], dtype='float32'), random_seed=rs) cls = [] lm = [] for i in range(n_trees): cls.append( soil.ThresholdDecider( feat_sel_prov, feat_calc, soil.RandomizedClassificationThresholdOptimizer( suggestions, n_classes, soil.EntropyGain(soil.ShannonEntropy()), random_seed=rs))) lm.append(soil.ClassificationLeafManager(n_classes)) forest = soil.Forest(depth, 1, 2, n_trees, cls, lm, soil.ClassicTraining(soil.NoBagging())) forest.fit(X, Y) if INTERACTIVE: plt.figure() point_prob_plot(forest, X, Y, plotx, ploty) plt.title('Random Forest $(T=%d, D=%d, |\Theta_j|=%d)$' % (n_trees, depth, suggestions * 2)) plt.savefig('spiral_rf.png') plt.show() assert accuracy_score(Y, np.argmax(forest.predict(X), axis=1)) > 0.95
n_trees = 200 # These variables will contain the classifiers and leaf managers for each tree. cls = [] lm = [] for i in range(n_trees): # Classifier: cls.append(soil.ThresholdDecider( soil.StandardFeatureSelectionProvider(1, 2, 2, 2, random_seed=1+i), soil.LinearSurfaceCalculator(400, random_seed=1+i), soil.RandomizedClassificationThresholdOptimizer( True, 2, soil.EntropyGain(soil.ShannonEntropy()), random_seed=1+i))) # Leaf manager: lm.append(soil.ClassificationLeafManager(2)) forest = soil.Forest(depth, 1, 2, n_trees, cls, lm, soil.ClassicTraining(soil.NoBagging())) forest.fit(X, Y) assert accuracy_score(Y, np.argmax(forest.predict(X), axis=1)) > 0.95 if INTERACTIVE: plt.figure() point_prob_plot(forest, X, Y, plotx, ploty) plt.savefig('custom.png') plt.show()