PythonライブラリのRocCurveクラスでF1最大化の閾値ではなく、MCC最大化の閾値を取得する方法を知りたいです。F1最大化は下記メソッドがありますが、get_best_mcc_threshold()メソッドはないようなので。
roc = model.get_roc_curve('validation') threshold = roc.get_best_f1_threshold()
dir(roc)
['__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_client', '_converter', '_fields', '_filter_data', '_repack_insights_response', '_safe_data', '_server_data', '_validate_threshold', 'estimate_threshold', 'from_data', 'from_location', 'from_server_data', 'get_best_f1_threshold', 'negative_class_predictions', 'positive_class_predictions', 'roc_points', 'source', 'source_model_id']
Pythonライブラリバージョンは3.2.1を使ってます。
解決済! 解決策の投稿を見る。
ご質問いただきありがとうございます。以下のコードでいかがでしょうか。
import pandas as pd import datarobot as dr from datarobot.enums import ACCURACY_METRIC from sklearn.datasets import load_breast_cancer # 乳がんデータセットをロード breast_cancer = load_breast_cancer() X = breast_cancer.data y = breast_cancer.target # 特徴量をDataFrameに変換 breast_cancer_df = pd.DataFrame(X, columns=breast_cancer.feature_names) # 目的変数をDataFrameに追加 breast_cancer_df['target'] = y # DataRobotプロジェクトを作成 project = dr.Project.create(sourcedata=breast_cancer_df, project_name="Breast Cancer Classification") # モデルの分析とトレーニングを開始 project.analyze_and_model( target="target", metric=ACCURACY_METRIC.AUC, worker_count=-1, ) # AutoPilotの完了を待つ project.wait_for_autopilot() # ベストモデルを取得 best_model = project.get_models()[0] # ROC曲線を取得 roc = best_model.get_roc_curve('validation').roc_points # MCC を最大化するエントリを探す max_mcc = max(roc, key=lambda x: x['matthews_correlation_coefficient']) # その際のthresholdを出力 max_mcc["threshold"]
ありがとうございます!実現できました!