Skip to content

Commit f0b85f2

Browse files
committed
Merge branch 'refactor-for-docs'
2 parents 80966b3 + 032648b commit f0b85f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1184
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
benchmarks/figures
12
_site
23
docs/*.md
34
docs/*.html

.pytest_cache/v/cache/lastfailed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.pytest_cache/v/cache/nodeids

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
"src/importnb/tests/test_importnb.ipynb::test_single_file_with_context",
3+
"src/importnb/tests/test_importnb.ipynb::test_from_filename",
4+
"src/importnb/tests/test_importnb.ipynb::test_with_doctest",
5+
"src/importnb/tests/test_importnb.ipynb::test_from_filename_main",
6+
"src/importnb/tests/test_importnb.ipynb::test_parameterize",
7+
"src/importnb/tests/test_importnb.ipynb::test_python_file",
8+
"src/importnb/tests/test_importnb.ipynb::test_single_file_with_capture",
9+
"src/importnb/tests/test_importnb.ipynb::test_capturer",
10+
"src/importnb/tests/test_importnb.ipynb::test_single_file_with_lazy",
11+
"src/importnb/tests/test_importnb.ipynb::test_single_file_without_context",
12+
"src/importnb/tests/test_importnb.ipynb::test_single_file_relative",
13+
"src/importnb/tests/test_importnb.ipynb::test_single_with_extension",
14+
"src/importnb/tests/test_importnb.ipynb::test_package",
15+
"src/importnb/tests/test_importnb.ipynb::test_package_failure",
16+
"src/importnb/tests/test_importnb.ipynb::test_package_failure_partial",
17+
"src/importnb/tests/test_module.ipynb::testmod",
18+
"src/importnb/tests/test_module.ipynb::test_all",
19+
"src/importnb/tests/test_unittests.ipynb::TestExtension::test_failure",
20+
"src/importnb/tests/test_unittests.ipynb::TestExtension::test_import",
21+
"src/importnb/tests/test_unittests.ipynb::TestContext::test_import",
22+
"src/importnb/tests/test_unittests.ipynb::TestContext::test_reload_with_context",
23+
"src/importnb/tests/test_unittests.ipynb::TestRemote::test_imports",
24+
"src/importnb/tests/test_unittests.ipynb::TestPartial::test_exception",
25+
"src/importnb/tests/test_unittests.ipynb::TestPartial::test_traceback"
26+
]

benchmarks/hello.png

3.79 KB
Loading

benchmarks/helpers_05_08.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
from sklearn.tree import DecisionTreeClassifier
5+
from ipywidgets import interact
6+
7+
8+
def visualize_tree(estimator, X, y, boundaries=True,
9+
xlim=None, ylim=None, ax=None):
10+
ax = ax or plt.gca()
11+
12+
# Plot the training points
13+
ax.scatter(X[:, 0], X[:, 1], c=y, s=30, cmap='viridis',
14+
clim=(y.min(), y.max()), zorder=3)
15+
ax.axis('tight')
16+
ax.axis('off')
17+
if xlim is None:
18+
xlim = ax.get_xlim()
19+
if ylim is None:
20+
ylim = ax.get_ylim()
21+
22+
# fit the estimator
23+
estimator.fit(X, y)
24+
xx, yy = np.meshgrid(np.linspace(*xlim, num=200),
25+
np.linspace(*ylim, num=200))
26+
Z = estimator.predict(np.c_[xx.ravel(), yy.ravel()])
27+
28+
# Put the result into a color plot
29+
n_classes = len(np.unique(y))
30+
Z = Z.reshape(xx.shape)
31+
contours = ax.contourf(xx, yy, Z, alpha=0.3,
32+
levels=np.arange(n_classes + 1) - 0.5,
33+
cmap='viridis', clim=(y.min(), y.max()),
34+
zorder=1)
35+
36+
ax.set(xlim=xlim, ylim=ylim)
37+
38+
# Plot the decision boundaries
39+
def plot_boundaries(i, xlim, ylim):
40+
if i >= 0:
41+
tree = estimator.tree_
42+
43+
if tree.feature[i] == 0:
44+
ax.plot([tree.threshold[i], tree.threshold[i]], ylim, '-k', zorder=2)
45+
plot_boundaries(tree.children_left[i],
46+
[xlim[0], tree.threshold[i]], ylim)
47+
plot_boundaries(tree.children_right[i],
48+
[tree.threshold[i], xlim[1]], ylim)
49+
50+
elif tree.feature[i] == 1:
51+
ax.plot(xlim, [tree.threshold[i], tree.threshold[i]], '-k', zorder=2)
52+
plot_boundaries(tree.children_left[i], xlim,
53+
[ylim[0], tree.threshold[i]])
54+
plot_boundaries(tree.children_right[i], xlim,
55+
[tree.threshold[i], ylim[1]])
56+
57+
if boundaries:
58+
plot_boundaries(0, xlim, ylim)
59+
60+
61+
def plot_tree_interactive(X, y):
62+
def interactive_tree(depth=5):
63+
clf = DecisionTreeClassifier(max_depth=depth, random_state=0)
64+
visualize_tree(clf, X, y)
65+
66+
return interact(interactive_tree, depth=[1, 5])
67+
68+
69+
def randomized_tree_interactive(X, y):
70+
N = int(0.75 * X.shape[0])
71+
72+
xlim = (X[:, 0].min(), X[:, 0].max())
73+
ylim = (X[:, 1].min(), X[:, 1].max())
74+
75+
def fit_randomized_tree(random_state=0):
76+
clf = DecisionTreeClassifier(max_depth=15)
77+
i = np.arange(len(y))
78+
rng = np.random.RandomState(random_state)
79+
rng.shuffle(i)
80+
visualize_tree(clf, X[i[:N]], y[i[:N]], boundaries=False,
81+
xlim=xlim, ylim=ylim)
82+
83+
interact(fit_randomized_tree, random_state=[0, 100]);

benchmarks/my_figure.png

25.7 KB
Loading
59.4 KB
Loading

benchmarks/temp.wav

10.8 KB
Binary file not shown.

changelog.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"# 0.3.0\n",
14+
"# 0.2.9\n",
1515
"\n",
1616
"* Include `Partial`, `Lazy`, and `NotebookTest` loaders.\n",
1717
"* Transform markdown cells to literate block strings so they are included in the ast.\n",

classes_importnb.png

193 KB
Loading

0 commit comments

Comments
 (0)