本示例說明了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