Skip to content

Commit 312ddfc

Browse files
committed
Pushing the docs to dev/ for branch: main, commit e67581c1aa59e07bba9f0fa4c97006d0a5fd4340
1 parent d0206f0 commit 312ddfc

File tree

1,217 files changed

+4391
-4388
lines changed

Some content is hidden

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

1,217 files changed

+4391
-4388
lines changed
Binary file not shown.
Binary file not shown.

dev/_downloads/cea3fc06a4f342c635cadafa63b33319/plot_weighted_samples.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import svm\n\n\ndef plot_decision_function(classifier, sample_weight, axis, title):\n # plot the decision function\n xx, yy = np.meshgrid(np.linspace(-4, 5, 500), np.linspace(-4, 5, 500))\n\n Z = classifier.decision_function(np.c_[xx.ravel(), yy.ravel()])\n Z = Z.reshape(xx.shape)\n\n # plot the line, the points, and the nearest vectors to the plane\n axis.contourf(xx, yy, Z, alpha=0.75, cmap=plt.cm.bone)\n axis.scatter(\n X[:, 0],\n X[:, 1],\n c=y,\n s=100 * sample_weight,\n alpha=0.9,\n cmap=plt.cm.bone,\n edgecolors=\"black\",\n )\n\n axis.axis(\"off\")\n axis.set_title(title)\n\n\n# we create 20 points\nnp.random.seed(0)\nX = np.r_[np.random.randn(10, 2) + [1, 1], np.random.randn(10, 2)]\ny = [1] * 10 + [-1] * 10\nsample_weight_last_ten = abs(np.random.randn(len(X)))\nsample_weight_constant = np.ones(len(X))\n# and bigger weights to some outliers\nsample_weight_last_ten[15:] *= 5\nsample_weight_last_ten[9] *= 15\n\n# for reference, first fit without sample weights\n\n# fit the model\nclf_weights = svm.SVC(gamma=1)\nclf_weights.fit(X, y, sample_weight=sample_weight_last_ten)\n\nclf_no_weights = svm.SVC(gamma=1)\nclf_no_weights.fit(X, y)\n\nfig, axes = plt.subplots(1, 2, figsize=(14, 6))\nplot_decision_function(\n clf_no_weights, sample_weight_constant, axes[0], \"Constant weights\"\n)\nplot_decision_function(clf_weights, sample_weight_last_ten, axes[1], \"Modified weights\")\n\nplt.show()"
29+
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import svm\n\n\ndef plot_decision_function(classifier, sample_weight, axis, title):\n # plot the decision function\n xx, yy = np.meshgrid(np.linspace(-4, 5, 500), np.linspace(-4, 5, 500))\n\n Z = classifier.decision_function(np.c_[xx.ravel(), yy.ravel()])\n Z = Z.reshape(xx.shape)\n\n # plot the line, the points, and the nearest vectors to the plane\n axis.contourf(xx, yy, Z, alpha=0.75, cmap=plt.cm.bone)\n axis.scatter(\n X[:, 0],\n X[:, 1],\n c=y,\n s=100 * sample_weight,\n alpha=0.9,\n cmap=plt.cm.bone,\n edgecolors=\"black\",\n )\n\n axis.axis(\"off\")\n axis.set_title(title)\n\n\n# we create 20 points\nnp.random.seed(0)\nX = np.r_[np.random.randn(10, 2) + [1, 1], np.random.randn(10, 2)]\ny = [1] * 10 + [-1] * 10\nsample_weight_last_ten = abs(np.random.randn(len(X)))\nsample_weight_constant = np.ones(len(X))\n# and bigger weights to some outliers\nsample_weight_last_ten[15:] *= 5\nsample_weight_last_ten[9] *= 15\n\n# Fit the models.\n\n# This model does not take into account sample weights.\nclf_no_weights = svm.SVC(gamma=1)\nclf_no_weights.fit(X, y)\n\n# This other model takes into account some dedicated sample weights.\nclf_weights = svm.SVC(gamma=1)\nclf_weights.fit(X, y, sample_weight=sample_weight_last_ten)\n\nfig, axes = plt.subplots(1, 2, figsize=(14, 6))\nplot_decision_function(\n clf_no_weights, sample_weight_constant, axes[0], \"Constant weights\"\n)\nplot_decision_function(clf_weights, sample_weight_last_ten, axes[1], \"Modified weights\")\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/d03d4aeab237925427bfe3c81433b953/plot_weighted_samples.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ def plot_decision_function(classifier, sample_weight, axis, title):
5252
sample_weight_last_ten[15:] *= 5
5353
sample_weight_last_ten[9] *= 15
5454

55-
# for reference, first fit without sample weights
56-
57-
# fit the model
58-
clf_weights = svm.SVC(gamma=1)
59-
clf_weights.fit(X, y, sample_weight=sample_weight_last_ten)
55+
# Fit the models.
6056

57+
# This model does not take into account sample weights.
6158
clf_no_weights = svm.SVC(gamma=1)
6259
clf_no_weights.fit(X, y)
6360

61+
# This other model takes into account some dedicated sample weights.
62+
clf_weights = svm.SVC(gamma=1)
63+
clf_weights.fit(X, y, sample_weight=sample_weight_last_ten)
64+
6465
fig, axes = plt.subplots(1, 2, figsize=(14, 6))
6566
plot_decision_function(
6667
clf_no_weights, sample_weight_constant, axes[0], "Constant weights"

dev/_downloads/scikit-learn-docs.zip

5.29 KB
Binary file not shown.

0 commit comments

Comments
 (0)