active-learning-system について
機械学習の実務者向けのアクティブラーニングスキルです。サンプル選択戦略、ラベリングの反復、性能監視を扱い、不確実性やモデル間の不一致、特徴の多様性に基づく選択を説明します。
主な機能
- 01不確実性サンプリング
- 02委員会の不一致によるサンプリング
- 03期待モデル変化の戦略
- 04多様性に基づくサンプル選択
- 05性能とアノテーションコストの監視
活用シーン
- 01人手ラベリング用の有益な例の選定
- 02アンサンブルの不一致による未ラベルデータの抽出
- 03モデル性能とアノテーションコストの追跡
- 04初期サンプルとバッチサイズの計画
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ dengineproblem/ agents-monorepo --skill active-learning-systemインストール後、Claude Code で/active-learning-systemを入力して読み込まれたか確認します。
詳細
アクティブラーニングシステムのエキスパート
機械学習のアクティブラーニングシステムのエキスパートです。
主な戦略
- 不確実性サンプリング:モデルの確信度が最も低いサンプルを選択します
- クエリ・バイ・コミッティ:アンサンブルの意見の相違を利用します
- 期待モデル変化:最も情報量の多いサンプルを選択します
- 多様性に基づく選択:特徴空間を網羅します
アクティブラーニングの基本サイクル
from modAL import ActiveLearner
from modAL.uncertainty import uncertainty_sampling
class ActiveLearningSystem:
def __init__(self, initial_labeled_pool, unlabeled_pool):
self.labeled_X, self.labeled_y = initial_labeled_pool
self.unlabeled_X = unlabeled_pool
self.learner = ActiveLearner(
estimator=RandomForestClassifier(n_estimators=100),
query_strategy=uncertainty_sampling,
X_training=self.labeled_X,
y_training=self.labeled_y
)
def query_and_update(self, batch_size=10, oracle_func=None):
query_indices = []
temp_unlabeled = self.unlabeled_X.copy()
for _ in range(min(batch_size, len(temp_unlabeled))):
query_idx, query_instance = self.learner.query(temp_unlabeled)
query_indices.append(query_idx)
temp_unlabeled = np.delete(temp_unlabeled, query_idx, axis=0)
queried_X = self.unlabeled_X[query_indices]
queried_y = oracle_func(queried_X) if oracle_func else self.simulate_oracle(queried_X)
self.learner.teach(queried_X, queried_y)
self.unlabeled_X = np.delete(self.unlabeled_X, query_indices, axis=0)
return query_indices, queried_X, queried_y
クエリ・バイ・コミッティ
class CommitteeActiveLearner:
def __init__(self, X_initial, y_initial):
self.committee = [
RandomForestClassifier(n_estimators=50),
GradientBoostingClassifier(n_estimators=50),
SVC(probability=True)
]
for clf in self.committee:
clf.fit(X_initial, y_initial)
def query_by_committee(self, X_pool, n_instances=1):
disagreements = []
for x in X_pool:
predictions = [clf.predict_proba([x])[0] for clf in self.committee]
avg_pred = np.mean(predictions, axis=0)
disagreement = -np.sum(avg_pred * np.log(avg_pred + 1e-10))
disagreements.append(disagreement)
selected_indices = np.argsort(disagreements)[-n_instances:]
return selected_indices, X_pool[selected_indices]
パフォーマンスのモニタリング
class ActiveLearningMonitor:
def track_performance(self, model, X_test, y_test, n_annotations):
accuracy = accuracy_score(y_test, model.predict(X_test))
self.performance_history.append(accuracy)
self.annotation_costs.append(n_annotations)
def calculate_learning_efficiency(self):
performance_gains = np.diff(self.performance_history)
annotation_increments = np.diff(self.annotation_costs)
efficiency = performance_gains / annotation_increments
return {
'current_efficiency': efficiency[-1],
'average_efficiency': np.mean(efficiency),
'efficiency_trend': np.polyfit(range(len(efficiency)), efficiency, 1)[0]
}
def suggest_stopping_criterion(self):
efficiency = self.calculate_learning_efficiency()
if efficiency['current_efficiency'] < 0.001:
return "Consider stopping - low marginal gains"
return "Continue learning"
ベストプラクティス
コールドスタート戦略
- 初期セットには層化サンプリングを使用します
- すべてのクラスが含まれるようにします
- クラスごとに最低5~10個のサンプルから始めます
バッチサイズの最適化
- 不確実性が高い場合は小さなバッチ(5~20)を使用します
- アノテーションのコストが高い場合は大きなバッチ(50~100)を使用します
- アノテーターの疲労を考慮します
よくある落とし穴
- クラスの不均衡を無視する
- キャリブレーションせずに確信度に過度に依存する
- アノテーター間の一致を軽視する
- アノテーションのノイズを考慮しない
コメント
Markdown 対応