【问题标题】:Using Keras/sklearn with CalibratedClassifierCV from sklearn.calibration使用 Keras/sklearn 和来自 sklearn.calibration 的 CalibratedClassifierCV
【发布时间】:2018-04-16 18:03:51
【问题描述】:

是否可以将 Keras 模型对象与来自 sklearn.calibration 的 CalibratedClassifierCV 一起使用?或者是否有另一种方法可以在 sklearn/其他 python 包中执行等渗回归,而无需将模型对象传递给它。

我尝试使用 Keras 的 sklearn 包装器,但它不起作用。 Here is the doc for the CalibratedClassifierCV class.

【问题讨论】:

  • 您能否详细说明您的问题?简而言之,您想知道如何将 Keras 发出的模型作为base_estimator 的输入传递给CalibratedClassifierCV?您可能对此感兴趣:machinelearningmastery.com/…

标签: keras scikit-learn


【解决方案1】:

您可以在预测后后验训练等渗回归。让 'file1' 成为一个 csv,其中包含您对数据子集的预测 pred 和实际观察到的事件 obs。理想情况下,这个子集以前从未使用过(甚至在 Keras 训练中也没有使用过)。让file2 包含您要校准的预测(测试集的 Keras 预测)。

    import pandas as pd
    from sklearn.isotonic import IsotonicRegression
    never_seen=pd.read_csv('file1') 
    uncalibrated=pd.read_csv('file2')   
    
    ir = IsotonicRegression( out_of_bounds = 'clip' )   
    ir.fit( never_seen.pred,never_seen.obs )
    p_calibrated = ir.transform( uncalibrated.pred )

【讨论】:

    猜你喜欢
    • 2015-07-04
    • 2022-01-09
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2018-11-03
    • 1970-01-01
    • 2018-09-16
    相关资源
    最近更新 更多