我正在尝试使用GridSearchCV来优化我正在进行的分析,并且我已经读过它支持多种评分方法,并且我在其他地方(示例)找到了此方法的示例,但是当我尝试运行具有多个评分的GridSearchCV时应该支持多种格式的度量标准,它会引发错误:
File "/home/graduate/adsherma/miniconda2/envs/testenv/lib/python2.7/site-packages/sklearn/model_selection/_validation.py", line 288, in _score
score = scorer(estimator, X_test, y_test)
TypeError: 'dict' object is not callable
Run Code Online (Sandbox Code Playgroud)
我的源代码是:
DF = pd.read_pickle("OutPut/from_ntuples/nominal.pkl")
X = DF[RC.FittableParameters]
y = DF['isSignal']
pipe = Pipeline([
('reduce_dim', SelectKBest()),
('classify', AdaBoostClassifier())
])
BASE_ESTIMATORS = [DecisionTreeClassifier(max_depth=i) for i in range(1, 4)]
N_ESTIMATORS = range(100, 600, 100)
param_grid = [
{
'reduce_dim': [PCA()],
'reduce_dim__n_components': [1,10,20,30,40,50],
'classify__base_estimator': BASE_ESTIMATORS,
'classify__n_estimators': N_ESTIMATORS,
} ,
]
scoring = {'Precision': make_scorer(precision_score),
'Accuracy': make_scorer(accuracy_score)} #does not work
# …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的日志文件和流设置不同的记录器级别,并且我(似乎)遵循了演示(https://docs.python.org/3/howto/logging-cookbook.html)到点。但是,在我的实际代码中它不起作用。在测试脚本中运行这个演示是可行的:
import logging
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler('spam.log')
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
# add the handlers to logger
logger.addHandler(ch)
logger.addHandler(fh)
# 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
logger.critical('critical message')
print(logger.handlers)
print(logger)
Run Code Online (Sandbox Code Playgroud)
结果是
alex@alexpc:~/Projects/claritydb$ …Run Code Online (Sandbox Code Playgroud)