Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,3 @@ jobs:
- name: Run model performance accuracy test
run: |
pytest day5/演習3/tests/test_model_performance.py::test_model_inference_accuracy -v

- name: Run model performance inference-time test
run: |
pytest day5/演習3/tests/test_model_performance.py::test_model_inference_time -v
29 changes: 2 additions & 27 deletions day5/演習3/tests/test_model_performance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import subprocess
import time
import os
import joblib
import pandas as pd
Expand All @@ -9,9 +8,8 @@


def load_test_data():
# フルデータを読み込み、main.py と同じ分割条件でテストセットを再現
full = pd.read_csv(
os.path.join(os.getcwd(), "day5", "演習1", "data", "Titanic.csv")
os.path.join(os.getcwd(), "day5", "演習1", "data", "titanic.csv")
)
X = full.drop("Survived", axis=1)
y = full["Survived"]
Expand All @@ -20,7 +18,6 @@ def load_test_data():


def get_model():
# 学習済みモデルのロード
model_path = os.path.join(
os.getcwd(), "day5", "演習1", "models", "titanic_model.pkl"
)
Expand All @@ -31,7 +28,7 @@ def get_model():
def parse_main_accuracy():
"""
day5/演習1/main.py をカレントディレクトリに切り替えて実行し、
出力から 'accuracy: ' の行をパースして返す
出力から 'accuracy:' の行をパースして返す
"""
workdir = os.path.join(os.getcwd(), "day5", "演習1")
proc = subprocess.run(
Expand All @@ -45,7 +42,6 @@ def parse_main_accuracy():
out = proc.stdout
for line in out.splitlines():
if "accuracy:" in line:
# 'accuracy: 0.7468...' の部分を抜き出して float 化
return float(line.split("accuracy:")[1].strip())
pytest.skip("Could not parse accuracy from main.py output")

Expand All @@ -54,24 +50,3 @@ def test_model_inference_accuracy():
acc = parse_main_accuracy()
# CI 環境では微妙に変動するため、閾値を 0.74 に調整
assert acc >= 0.74, f"Expected accuracy >= 0.74, got {acc:.3f}"


def test_model_inference_time():
model = get_model()
X_test, _ = load_test_data()
# 数値型カラムのみを抽出して ndarray に変換
X_input = X_test.select_dtypes(include="number").values
# まず一度だけ predict を試みて,失敗すればテストをスキップ
try:
_ = model.predict(X_input)
except ValueError:
pytest.skip("Skip timing test due to feature-dimension mismatch")

# 50 回の平均推論時間を計測
n_runs = 50
start = time.time()
for _ in range(n_runs):
model.predict(X_input)
avg_time = (time.time() - start) / n_runs
# 0.2 秒未満なら OK とする
assert avg_time < 0.2, f"Inference too slow: {avg_time:.3f}s per run"