Skip to content

Commit 2ae1117

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 11e7369034b2c809f6511e9e9b3f04cc9969b888
1 parent 87a9af2 commit 2ae1117

File tree

996 files changed

+3056
-3059
lines changed

Some content is hidden

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

996 files changed

+3056
-3059
lines changed
-47 Bytes
Binary file not shown.
-46 Bytes
Binary file not shown.

dev/_downloads/plot_classifier_chain_yeast.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# Classifier Chain\n\nExample of using classifier chain on a multilabel dataset.\n\nFor this example we will use the `yeast\n<http://mldata.org/repository/data/viewslug/yeast>`_ dataset which contains\n2417 datapoints each with 103 features and 14 possible labels. Each\ndata point has at least one label. As a baseline we first train a logistic\nregression classifier for each of the 14 labels. To evaluate the performance of\nthese classifiers we predict on a held-out test set and calculate the\n`jaccard similarity score <jaccard_similarity_score>`.\n\nNext we create 10 classifier chains. Each classifier chain contains a\nlogistic regression model for each of the 14 labels. The models in each\nchain are ordered randomly. In addition to the 103 features in the dataset,\neach model gets the predictions of the preceding models in the chain as\nfeatures (note that by default at training time each model gets the true\nlabels as features). These additional features allow each chain to exploit\ncorrelations among the classes. The Jaccard similarity score for each chain\ntends to be greater than that of the set independent logistic models.\n\nBecause the models in each chain are arranged randomly there is significant\nvariation in performance among the chains. Presumably there is an optimal\nordering of the classes in a chain that will yield the best performance.\nHowever we do not know that ordering a priori. Instead we can construct an\nvoting ensemble of classifier chains by averaging the binary predictions of\nthe chains and apply a threshold of 0.5. The Jaccard similarity score of the\nensemble is greater than that of the independent models and tends to exceed\nthe score of each chain in the ensemble (although this is not guaranteed\nwith randomly ordered chains).\n\n"
18+
"\n# Classifier Chain\n\nExample of using classifier chain on a multilabel dataset.\n\nFor this example we will use the `yeast\n<http://mldata.org/repository/data/viewslug/yeast>`_ dataset which\ncontains 2417 datapoints each with 103 features and 14 possible labels. Each\ndatapoint has at least one label. As a baseline we first train a logistic\nregression classifier for each of the 14 labels. To evaluate the performance\nof these classifiers we predict on a held-out test set and calculate the\n`User Guide <jaccard_similarity_score>`.\n\nNext we create 10 classifier chains. Each classifier chain contains a\nlogistic regression model for each of the 14 labels. The models in each\nchain are ordered randomly. In addition to the 103 features in the dataset,\neach model gets the predictions of the preceding models in the chain as\nfeatures (note that by default at training time each model gets the true\nlabels as features). These additional features allow each chain to exploit\ncorrelations among the classes. The Jaccard similarity score for each chain\ntends to be greater than that of the set independent logistic models.\n\nBecause the models in each chain are arranged randomly there is significant\nvariation in performance among the chains. Presumably there is an optimal\nordering of the classes in a chain that will yield the best performance.\nHowever we do not know that ordering a priori. Instead we can construct an\nvoting ensemble of classifier chains by averaging the binary predictions of\nthe chains and apply a threshold of 0.5. The Jaccard similarity score of the\nensemble is greater than that of the independent models and tends to exceed\nthe score of each chain in the ensemble (although this is not guaranteed\nwith randomly ordered chains).\n\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\n# Author: Adam Kleczewski\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.multioutput import ClassifierChain\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.multiclass import OneVsRestClassifier\nfrom sklearn.metrics import jaccard_similarity_score\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.datasets import fetch_mldata\n\n# Load a multi-label dataset\nyeast = fetch_mldata('yeast')\nX = yeast['data']\nY = yeast['target'].transpose().toarray()\nX_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=.2,\n random_state=0)\n\n# Fit an independent logistic regression model for each class using the\n# OneVsRestClassifier wrapper.\novr = OneVsRestClassifier(LogisticRegression())\novr.fit(X_train, Y_train)\nY_pred_ovr = ovr.predict(X_test)\novr_jaccard_score = jaccard_similarity_score(Y_test, Y_pred_ovr)\n\n# Fit an ensemble of logistic regression classifier chains and take the\n# take the average prediction of all the chains.\nchains = [ClassifierChain(LogisticRegression(), order='random', random_state=i)\n for i in range(10)]\nfor chain in chains:\n chain.fit(X_train, Y_train)\n\nY_pred_chains = np.array([chain.predict(X_test) for chain in\n chains])\nchain_jaccard_scores = [jaccard_similarity_score(Y_test, Y_pred_chain >= .5)\n for Y_pred_chain in Y_pred_chains]\n\nY_pred_ensemble = Y_pred_chains.mean(axis=0)\nensemble_jaccard_score = jaccard_similarity_score(Y_test,\n Y_pred_ensemble >= .5)\n\nmodel_scores = [ovr_jaccard_score] + chain_jaccard_scores\nmodel_scores.append(ensemble_jaccard_score)\n\nmodel_names = ('Independent',\n 'Chain 1',\n 'Chain 2',\n 'Chain 3',\n 'Chain 4',\n 'Chain 5',\n 'Chain 6',\n 'Chain 7',\n 'Chain 8',\n 'Chain 9',\n 'Chain 10',\n 'Ensemble')\n\nx_pos = np.arange(len(model_names))\n\n# Plot the Jaccard similarity scores for the independent model, each of the\n# chains, and the ensemble (note that the vertical axis on this plot does\n# not begin at 0).\n\nfig, ax = plt.subplots(figsize=(7, 4))\nax.grid(True)\nax.set_title('Classifier Chain Ensemble Performance Comparison')\nax.set_xticks(x_pos)\nax.set_xticklabels(model_names, rotation='vertical')\nax.set_ylabel('Jaccard Similarity Score')\nax.set_ylim([min(model_scores) * .9, max(model_scores) * 1.1])\ncolors = ['r'] + ['b'] * len(chain_jaccard_scores) + ['g']\nax.bar(x_pos, model_scores, alpha=0.5, color=colors)\nplt.tight_layout()\nplt.show()"
29+
"print(__doc__)\n\n# Author: Adam Kleczewski\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.multioutput import ClassifierChain\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.multiclass import OneVsRestClassifier\nfrom sklearn.metrics import jaccard_similarity_score\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.datasets import fetch_mldata\n\n# Load a multi-label dataset\nyeast = fetch_mldata('yeast')\nX = yeast['data']\nY = yeast['target'].transpose().toarray()\nX_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=.2,\n random_state=0)\n\n# Fit an independent logistic regression model for each class using the\n# OneVsRestClassifier wrapper.\novr = OneVsRestClassifier(LogisticRegression())\novr.fit(X_train, Y_train)\nY_pred_ovr = ovr.predict(X_test)\novr_jaccard_score = jaccard_similarity_score(Y_test, Y_pred_ovr)\n\n# Fit an ensemble of logistic regression classifier chains and take the\n# take the average prediction of all the chains.\nchains = [ClassifierChain(LogisticRegression(), order='random', random_state=i)\n for i in range(10)]\nfor chain in chains:\n chain.fit(X_train, Y_train)\n\nY_pred_chains = np.array([chain.predict(X_test) for chain in\n chains])\nchain_jaccard_scores = [jaccard_similarity_score(Y_test, Y_pred_chain >= .5)\n for Y_pred_chain in Y_pred_chains]\n\nY_pred_ensemble = Y_pred_chains.mean(axis=0)\nensemble_jaccard_score = jaccard_similarity_score(Y_test,\n Y_pred_ensemble >= .5)\n\nmodel_scores = [ovr_jaccard_score] + chain_jaccard_scores\nmodel_scores.append(ensemble_jaccard_score)\n\nmodel_names = ('Independent Models',\n 'Chain 1',\n 'Chain 2',\n 'Chain 3',\n 'Chain 4',\n 'Chain 5',\n 'Chain 6',\n 'Chain 7',\n 'Chain 8',\n 'Chain 9',\n 'Chain 10',\n 'Ensemble Average')\n\ny_pos = np.arange(len(model_names))\ny_pos[1:] += 1\ny_pos[-1] += 1\n\n# Plot the Jaccard similarity scores for the independent model, each of the\n# chains, and the ensemble (note that the vertical axis on this plot does\n# not begin at 0).\n\nfig = plt.figure(figsize=(7, 4))\nplt.title('Classifier Chain Ensemble')\nplt.xticks(y_pos, model_names, rotation='vertical')\nplt.ylabel('Jaccard Similarity Score')\nplt.ylim([min(model_scores) * .9, max(model_scores) * 1.1])\ncolors = ['r'] + ['b'] * len(chain_jaccard_scores) + ['g']\nplt.bar(y_pos, model_scores, align='center', alpha=0.5, color=colors)\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_classifier_chain_yeast.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
Example of using classifier chain on a multilabel dataset.
66
77
For this example we will use the `yeast
8-
<http://mldata.org/repository/data/viewslug/yeast>`_ dataset which contains
9-
2417 datapoints each with 103 features and 14 possible labels. Each
10-
data point has at least one label. As a baseline we first train a logistic
11-
regression classifier for each of the 14 labels. To evaluate the performance of
12-
these classifiers we predict on a held-out test set and calculate the
13-
:ref:`jaccard similarity score <jaccard_similarity_score>`.
8+
<http://mldata.org/repository/data/viewslug/yeast>`_ dataset which
9+
contains 2417 datapoints each with 103 features and 14 possible labels. Each
10+
datapoint has at least one label. As a baseline we first train a logistic
11+
regression classifier for each of the 14 labels. To evaluate the performance
12+
of these classifiers we predict on a held-out test set and calculate the
13+
:ref:`User Guide <jaccard_similarity_score>`.
1414
1515
Next we create 10 classifier chains. Each classifier chain contains a
1616
logistic regression model for each of the 14 labels. The models in each
@@ -79,7 +79,7 @@
7979
model_scores = [ovr_jaccard_score] + chain_jaccard_scores
8080
model_scores.append(ensemble_jaccard_score)
8181

