Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8258e8a

Browse files
committed
Pushing the docs to dev/ for branch: master, commit e3fe559a870cbe52bbdd23fd1c74f07ec83052f5
1 parentc9d2d2a commit8258e8a

File tree

1,177 files changed

+3648
-3648
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,177 files changed

+3648
-3648
lines changed

‎dev/_downloads/18771ded92de7c896426232db4ecc24e/plot_sgd_weighted_samples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
cmap=plt.cm.bone,edgecolor='black')
2828

2929
# fit the unweighted model
30-
clf=linear_model.SGDClassifier(alpha=0.01,max_iter=100,tol=1e-3)
30+
clf=linear_model.SGDClassifier(alpha=0.01,max_iter=100)
3131
clf.fit(X,y)
3232
Z=clf.decision_function(np.c_[xx.ravel(),yy.ravel()])
3333
Z=Z.reshape(xx.shape)
3434
no_weights=plt.contour(xx,yy,Z,levels=[0],linestyles=['solid'])
3535

3636
# fit the weighted model
37-
clf=linear_model.SGDClassifier(alpha=0.01,max_iter=100,tol=1e-3)
37+
clf=linear_model.SGDClassifier(alpha=0.01,max_iter=100)
3838
clf.fit(X,y,sample_weight=sample_weight)
3939
Z=clf.decision_function(np.c_[xx.ravel(),yy.ravel()])
4040
Z=Z.reshape(xx.shape)

‎dev/_downloads/1abc4484d4183963e2039c8c679497eb/plot_sgd_comparison.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-
"# Author: Rob Zinkov <rob at zinkov dot com>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import datasets\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import SGDClassifier, Perceptron\nfrom sklearn.linear_model import PassiveAggressiveClassifier\nfrom sklearn.linear_model import LogisticRegression\n\nheldout = [0.95, 0.90, 0.75, 0.50, 0.01]\nrounds = 20\nX, y = datasets.load_digits(return_X_y=True)\n\nclassifiers = [\n (\"SGD\", SGDClassifier(max_iter=100, tol=1e-3)),\n (\"ASGD\", SGDClassifier(average=True, max_iter=1000, tol=1e-3)),\n (\"Perceptron\", Perceptron(tol=1e-3)),\n (\"Passive-Aggressive I\", PassiveAggressiveClassifier(loss='hinge',\n C=1.0, tol=1e-4)),\n (\"Passive-Aggressive II\", PassiveAggressiveClassifier(loss='squared_hinge',\n C=1.0, tol=1e-4)),\n (\"SAG\", LogisticRegression(solver='sag', tol=1e-1, C=1.e4 / X.shape[0]))\n]\n\nxx = 1. - np.array(heldout)\n\nfor name, clf in classifiers:\n print(\"training %s\" % name)\n rng = np.random.RandomState(42)\n yy = []\n for i in heldout:\n yy_ = []\n for r in range(rounds):\n X_train, X_test, y_train, y_test = \\\n train_test_split(X, y, test_size=i, random_state=rng)\n clf.fit(X_train, y_train)\n y_pred = clf.predict(X_test)\n yy_.append(1 - np.mean(y_pred == y_test))\n yy.append(np.mean(yy_))\n plt.plot(xx, yy, label=name)\n\nplt.legend(loc=\"upper right\")\nplt.xlabel(\"Proportion train\")\nplt.ylabel(\"Test Error Rate\")\nplt.show()"
29+
"# Author: Rob Zinkov <rob at zinkov dot com>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import datasets\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import SGDClassifier, Perceptron\nfrom sklearn.linear_model import PassiveAggressiveClassifier\nfrom sklearn.linear_model import LogisticRegression\n\nheldout = [0.95, 0.90, 0.75, 0.50, 0.01]\nrounds = 20\nX, y = datasets.load_digits(return_X_y=True)\n\nclassifiers = [\n (\"SGD\", SGDClassifier(max_iter=100)),\n (\"ASGD\", SGDClassifier(average=True, max_iter=1000)),\n (\"Perceptron\", Perceptron(tol=1e-3)),\n (\"Passive-Aggressive I\", PassiveAggressiveClassifier(loss='hinge',\n C=1.0, tol=1e-4)),\n (\"Passive-Aggressive II\", PassiveAggressiveClassifier(loss='squared_hinge',\n C=1.0, tol=1e-4)),\n (\"SAG\", LogisticRegression(solver='sag', tol=1e-1, C=1.e4 / X.shape[0]))\n]\n\nxx = 1. - np.array(heldout)\n\nfor name, clf in classifiers:\n print(\"training %s\" % name)\n rng = np.random.RandomState(42)\n yy = []\n for i in heldout:\n yy_ = []\n for r in range(rounds):\n X_train, X_test, y_train, y_test = \\\n train_test_split(X, y, test_size=i, random_state=rng)\n clf.fit(X_train, y_train)\n y_pred = clf.predict(X_test)\n yy_.append(1 - np.mean(y_pred == y_test))\n yy.append(np.mean(yy_))\n plt.plot(xx, yy, label=name)\n\nplt.legend(loc=\"upper right\")\nplt.xlabel(\"Proportion train\")\nplt.ylabel(\"Test Error Rate\")\nplt.show()"
3030
]
3131
}
3232
],

