MCPcopy
hub / github.com/ddbourgin/numpy-ml / plot

Function plot

numpy_ml/plots/trees_plots.py:20–161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18
19
20def plot():
21 fig, axes = plt.subplots(4, 4)
22 fig.set_size_inches(10, 10)
23 for ax in axes.flatten():
24 n_ex = 100
25 n_trees = 50
26 n_feats = np.random.randint(2, 100)
27 max_depth_d = np.random.randint(1, 100)
28 max_depth_r = np.random.randint(1, 10)
29
30 classifier = np.random.choice([True, False])
31 if classifier:
32 # create classification problem
33 n_classes = np.random.randint(2, 10)
34 X, Y = make_blobs(n_samples=n_ex, centers=n_classes, n_features=2)
35 X, X_test, Y, Y_test = train_test_split(X, Y, test_size=0.3)
36 n_feats = min(n_feats, X.shape[1])
37
38 # initialize model
39 def loss(yp, y):
40 return accuracy_score(yp, y)
41
42 # initialize model
43 criterion = np.random.choice(["entropy", "gini"])
44 mine = RandomForest(
45 classifier=classifier,
46 n_feats=n_feats,
47 n_trees=n_trees,
48 criterion=criterion,
49 max_depth=max_depth_r,
50 )
51 mine_d = DecisionTree(
52 criterion=criterion, max_depth=max_depth_d, classifier=classifier
53 )
54 mine_g = GradientBoostedDecisionTree(
55 n_trees=n_trees,
56 max_depth=max_depth_d,
57 classifier=classifier,
58 learning_rate=1,
59 loss="crossentropy",
60 step_size="constant",
61 split_criterion=criterion,
62 )
63
64 else:
65 # create regeression problem
66 X, Y = make_regression(n_samples=n_ex, n_features=1)
67 X, X_test, Y, Y_test = train_test_split(X, Y, test_size=0.3)
68 n_feats = min(n_feats, X.shape[1])
69
70 # initialize model
71 criterion = "mse"
72 loss = mean_squared_error
73 mine = RandomForest(
74 criterion=criterion,
75 n_feats=n_feats,
76 n_trees=n_trees,
77 max_depth=max_depth_r,

Callers

nothing calls this directly

Calls 10

fitMethod · 0.95
fitMethod · 0.95
fitMethod · 0.95
predictMethod · 0.95
predictMethod · 0.95
predictMethod · 0.95
RandomForestClass · 0.90
DecisionTreeClass · 0.90
lossFunction · 0.70

Tested by

no test coverage detected