{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open in Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/justmarkham/scikit-learn-tips/master?filepath=notebooks%2F40_print_changed_only.ipynb)\n", "\n", "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/justmarkham/scikit-learn-tips/blob/master/notebooks/40_print_changed_only.ipynb)\n", "\n", "# 🤖⚡ scikit-learn tip #40 ([video](https://www.youtube.com/watch?v=9MW6Vpzbock&list=PL5-da3qGB5ID7YYAqireYEew2mWVvgmj6&index=40))\n", "\n", "New in version 0.23: Estimators only print the parameters that are \\*not\\* set to their default values.\n", "\n", "You can still see all parameters with get_params(), or restore the previous behavior with set_config().\n", "\n", "See example 👇" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from sklearn.linear_model import LogisticRegression" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "clf = LogisticRegression(C=0.1, solver='liblinear')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "LogisticRegression(C=0.1, solver='liblinear')" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# only prints parameters that have been changed from their default values\n", "clf" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'C': 0.1,\n", " 'class_weight': None,\n", " 'dual': False,\n", " 'fit_intercept': True,\n", " 'intercept_scaling': 1,\n", " 'l1_ratio': None,\n", " 'max_iter': 100,\n", " 'multi_class': 'auto',\n", " 'n_jobs': None,\n", " 'penalty': 'l2',\n", " 'random_state': None,\n", " 'solver': 'liblinear',\n", " 'tol': 0.0001,\n", " 'verbose': 0,\n", " 'warm_start': False}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# see all parameters\n", "clf.get_params()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "LogisticRegression(C=0.1, class_weight=None, dual=False, fit_intercept=True,\n", " intercept_scaling=1, l1_ratio=None, max_iter=100,\n", " multi_class='auto', n_jobs=None, penalty='l2',\n", " random_state=None, solver='liblinear', tol=0.0001, verbose=0,\n", " warm_start=False)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# restore the previous behavior\n", "from sklearn import set_config\n", "set_config(print_changed_only=False)\n", "clf" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Want more tips? [View all tips on GitHub](https://github.com/justmarkham/scikit-learn-tips) or [Sign up to receive 2 tips by email every week](https://scikit-learn.tips) 💌\n", "\n", "© 2020 [Data School](https://www.dataschool.io). All rights reserved." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.4" } }, "nbformat": 4, "nbformat_minor": 4 }