‎dev/_downloads/275c1a8902428a3a52b079bb6f13591a/plot_sgd_separating_hyperplane.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# fit the model
2121
clf=SGDClassifier(loss="hinge",alpha=0.01,max_iter=200,
22-
fit_intercept=True,tol=1e-3)
22+
fit_intercept=True)
2323
clf.fit(X,Y)
2424

2525
# plot the line, the points, and the nearest vectors to the plane
Binary file not shown.

‎dev/_downloads/3650884f0a646ba96d2e47df0a6fb935/plot_sgd_comparison.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
X,y=datasets.load_digits(return_X_y=True)
2525

2626
classifiers= [
27-
("SGD",SGDClassifier(max_iter=100,tol=1e-3)),
28-
("ASGD",SGDClassifier(average=True,max_iter=1000,tol=1e-3)),
27+
("SGD",SGDClassifier(max_iter=100)),
28+
("ASGD",SGDClassifier(average=True,max_iter=1000)),
2929
("Perceptron",Perceptron(tol=1e-3)),
3030
("Passive-Aggressive I",PassiveAggressiveClassifier(loss='hinge',
3131
C=1.0,tol=1e-4)),

‎dev/_downloads/4339c826f9873f4c9ebbcaf331f57b9d/grid_search_text_feature_extraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
pipeline=Pipeline([
8888
('vect',CountVectorizer()),
8989
('tfidf',TfidfTransformer()),
90-
('clf',SGDClassifier(tol=1e-3)),
90+
('clf',SGDClassifier()),
9191
])
9292

9393
# uncommenting more parameters will give better exploring power but will

‎dev/_downloads/4452f13fc6e1f6bc2280af49e5c4afde/plot_sgd_iris.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
h=.02# step size in the mesh
4040

41-
clf=SGDClassifier(alpha=0.001,max_iter=100,tol=1e-3).fit(X,y)
41+
clf=SGDClassifier(alpha=0.001,max_iter=100).fit(X,y)
4242

4343
# create a mesh to plot in
4444
x_min,x_max=X[:,0].min()-1,X[:,0].max()+1

‎dev/_downloads/4aaaf51a640f112464b83039979cb0fe/plot_sgd_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-
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import linear_model\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 = 100 * np.abs(np.random.randn(20))\n# and assign a bigger weight to the last 10 samples\nsample_weight[:10] *= 10\n\n# plot the weighted data points\nxx, yy = np.meshgrid(np.linspace(-4, 5, 500), np.linspace(-4, 5, 500))\nplt.figure()\nplt.scatter(X[:, 0], X[:, 1], c=y, s=sample_weight, alpha=0.9,\n cmap=plt.cm.bone, edgecolor='black')\n\n# fit the unweighted model\nclf = linear_model.SGDClassifier(alpha=0.01, max_iter=100, tol=1e-3)\nclf.fit(X, y)\nZ = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])\nZ = Z.reshape(xx.shape)\nno_weights = plt.contour(xx, yy, Z, levels=[0], linestyles=['solid'])\n\n# fit the weighted model\nclf = linear_model.SGDClassifier(alpha=0.01, max_iter=100, tol=1e-3)\nclf.fit(X, y, sample_weight=sample_weight)\nZ = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])\nZ = Z.reshape(xx.shape)\nsamples_weights = plt.contour(xx, yy, Z, levels=[0], linestyles=['dashed'])\n\nplt.legend([no_weights.collections[0], samples_weights.collections[0]],\n [\"no weights\", \"with weights\"], loc=\"lower left\")\n\nplt.xticks(())\nplt.yticks(())\nplt.show()"
29+
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import linear_model\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 = 100 * np.abs(np.random.randn(20))\n# and assign a bigger weight to the last 10 samples\nsample_weight[:10] *= 10\n\n# plot the weighted data points\nxx, yy = np.meshgrid(np.linspace(-4, 5, 500), np.linspace(-4, 5, 500))\nplt.figure()\nplt.scatter(X[:, 0], X[:, 1], c=y, s=sample_weight, alpha=0.9,\n cmap=plt.cm.bone, edgecolor='black')\n\n# fit the unweighted model\nclf = linear_model.SGDClassifier(alpha=0.01, max_iter=100)\nclf.fit(X, y)\nZ = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])\nZ = Z.reshape(xx.shape)\nno_weights = plt.contour(xx, yy, Z, levels=[0], linestyles=['solid'])\n\n# fit the weighted model\nclf = linear_model.SGDClassifier(alpha=0.01, max_iter=100)\nclf.fit(X, y, sample_weight=sample_weight)\nZ = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])\nZ = Z.reshape(xx.shape)\nsamples_weights = plt.contour(xx, yy, Z, levels=[0], linestyles=['dashed'])\n\nplt.legend([no_weights.collections[0], samples_weights.collections[0]],\n [\"no weights\", \"with weights\"], loc=\"lower left\")\n\nplt.xticks(())\nplt.yticks(())\nplt.show()"
3030
]
3131
}
3232
],

