0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【量子AI #20】古典ML vs QML ベンチマーク比較の実装

0
Posted at

8. パフォーマンスベンチマーク

8.1 古典MLとQMLの比較実験

import time, numpy as np, pandas as pd
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score

class QMLBenchmark:
    def __init__(self, n_features=32, n_samples=500):
        self.n_features = n_features; self.n_samples = n_samples

    def benchmark_classical(self, X, y):
        scaler = StandardScaler()
        Xs = scaler.fit_transform(X)
        models = {
            "SVM (RBF)": SVC(kernel='rbf', probability=True, class_weight='balanced'),
            "Random Forest": RandomForestClassifier(n_estimators=100, class_weight='balanced'),
            "Gradient Boosting": GradientBoostingClassifier(n_estimators=100),
            "MLP (Classical NN)": MLPClassifier(hidden_layer_sizes=(64,32,16), max_iter=500)
        }
        results = {}
        for name, model in models.items():
            t0 = time.perf_counter()
            scores = cross_val_score(model, Xs, y, cv=5, scoring='roc_auc')
            elapsed = time.perf_counter() - t0
            results[name] = {"roc_auc": scores.mean(), "std": scores.std(), "time": elapsed}
            print(f"{name:25s}: ROC-AUC={scores.mean():.4f}+/-{scores.std():.4f} ({elapsed:.1f}s)")
        return results

benchmark = QMLBenchmark(n_features=32, n_samples=500)
pipeline = ManufacturingQMLPipeline(n_features=32)
X, y = pipeline.generate_synthetic_sensor_data(n_samples=500)
print(f"データセット: {X.shape} | 不良率: {y.mean():.1%}")
results = benchmark.benchmark_classical(X, y)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?