Skip to content

Commit 5915086

Browse files
committed
Pushing the docs to dev/ for branch: master, commit ecea98f9c965fbb25d2dfb1fdc23784364aa5657
1 parent 3ff572c commit 5915086

File tree

1,075 files changed

+3195
-3155
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,075 files changed

+3195
-3155
lines changed
38 Bytes
Binary file not shown.
38 Bytes
Binary file not shown.

dev/_downloads/plot_column_transformer_mixed_types.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: Pedro Morales <[email protected]>\n#\n# License: BSD 3 clause\n\nimport pandas as pd\nimport numpy as np\n\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler, OneHotEncoder\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split, GridSearchCV\n\nnp.random.seed(0)\n\n# Read data from Titanic dataset.\ntitanic_url = ('https://raw.githubusercontent.com/amueller/'\n 'scipy-2017-sklearn/091d371/notebooks/datasets/titanic3.csv')\ndata = pd.read_csv(titanic_url)\n\n# We will train our classifier with the following features:\n# Numeric Features:\n# - age: float.\n# - fare: float.\n# Categorical Features:\n# - embarked: categories encoded as strings {'C', 'S', 'Q'}.\n# - sex: categories encoded as strings {'female', 'male'}.\n# - pclass: ordinal integers {1, 2, 3}.\n\n# We create the preprocessing pipelines for both numeric and categorical data.\nnumeric_features = ['age', 'fare']\nnumeric_transformer = Pipeline(steps=[\n ('imputer', SimpleImputer(strategy='median')),\n ('scaler', StandardScaler())])\n\ncategorical_features = ['embarked', 'sex', 'pclass']\ncategorical_transformer = Pipeline(steps=[\n ('imputer', SimpleImputer(strategy='constant', fill_value='missing')),\n ('onehot', OneHotEncoder(handle_unknown='ignore'))])\n\npreprocessor = ColumnTransformer(\n transformers=[\n ('num', numeric_transformer, numeric_features),\n ('cat', categorical_transformer, categorical_features)])\n\n# Append classifier to preprocessing pipeline.\n# Now we have a full prediction pipeline.\nclf = Pipeline(steps=[('preprocessor', preprocessor),\n ('classifier', LogisticRegression())])\n\nX = data.drop('survived', axis=1)\ny = data['survived']\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n\nclf.fit(X_train, y_train)\nprint(\"model score: %.3f\" % clf.score(X_test, y_test))"
29+
"# Author: Pedro Morales <[email protected]>\n#\n# License: BSD 3 clause\n\nimport numpy as np\n\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler, OneHotEncoder\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split, GridSearchCV\n\nnp.random.seed(0)\n\n# Read data from Titanic dataset.\ntitanic = fetch_openml(data_id=40945, as_frame=True)\nX, y = titanic.data, titanic.target\n\n# Alternatively X and y can be obtained directly from the frame attribute:\n# X = titanic.frame.drop('survived', axis=1)\n# y = titanic.frame['survived']\n\n# We will train our classifier with the following features:\n# Numeric Features:\n# - age: float.\n# - fare: float.\n# Categorical Features:\n# - embarked: categories encoded as strings {'C', 'S', 'Q'}.\n# - sex: categories encoded as strings {'female', 'male'}.\n# - pclass: ordinal integers {1, 2, 3}.\n\n# We create the preprocessing pipelines for both numeric and categorical data.\nnumeric_features = ['age', 'fare']\nnumeric_transformer = Pipeline(steps=[\n ('imputer', SimpleImputer(strategy='median')),\n ('scaler', StandardScaler())])\n\ncategorical_features = ['embarked', 'sex', 'pclass']\ncategorical_transformer = Pipeline(steps=[\n ('imputer', SimpleImputer(strategy='constant', fill_value='missing')),\n ('onehot', OneHotEncoder(handle_unknown='ignore'))])\n\npreprocessor = ColumnTransformer(\n transformers=[\n ('num', numeric_transformer, numeric_features),\n ('cat', categorical_transformer, categorical_features)])\n\n# Append classifier to preprocessing pipeline.\n# Now we have a full prediction pipeline.\nclf = Pipeline(steps=[('preprocessor', preprocessor),\n ('classifier', LogisticRegression())])\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n\nclf.fit(X_train, y_train)\nprint(\"model score: %.3f\" % clf.score(X_test, y_test))"
3030
]
3131
},
3232
{

dev/_downloads/plot_column_transformer_mixed_types.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#
2525
# License: BSD 3 clause
2626

27-
import pandas as pd
2827
import numpy as np
2928

3029
from sklearn.compose import ColumnTransformer
30+
from sklearn.datasets import fetch_openml
3131
from sklearn.pipeline import Pipeline
3232
from sklearn.impute import SimpleImputer
3333
from sklearn.preprocessing import StandardScaler, OneHotEncoder
@@ -37,9 +37,12 @@
3737
np.random.seed(0)
3838

3939
# Read data from Titanic dataset.
40-
titanic_url = ('https://raw.githubusercontent.com/amueller/'
41-
'scipy-2017-sklearn/091d371/notebooks/datasets/titanic3.csv')
42-
data = pd.read_csv(titanic_url)
40+
titanic = fetch_openml(data_id=40945, as_frame=True)
41+
X, y = titanic.data, titanic.target
42+
43+
# Alternatively X and y can be obtained directly from the frame attribute:
44+
# X = titanic.frame.drop('survived', axis=1)
45+
# y = titanic.frame['survived']
4346

4447
# We will train our classifier with the following features:
4548
# Numeric Features:
@@ -71,9 +74,6 @@
7174
clf = Pipeline(steps=[('preprocessor', preprocessor),
7275
('classifier', LogisticRegression())])
7376

74-
X = data.drop('survived', axis=1)
75-
y = data['survived']
76-
7777
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
7878

7979
clf.fit(X_train, y_train)

dev/_downloads/scikit-learn-docs.pdf

5.14 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
98 Bytes
98 Bytes
0 Bytes
0 Bytes

0 commit comments

Comments
 (0)