| name | scientific-semi-supervised-learning |
| description | 半教師あり学習スキル。Self-Training・Label Propagation・
MixMatch/FixMatch・Pseudo-Labeling・ラベル効率評価。
|
| tu_tools | [{"key":"openml","name":"OpenML","description":"半教師あり学習ベンチマーク"}] |
Scientific Semi-Supervised Learning
少量のラベル付きデータと大量の未ラベルデータを活用する
半教師あり学習パイプラインを提供する。
When to Use
- ラベル付きデータが少量しかないとき
- アノテーションコストが高く全量ラベリングが困難なとき
- Self-Training で反復的にラベルを拡張するとき
- グラフベースの Label Propagation を適用するとき
- Pseudo-Labeling の信頼度閾値を設計するとき
Quick Start
1. Self-Training パイプライン
import numpy as np
import pandas as pd
from sklearn.base import clone
from sklearn.metrics import accuracy_score, classification_report
def self_training_pipeline(X_labeled, y_labeled, X_unlabeled,
base_estimator=None, threshold=0.95,
max_iterations=10, batch_size=None,
X_test=None, y_test=None):
"""
Self-Training 半教師あり学習。
Parameters:
X_labeled: np.ndarray — ラベル付き特徴量
y_labeled: np.ndarray — ラベル
X_unlabeled: np.ndarray — 未ラベル特徴量
base_estimator: sklearn estimator | None — 基底分類器
threshold: float — Pseudo-Label 採用閾値
max_iterations: int — 最大反復回数
batch_size: int | None — 各反復で追加するサンプル数上限
X_test: np.ndarray | None — テスト特徴量
y_test: np.ndarray | None — テストラベル
"""
sklearn.ensemble GradientBoostingClassifier
base_estimator :
base_estimator = GradientBoostingClassifier(
n_estimators=, random_state=)
X_train = X_labeled.copy()
y_train = y_labeled.copy()
X_pool = X_unlabeled.copy()
history = []
iteration (max_iterations):
(X_pool) == :
()
model = clone(base_estimator)
model.fit(X_train, y_train)
proba = model.predict_proba(X_pool)
max_proba = proba.(axis=)
pseudo_labels = proba.argmax(axis=)
confident_mask = max_proba >= threshold
n_confident = confident_mask.()
batch_size n_confident > batch_size:
top_idx = np.argsort(max_proba)[-batch_size:]
confident_mask = np.zeros((X_pool), dtype=)
confident_mask[top_idx] =
n_confident = batch_size
n_confident == :
()
X_train = np.vstack([X_train, X_pool[confident_mask]])
y_train = np.concatenate([
y_train, pseudo_labels[confident_mask]])
X_pool = X_pool[~confident_mask]
record = {: iteration,
: (X_train),
: (X_pool),
: (n_confident),
: (max_proba[confident_mask].mean())}
X_test y_test :
test_acc = accuracy_score(y_test, model.predict(X_test))
record[] = test_acc
history.append(record)
(
)
final_model = clone(base_estimator)
final_model.fit(X_train, y_train)
final_model, pd.DataFrame(history)