本示例说明了print_changed_only全局参数的用法。
将print_changed_only设置为True将更改估计器的表示,从而仅显示已设置为非默认值的参数。
这可以用来输出(打印)更紧凑的模型表示形式,方便检查模型参数的设置情况。
代码实现[Python]
# -*- coding: utf-8 -*-
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')
运行程序
运行时间大约:0分0.003秒。
运行输出的文本内容如下:
Default representation: 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) With changed_only option: LogisticRegression(penalty='l1')
源码下载
- Python版源码文件: plot_changed_only_pprint_parameter.py
- Jupyter Notebook版源码文件: plot_changed_only_pprint_parameter.ipynb