用户标准和“make_scorer”

时间:2018-05-21 09:49:34

标签: python scikit-learn

  1. 我是否需要将参数(y_true,y_pred)传递给«make_scorer»函数? 如果是这样,他们是如何传播的?如果可以举例。
  2. 如何在“评分”中设置自定义条件?
  3. 每次迭代的结果都是训练或测试的结果?
  4. _scorer = make_scorer(f1_score,pos_label=0)
    
    grid_searcher = GridSearchCV(clf, parameter_grid, verbose=200, scoring=_scorer)
    grid_searcher.fit(X_train, y_train)
    clf_best = grid_searcher.best_estimator_
    
    • 在流程中生成的每次迭代:
    [CV] class_weight=balanced, max_depth=10, n_estimators=100 ........... 
    [CV] class_weight=balanced, max_depth=10, n_estimators=100, score=0.4419706300331596, total= 16.4s 
    [Parallel(n_jobs=1)]: Done 12 out of 12 | elapsed: 1.7min remaining: 0.0s 
    [CV] class_weight=balanced, max_depth=10, n_estimators=150 > – user287629 47 mins ago  
    
    y_pred = clf.predict (X_test) 
    r = np.sum (y_pred == 0) & (y_pred == y_test) 
    s = np.sum (y_pred == 1) & (y_pred! = y_test) 
    z = r / s #I need to get a z 
    

2 个答案:

答案 0 :(得分:0)

试过这样,不起作用(经验不多):

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
def T_scorer(clf, X_test,y_test):
    y_pred = clf.predict(X_test)
    r = np.sum(y_pred == 0) & (y_pred == y_test)
    s = np.sum(y_pred == 1) & (y_pred!= y_test)
    z = r / s  # I need to get a z
    return z
clf = RandomForestClassifier()

grid_searcher = GridSearchCV(clf, parameter_grid, verbose=2, scoring=T_scorer)
grid_searcher.fit(X_test, y_test)

clf_best = grid_searcher.best_estimator_
print('Best params = ', clf_best.get_params())

答案 1 :(得分:0)

试试这个:

java -version