‎dev/_downloads/637afdd681404c733540858401aadf5c/wikipedia_principal_eigenvector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,6 @@ def centrality_scores(X, alpha=0.85, max_iter=100, tol=1e-10):
224224

225225
print("Computing principal eigenvector score using a power iteration method")
226226
t0=time()
227-
scores=centrality_scores(X,max_iter=100,tol=1e-10)
227+
scores=centrality_scores(X,max_iter=100)
228228
print("done in %0.3fs"% (time()-t0))
229229
pprint([names[i]foriinnp.abs(scores).argsort()[-10:]])

‎dev/_downloads/80692cf167e9ea27b27e5bd144159c82/plot_out_of_core_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def progress(blocknum, bs, size):
207207

208208
# Here are some classifiers that support the `partial_fit` method
209209
partial_fit_classifiers= {
210-
'SGD':SGDClassifier(max_iter=5,tol=1e-3),
210+
'SGD':SGDClassifier(max_iter=5),
211211
'Perceptron':Perceptron(tol=1e-3),
212212
'NB Multinomial':MultinomialNB(alpha=0.01),
213213
'Passive-Aggressive':PassiveAggressiveClassifier(tol=1e-3),

‎dev/_downloads/9f3f07bb0415c63c255a2eb1b8db4d9d/plot_sgd_early_stopping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def fit_and_score(estimator, max_iter, X_train, X_test, y_train, y_test):
8989
# Define the estimators to compare
9090
estimator_dict= {
9191
'No stopping criterion':
92-
linear_model.SGDClassifier(tol=1e-3,n_iter_no_change=3),
92+
linear_model.SGDClassifier(n_iter_no_change=3),
9393
'Training loss':
9494
linear_model.SGDClassifier(early_stopping=False,n_iter_no_change=3,
9595
tol=0.1),

‎dev/_downloads/a44cd61773570036d8dd547ccc750b2a/plot_sgd_early_stopping.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-
"# Authors: Tom Dupre la Tour\n#\n# License: BSD 3 clause\nimport time\nimport sys\n\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import linear_model\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.utils.testing import ignore_warnings\nfrom sklearn.exceptions import ConvergenceWarning\nfrom sklearn.utils import shuffle\n\nprint(__doc__)\n\n\ndef load_mnist(n_samples=None, class_0='0', class_1='8'):\n \"\"\"Load MNIST, select two classes, shuffle and return only n_samples.\"\"\"\n # Load data from http://openml.org/d/554\n mnist = fetch_openml('mnist_784', version=1)\n\n # take only two classes for binary classification\n mask = np.logical_or(mnist.target == class_0, mnist.target == class_1)\n\n X, y = shuffle(mnist.data[mask], mnist.target[mask], random_state=42)\n if n_samples is not None:\n X, y = X[:n_samples], y[:n_samples]\n return X, y\n\n\n@ignore_warnings(category=ConvergenceWarning)\ndef fit_and_score(estimator, max_iter, X_train, X_test, y_train, y_test):\n \"\"\"Fit the estimator on the train set and score it on both sets\"\"\"\n estimator.set_params(max_iter=max_iter)\n estimator.set_params(random_state=0)\n\n start = time.time()\n estimator.fit(X_train, y_train)\n\n fit_time = time.time() - start\n n_iter = estimator.n_iter_\n train_score = estimator.score(X_train, y_train)\n test_score = estimator.score(X_test, y_test)\n\n return fit_time, n_iter, train_score, test_score\n\n\n# Define the estimators to compare\nestimator_dict = {\n 'No stopping criterion':\n linear_model.SGDClassifier(tol=1e-3, n_iter_no_change=3),\n 'Training loss':\n linear_model.SGDClassifier(early_stopping=False, n_iter_no_change=3,\n tol=0.1),\n 'Validation score':\n linear_model.SGDClassifier(early_stopping=True, n_iter_no_change=3,\n tol=0.0001, validation_fraction=0.2)\n}\n\n# Load the dataset\nX, y = load_mnist(n_samples=10000)\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5,\n random_state=0)\n\nresults = []\nfor estimator_name, estimator in estimator_dict.items():\n print(estimator_name + ': ', end='')\n for max_iter in range(1, 50):\n print('.', end='')\n sys.stdout.flush()\n\n fit_time, n_iter, train_score, test_score = fit_and_score(\n estimator, max_iter, X_train, X_test, y_train, y_test)\n\n results.append((estimator_name, max_iter, fit_time, n_iter,\n train_score, test_score))\n print('')\n\n# Transform the results in a pandas dataframe for easy plotting\ncolumns = [\n 'Stopping criterion', 'max_iter', 'Fit time (sec)', 'n_iter_',\n 'Train score', 'Test score'\n]\nresults_df = pd.DataFrame(results, columns=columns)\n\n# Define what to plot (x_axis, y_axis)\nlines = 'Stopping criterion'\nplot_list = [\n ('max_iter', 'Train score'),\n ('max_iter', 'Test score'),\n ('max_iter', 'n_iter_'),\n ('max_iter', 'Fit time (sec)'),\n]\n\nnrows = 2\nncols = int(np.ceil(len(plot_list) / 2.))\nfig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(6 * ncols,\n 4 * nrows))\naxes[0, 0].get_shared_y_axes().join(axes[0, 0], axes[0, 1])\n\nfor ax, (x_axis, y_axis) in zip(axes.ravel(), plot_list):\n for criterion, group_df in results_df.groupby(lines):\n group_df.plot(x=x_axis, y=y_axis, label=criterion, ax=ax)\n ax.set_title(y_axis)\n ax.legend(title=lines)\n\nfig.tight_layout()\nplt.show()"
29+
"# Authors: Tom Dupre la Tour\n#\n# License: BSD 3 clause\nimport time\nimport sys\n\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import linear_model\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.utils.testing import ignore_warnings\nfrom sklearn.exceptions import ConvergenceWarning\nfrom sklearn.utils import shuffle\n\nprint(__doc__)\n\n\ndef load_mnist(n_samples=None, class_0='0', class_1='8'):\n \"\"\"Load MNIST, select two classes, shuffle and return only n_samples.\"\"\"\n # Load data from http://openml.org/d/554\n mnist = fetch_openml('mnist_784', version=1)\n\n # take only two classes for binary classification\n mask = np.logical_or(mnist.target == class_0, mnist.target == class_1)\n\n X, y = shuffle(mnist.data[mask], mnist.target[mask], random_state=42)\n if n_samples is not None:\n X, y = X[:n_samples], y[:n_samples]\n return X, y\n\n\n@ignore_warnings(category=ConvergenceWarning)\ndef fit_and_score(estimator, max_iter, X_train, X_test, y_train, y_test):\n \"\"\"Fit the estimator on the train set and score it on both sets\"\"\"\n estimator.set_params(max_iter=max_iter)\n estimator.set_params(random_state=0)\n\n start = time.time()\n estimator.fit(X_train, y_train)\n\n fit_time = time.time() - start\n n_iter = estimator.n_iter_\n train_score = estimator.score(X_train, y_train)\n test_score = estimator.score(X_test, y_test)\n\n return fit_time, n_iter, train_score, test_score\n\n\n# Define the estimators to compare\nestimator_dict = {\n 'No stopping criterion':\n linear_model.SGDClassifier(n_iter_no_change=3),\n 'Training loss':\n linear_model.SGDClassifier(early_stopping=False, n_iter_no_change=3,\n tol=0.1),\n 'Validation score':\n linear_model.SGDClassifier(early_stopping=True, n_iter_no_change=3,\n tol=0.0001, validation_fraction=0.2)\n}\n\n# Load the dataset\nX, y = load_mnist(n_samples=10000)\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5,\n random_state=0)\n\nresults = []\nfor estimator_name, estimator in estimator_dict.items():\n print(estimator_name + ': ', end='')\n for max_iter in range(1, 50):\n print('.', end='')\n sys.stdout.flush()\n\n fit_time, n_iter, train_score, test_score = fit_and_score(\n estimator, max_iter, X_train, X_test, y_train, y_test)\n\n results.append((estimator_name, max_iter, fit_time, n_iter,\n train_score, test_score))\n print('')\n\n# Transform the results in a pandas dataframe for easy plotting\ncolumns = [\n 'Stopping criterion', 'max_iter', 'Fit time (sec)', 'n_iter_',\n 'Train score', 'Test score'\n]\nresults_df = pd.DataFrame(results, columns=columns)\n\n# Define what to plot (x_axis, y_axis)\nlines = 'Stopping criterion'\nplot_list = [\n ('max_iter', 'Train score'),\n ('max_iter', 'Test score'),\n ('max_iter', 'n_iter_'),\n ('max_iter', 'Fit time (sec)'),\n]\n\nnrows = 2\nncols = int(np.ceil(len(plot_list) / 2.))\nfig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(6 * ncols,\n 4 * nrows))\naxes[0, 0].get_shared_y_axes().join(axes[0, 0], axes[0, 1])\n\nfor ax, (x_axis, y_axis) in zip(axes.ravel(), plot_list):\n for criterion, group_df in results_df.groupby(lines):\n group_df.plot(x=x_axis, y=y_axis, label=criterion, ax=ax)\n ax.set_title(y_axis)\n ax.legend(title=lines)\n\nfig.tight_layout()\nplt.show()"
3030
]
3131
}
3232
],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp