Skip to content

Commit 9060458

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 22071218b221e4a48f78f834864302b6d4b69b91
1 parent cb99cc3 commit 9060458

File tree

1,084 files changed

+3512
-3355
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,084 files changed

+3512
-3355
lines changed
177 Bytes
Binary file not shown.
171 Bytes
Binary file not shown.

dev/_downloads/plot_feature_selection_pipeline.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# Pipeline Anova SVM\n\n\nSimple usage of Pipeline that runs successively a univariate\nfeature selection with anova and then a C-SVM of the selected features.\n\n"
18+
"\n# Pipeline Anova SVM\n\n\nSimple usage of Pipeline that runs successively a univariate\nfeature selection with anova and then a SVM of the selected features.\n\nUsing a sub-pipeline, the fitted coefficients can be mapped back into\nthe original feature space.\n\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from sklearn import svm\nfrom sklearn.datasets import samples_generator\nfrom sklearn.feature_selection import SelectKBest, f_regression\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import classification_report\n\nprint(__doc__)\n\n# import some data to play with\nX, y = samples_generator.make_classification(\n n_features=20, n_informative=3, n_redundant=0, n_classes=4,\n n_clusters_per_class=2)\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)\n\n# ANOVA SVM-C\n# 1) anova filter, take 3 best ranked features\nanova_filter = SelectKBest(f_regression, k=3)\n# 2) svm\nclf = svm.SVC(kernel='linear')\n\nanova_svm = make_pipeline(anova_filter, clf)\nanova_svm.fit(X_train, y_train)\ny_pred = anova_svm.predict(X_test)\nprint(classification_report(y_test, y_pred))"
29+
"from sklearn import svm\nfrom sklearn.datasets import samples_generator\nfrom sklearn.feature_selection import SelectKBest, f_regression\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import classification_report\n\nprint(__doc__)\n\n# import some data to play with\nX, y = samples_generator.make_classification(\n n_features=20, n_informative=3, n_redundant=0, n_classes=4,\n n_clusters_per_class=2)\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)\n\n# ANOVA SVM-C\n# 1) anova filter, take 3 best ranked features\nanova_filter = SelectKBest(f_regression, k=3)\n# 2) svm\nclf = svm.LinearSVC()\n\nanova_svm = make_pipeline(anova_filter, clf)\nanova_svm.fit(X_train, y_train)\ny_pred = anova_svm.predict(X_test)\nprint(classification_report(y_test, y_pred))\n\ncoef = anova_svm[:-1].inverse_transform(anova_svm['linearsvc'].coef_)\nprint(coef)"
3030
]
3131
}
3232
],

dev/_downloads/plot_feature_selection_pipeline.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
==================
55
66
Simple usage of Pipeline that runs successively a univariate
7-
feature selection with anova and then a C-SVM of the selected features.
7+
feature selection with anova and then a SVM of the selected features.
8+
9+
Using a sub-pipeline, the fitted coefficients can be mapped back into
10+
the original feature space.
811
"""
912
from sklearn import svm
1013
from sklearn.datasets import samples_generator
@@ -26,9 +29,12 @@
2629
# 1) anova filter, take 3 best ranked features
2730
anova_filter = SelectKBest(f_regression, k=3)
2831
# 2) svm
29-
clf = svm.SVC(kernel='linear')
32+
clf = svm.LinearSVC()
3033

3134
anova_svm = make_pipeline(anova_filter, clf)
3235
anova_svm.fit(X_train, y_train)
3336
y_pred = anova_svm.predict(X_test)
3437
print(classification_report(y_test, y_pred))
38+
39+
coef = anova_svm[:-1].inverse_transform(anova_svm['linearsvc'].coef_)
40+
print(coef)

dev/_downloads/scikit-learn-docs.pdf

45.8 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
85 Bytes
85 Bytes
699 Bytes
699 Bytes

0 commit comments

Comments
 (0)