scikit-learn/examples/plot_changed_only_pprint_pa...

31 lines
1.0 KiB
Python
Raw Normal View History

[MRG] Add pprint for estimators - continued (#11705) * add pprint for estimators * strip color from length, add color option * Minor cleaning, fixes, factoring and docs * Added some basic tests * Fixed line length issue * fixed flake8 and added visual test for review * Fixed test * Fixed Python 2 issues (inspect.signature import) * Trying to fix flake8 again * Added special repr for functions * Added some other visual tests * Changed _format_function in to _format_callable because callable() returns True also for class objects (which we want to reprensent with their name as well anyway) * Consistent output in Python 2 and 3 * WIP * Now using the builtin pprint module * pep8 * Added changed_only param * Fixed printing when string would fit in less than line width * Fixed printing of steps parameter * Fixed changed_only param for short estimators * fixed pep8 * Added some more description in docstring * changed_only is now an option from set_config() * Put _pprint.py into sklearn/utils, added tests * Added doctest NORMALIZE_WHITESPACE where needed * Fixed tests * fix test-doc * fixing test that passed before.... * Fixed tests * Added test for changed_only and long lines * typo * Added authors names * Added license file * Added ellipsis based on number of elements in sequence + added increasinly aggressive repr strategies * Updated whatsnew * dont use increaingly aggressive strategy * Fixed tests * Removed LICENSE file and put license text in _pprint.py * fixed test_base * Sorted parameters dictionary for consistent output in 3.5 * Actually using OrderedDict... * Addressed comments * Added test for NaN changed parameter * Update whatsnew * Added example to set_config() * Removed example * Added example in gallery * Spelling
2018-12-20 12:48:21 +08:00
"""
=================================
Compact estimator representations
=================================
This example illustrates the use of the print_changed_only global parameter.
Setting print_changed_only to True will alterate the representation of
estimators to only show the parameters that have been set to non-default
values. This can be used to have more compact representations.
"""
print(__doc__)
from sklearn.linear_model import LogisticRegression
from sklearn import set_config
lr = LogisticRegression(penalty='l1')
print('Default representation:')
print(lr)
# LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
# intercept_scaling=1, l1_ratio=None, max_iter=100,
# multi_class='warn', n_jobs=None, penalty='l1',
# random_state=None, solver='warn', tol=0.0001, verbose=0,
# warm_start=False)
set_config(print_changed_only=True)
print('\nWith changed_only option:')
print(lr)
# LogisticRegression(penalty='l1')