.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/miscellaneous/plot_pipeline_display.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_miscellaneous_plot_pipeline_display.py: ==================== عرض خطوط الأنابيب ==================== تكوين العرض الافتراضي لخط الأنابيب في دفتر Jupyter هو `'diagram'` حيث `set_config(display='diagram')`. لإلغاء تنشيط التمثيل HTML، استخدم `set_config(display='text')`. لمشاهدة خطوات أكثر تفصيلاً في تصور خط الأنابيب، انقر على الخطوات في خط الأنابيب. .. GENERATED FROM PYTHON SOURCE LINES 13-16 .. code-block:: Python # المؤلفون: مطوري scikit-learn # معرف SPDX-License: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 17-22 عرض خط أنابيب مع خطوة ما قبل المعالجة والتصنيف ############################################################## يقوم هذا القسم ببناء :class:`~sklearn.pipeline.Pipeline` مع خطوة ما قبل المعالجة ، :class:`~sklearn.preprocessing.StandardScaler`، والتصنيف، :class:`~sklearn.linear_model.LogisticRegression`، ويعرض تمثيله المرئي. .. GENERATED FROM PYTHON SOURCE LINES 22-34 .. code-block:: Python from sklearn import set_config from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler steps = [ ("preprocessing", StandardScaler()), ("classifier", LogisticRegression()), ] pipe = Pipeline(steps) .. GENERATED FROM PYTHON SOURCE LINES 35-36 لعرض المخطط، الافتراضي هو `display='diagram'`. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python set_config(display="diagram") pipe # انقر على المخطط أدناه لمشاهدة تفاصيل كل خطوة .. raw:: html
Pipeline(steps=[('preprocessing', StandardScaler()),
                    ('classifier', LogisticRegression())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 40-41 لمشاهدة خط الأنابيب النصي، قم بتغييره إلى `display='text'`. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python set_config(display="text") pipe .. rst-class:: sphx-glr-script-out .. code-block:: none Pipeline(steps=[('preprocessing', StandardScaler()), ('classifier', LogisticRegression())]) .. GENERATED FROM PYTHON SOURCE LINES 45-46 إعادة إعداد العرض الافتراضي .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python set_config(display="diagram") .. GENERATED FROM PYTHON SOURCE LINES 49-55 عرض خط أنابيب يربط بين خطوات ما قبل المعالجة والتصنيف ######################################################################## يقوم هذا القسم ببناء :class:`~sklearn.pipeline.Pipeline` مع خطوات متعددة ما قبل المعالجة، :class:`~sklearn.preprocessing.PolynomialFeatures` و :class:`~sklearn.preprocessing.StandardScaler`، وخطوة التصنيف، :class:`~sklearn.linear_model.LogisticRegression`، ويعرض تمثيله المرئي. .. GENERATED FROM PYTHON SOURCE LINES 55-68 .. code-block:: Python from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline from sklearn.preprocessing import PolynomialFeatures, StandardScaler steps = [ ("standard_scaler", StandardScaler()), ("polynomial", PolynomialFeatures(degree=3)), ("classifier", LogisticRegression(C=2.0)), ] pipe = Pipeline(steps) pipe # انقر على المخطط أدناه لمشاهدة تفاصيل كل خطوة .. raw:: html
Pipeline(steps=[('standard_scaler', StandardScaler()),
                    ('polynomial', PolynomialFeatures(degree=3)),
                    ('classifier', LogisticRegression(C=2.0))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 69-74 عرض خط أنابيب وخفض الأبعاد والتصنيف ################################################################# يقوم هذا القسم ببناء :class:`~sklearn.pipeline.Pipeline` مع خطوة خفض الأبعاد، :class:`~sklearn.decomposition.PCA`، ، :class:`~sklearn.svm.SVC`، ويعرض تمثيله المرئي. .. GENERATED FROM PYTHON SOURCE LINES 74-83 .. code-block:: Python from sklearn.decomposition import PCA from sklearn.pipeline import Pipeline from sklearn.svm import SVC steps = [("reduce_dim", PCA(n_components=4)), ("classifier", SVC(kernel="linear"))] pipe = Pipeline(steps) pipe # انقر على المخطط أدناه لمشاهدة تفاصيل كل خطوة .. raw:: html
Pipeline(steps=[('reduce_dim', PCA(n_components=4)),
                    ('classifier', SVC(kernel='linear'))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 84-89 عرض خط أنابيب معقد يربط بين محول الأعمدة ########################################################### يقوم هذا القسم ببناء خط أنابيب معقد :class:`~sklearn.pipeline.Pipeline` مع :class:`~sklearn.compose.ColumnTransformer` والتصنيف، :class:`~sklearn.linear_model.LogisticRegression`، ويعرض تمثيله المرئي. .. GENERATED FROM PYTHON SOURCE LINES 89-125 .. code-block:: Python import numpy as np from sklearn.compose import ColumnTransformer from sklearn.impute import SimpleImputer from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline, make_pipeline from sklearn.preprocessing import OneHotEncoder, StandardScaler numeric_preprocessor = Pipeline( steps=[ ("imputation_mean", SimpleImputer(missing_values=np.nan, strategy="mean")), ("scaler", StandardScaler()), ] ) categorical_preprocessor = Pipeline( steps=[ ( "imputation_constant", SimpleImputer(fill_value="missing", strategy="constant"), ), ("onehot", OneHotEncoder(handle_unknown="ignore")), ] ) preprocessor = ColumnTransformer( [ ("categorical", categorical_preprocessor, ["state", "gender"]), ("numerical", numeric_preprocessor, ["age", "weight"]), ] ) pipe = make_pipeline(preprocessor, LogisticRegression(max_iter=500)) pipe # انقر على المخطط أدناه لمشاهدة تفاصيل كل خطوة .. raw:: html
Pipeline(steps=[('columntransformer',
                     ColumnTransformer(transformers=[('categorical',
                                                      Pipeline(steps=[('imputation_constant',
                                                                       SimpleImputer(fill_value='missing',
                                                                                     strategy='constant')),
                                                                      ('onehot',
                                                                       OneHotEncoder(handle_unknown='ignore'))]),
                                                      ['state', 'gender']),
                                                     ('numerical',
                                                      Pipeline(steps=[('imputation_mean',
                                                                       SimpleImputer()),
                                                                      ('scaler',
                                                                       StandardScaler())]),
                                                      ['age', 'weight'])])),
                    ('logisticregression', LogisticRegression(max_iter=500))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 126-131 عرض بحث شبكي عبر خط أنابيب مع تصنيف ########################################################## يقوم هذا القسم ببناء :class:`~sklearn.model_selection.GridSearchCV` عبر :class:`~sklearn.pipeline.Pipeline` مع :class:`~sklearn.ensemble.RandomForestClassifier` ويعرض تمثيله المرئي. .. GENERATED FROM PYTHON SOURCE LINES 131-177 .. code-block:: Python import numpy as np from sklearn.compose import ColumnTransformer from sklearn.ensemble import RandomForestClassifier from sklearn.impute import SimpleImputer from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline, make_pipeline from sklearn.preprocessing import OneHotEncoder, StandardScaler numeric_preprocessor = Pipeline( steps=[ ("imputation_mean", SimpleImputer(missing_values=np.nan, strategy="mean")), ("scaler", StandardScaler()), ] ) categorical_preprocessor = Pipeline( steps=[ ( "imputation_constant", SimpleImputer(fill_value="missing", strategy="constant"), ), ("onehot", OneHotEncoder(handle_unknown="ignore")), ] ) preprocessor = ColumnTransformer( [ ("categorical", categorical_preprocessor, ["state", "gender"]), ("numerical", numeric_preprocessor, ["age", "weight"]), ] ) pipe = Pipeline( steps=[("preprocessor", preprocessor), ("classifier", RandomForestClassifier())] ) param_grid = { "classifier__n_estimators": [200, 500], "classifier__max_features": ["auto", "sqrt", "log2"], "classifier__max_depth": [4, 5, 6, 7, 8], "classifier__criterion": ["gini", "entropy"], } grid_search = GridSearchCV(pipe, param_grid=param_grid, n_jobs=1) grid_search # انقر على المخطط أدناه لمشاهدة تفاصيل كل خطوة .. raw:: html
GridSearchCV(estimator=Pipeline(steps=[('preprocessor',
                                            ColumnTransformer(transformers=[('categorical',
                                                                             Pipeline(steps=[('imputation_constant',
                                                                                              SimpleImputer(fill_value='missing',
                                                                                                            strategy='constant')),
                                                                                             ('onehot',
                                                                                              OneHotEncoder(handle_unknown='ignore'))]),
                                                                             ['state',
                                                                              'gender']),
                                                                            ('numerical',
                                                                             Pipeline(steps=[('imputation_mean',
                                                                                              SimpleImputer()),
                                                                                             ('scaler',
                                                                                              StandardScaler())]),
                                                                             ['age',
                                                                              'weight'])])),
                                           ('classifier',
                                            RandomForestClassifier())]),
                 n_jobs=1,
                 param_grid={'classifier__criterion': ['gini', 'entropy'],
                             'classifier__max_depth': [4, 5, 6, 7, 8],
                             'classifier__max_features': ['auto', 'sqrt', 'log2'],
                             'classifier__n_estimators': [200, 500]})
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.156 seconds) .. _sphx_glr_download_auto_examples_miscellaneous_plot_pipeline_display.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/miscellaneous/plot_pipeline_display.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/miscellaneous/plot_pipeline_display.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pipeline_display.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pipeline_display.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_pipeline_display.zip ` .. include:: plot_pipeline_display.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_