Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 模型定义不提供任何输出_Python_Scikit Learn - Fatal编程技术网

Python 模型定义不提供任何输出

Python 模型定义不提供任何输出,python,scikit-learn,Python,Scikit Learn,以上代码的输出只是 from sklearn.linear_model import LogisticRegression logmodel = LogisticRegression() logmodel 但我希望得到更详细的信息,包括模型参数,即: LogisticRegression() 我做错了什么?这是由于scikit学习v0.23版以后的默认设置发生了更改;从: 默认设置print\u changed\u only已从False更改为True。这意味着估计器的repr现在更加简洁,

以上代码的输出只是

from sklearn.linear_model import LogisticRegression
logmodel = LogisticRegression()
logmodel
但我希望得到更详细的信息,包括模型参数,即:

LogisticRegression()

我做错了什么?

这是由于scikit学习v0.23版以后的默认设置发生了更改;从:

默认设置
print\u changed\u only
已从False更改为True。这意味着估计器的
repr
现在更加简洁,只显示在打印估计器时默认值已更改的参数。您可以使用
sklearn.set\u config(print\u changed\u only=False)
恢复以前的行为。另外,请注意,始终可以使用
est.get_params(deep=False)
快速检查任何估计器的参数

换句话说,在v0.23之前的版本中,以下代码:

LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
                   intercept_scaling=1, l1_ratio=None, max_iter=100,
                   multi_class='auto', n_jobs=None, penalty='l2',
                   random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
                   warm_start=False)
使用所有模型参数生成以下输出:

import sklearn
sklearn.__version__
# 0.22.2

from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr
但v0.23以后的代码相同:

LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
                   intercept_scaling=1, l1_ratio=None, max_iter=100,
                   multi_class='auto', n_jobs=None, penalty='l2',
                   random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
                   warm_start=False)
将产生以下结果:

import sklearn
sklearn.__version__
# 0.23.2

from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr
在这里这样的情况下,即没有明确定义参数,并且所有参数都保持默认值。这是因为
print\u changed\u only
参数现在默认设置为
True

LogisticRegression()
要在较新的scikit学习版本中打印所有参数,您应该

sklearn.get_config()

# result:

{'assume_finite': False,
 'working_memory': 1024,
 'print_changed_only': True,
 'display': 'text'}
或更改设置(最好,因为它会影响以后使用的任何和所有型号):

lr.get_params()

# result

{'C': 1.0,
 'class_weight': None,
 'dual': False,
 'fit_intercept': True,
 'intercept_scaling': 1,
 'l1_ratio': None,
 'max_iter': 100,
 'multi_class': 'auto',
 'n_jobs': None,
 'penalty': 'l2',
 'random_state': None,
 'solver': 'lbfgs',
 'tol': 0.0001,
 'verbose': 0,
 'warm_start': False}
sklearn.set_config(print_changed_only=False) # needed only once
lr # as defined above

# result

LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
                   intercept_scaling=1, l1_ratio=None, max_iter=100,
                   multi_class='auto', n_jobs=None, penalty='l2',
                   random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
                   warm_start=False)