Skip to content
Closed
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: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: ML Pipeline CI

on:
# push:
# branches: [ main, master ]
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

Expand Down
Binary file added day5/演習3/models/titanic_model_prev.pkl
Binary file not shown.
12 changes: 8 additions & 4 deletions day5/演習3/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DATA_PATH = os.path.join(os.path.dirname(__file__), "../data/Titanic.csv")
MODEL_DIR = os.path.join(os.path.dirname(__file__), "../models")
MODEL_PATH = os.path.join(MODEL_DIR, "titanic_model.pkl")
MODEL_PATH2 = os.path.join(MODEL_DIR, "titanic_model_prev.pkl")


@pytest.fixture
Expand Down Expand Up @@ -108,6 +109,10 @@ def test_model_exists():
pytest.skip("モデルファイルが存在しないためスキップします")
assert os.path.exists(MODEL_PATH), "モデルファイルが存在しません"

if not os.path.exists(MODEL_PATH2):
pytest.skip("前回のモデルファイルが存在しないためスキップします")
assert os.path.exists(MODEL_PATH2), "前回のモデルファイルが存在しません"


def test_model_accuracy(train_model):
"""モデルの精度を検証"""
Expand All @@ -116,6 +121,7 @@ def test_model_accuracy(train_model):
# 予測と精度計算
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(f"モデルの精度: {accuracy:.4f}")

# Titanicデータセットでは0.75以上の精度が一般的に良いとされる
assert accuracy >= 0.75, f"モデルの精度が低すぎます: {accuracy}"
Expand All @@ -131,7 +137,7 @@ def test_model_inference_time(train_model):
end_time = time.time()

inference_time = end_time - start_time

print(f"推論時間: {inference_time:.4f}秒")
# 推論時間が1秒未満であることを確認
assert inference_time < 1.0, f"推論時間が長すぎます: {inference_time}秒"

Expand Down Expand Up @@ -168,6 +174,4 @@ def test_model_reproducibility(sample_data, preprocessor):
predictions1 = model1.predict(X_test)
predictions2 = model2.predict(X_test)

assert np.array_equal(
predictions1, predictions2
), "モデルの予測結果に再現性がありません"
assert np.array_equal(predictions1, predictions2), "モデルの予測結果に再現性がありません"
Loading