始める無料で始める

Contamination をもう一度

one-class SVM にはcontaminationパラメータがないことに気づきます。しかし、偽陽性率をコントロールするには、新規と判定されるサンプルの割合を制御する方法が必要だと、すでに理解しています。そこで、スコアにしきい値を設ける方法を試すことにします。検出器はonesvmとしてインポート済みで、X_trainX_testy_trainy_testnumpynp、さらにconfusion_matrix()が利用できます。

この演習はコースの一部です

Python で設計する Machine Learning ワークフロー

コースを見る

演習の手順

  • 1-class SVM を学習し、テストデータのスコアを計算します。
  • テストデータにおける外れ値の観測割合を計算します。
  • その割合になるようにスコアのしきい値を見つけるため、np.quantile()を使います。
  • 得られたしきい値でテストデータにラベルを付けます。混同行列を出力してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Fit a one-class SVM detector and score the test data
nov_det = ____(X_train)
scores = ____(X_test)

# Find the observed proportion of outliers in the test data
prop = np.____(y_test==____)

# Compute the appropriate threshold
threshold = np.____(____, ____)

# Print the confusion matrix for the thresholded scores
print(confusion_matrix(y_test, ____ > ____))
コードを編集して実行