82-
model_names = ('Independent',
82+
model_names = ('Independent Models',
8383
'Chain 1',
8484
'Chain 2',
8585
'Chain 3',
@@ -90,22 +90,21 @@
9090
'Chain 8',
9191
'Chain 9',
9292
'Chain 10',
93-
'Ensemble')
93+
'Ensemble Average')
9494

95-
x_pos = np.arange(len(model_names))
95+
y_pos = np.arange(len(model_names))
96+
y_pos[1:] += 1
97+
y_pos[-1] += 1
9698

9799
# Plot the Jaccard similarity scores for the independent model, each of the
98100
# chains, and the ensemble (note that the vertical axis on this plot does
99101
# not begin at 0).
100102

101-
fig, ax = plt.subplots(figsize=(7, 4))
102-
ax.grid(True)
103-
ax.set_title('Classifier Chain Ensemble Performance Comparison')
104-
ax.set_xticks(x_pos)
105-
ax.set_xticklabels(model_names, rotation='vertical')
106-
ax.set_ylabel('Jaccard Similarity Score')
107-
ax.set_ylim([min(model_scores) * .9, max(model_scores) * 1.1])
103+
fig = plt.figure(figsize=(7, 4))
104+
plt.title('Classifier Chain Ensemble')
105+
plt.xticks(y_pos, model_names, rotation='vertical')
106+
plt.ylabel('Jaccard Similarity Score')
107+
plt.ylim([min(model_scores) * .9, max(model_scores) * 1.1])
108108
colors = ['r'] + ['b'] * len(chain_jaccard_scores) + ['g']
109-
ax.bar(x_pos, model_scores, alpha=0.5, color=colors)
110-
plt.tight_layout()
109+
plt.bar(y_pos, model_scores, align='center', alpha=0.5, color=colors)
111110
plt.show()

dev/_downloads/scikit-learn-docs.pdf

30 Bytes
Binary file not shown.
84 Bytes
84 Bytes
224 Bytes
224 Bytes
-42 Bytes

0 commit comments

Comments
 (0)