diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4aad9943..649feecf7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pytest great_expectations pandas scikit-learn flake8 black mypy pytest-cov + pip install mlflow numpy tensorflow if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 @@ -39,3 +40,13 @@ jobs: - name: Run model tests run: | pytest day5/演習3/tests/test_model.py -v + + # 追加: モデルの推論精度・時間の検証 + - name: Run model inference tests + run: | + pytest day5/演習3/tests/test_model_inference.py -v + + # 追加: モデルのパフォーマンス比較テスト + - name: Run model performance comparison + run: | + pytest day5/演習3/tests/test_model_comparison.py -v \ No newline at end of file diff --git "a/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" "b/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" index 6fec87e47..f65bd0469 100644 Binary files "a/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" and "b/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" differ diff --git "a/day5/\346\274\224\347\277\2222/black_check.py" "b/day5/\346\274\224\347\277\2222/black_check.py" index 3158f952d..910a40c3a 100644 --- "a/day5/\346\274\224\347\277\2222/black_check.py" +++ "b/day5/\346\274\224\347\277\2222/black_check.py" @@ -1,7 +1,18 @@ +def say_hello(name): + print("Hello," + name + "!") # greet + + +def say_hello(name): + print("Hello," + name + "!") # greet + + +def add(a, b): + return a + b + + +def add(a, b): + return a + b + -def say_hello(name):print("Hello,"+name+"!") # greet -def say_hello(name):print("Hello," + name +"!") # greet -def add( a,b):return a+b -def add( a , b ):return a+b def add(a, b): - return a+b \ No newline at end of file + return a + b diff --git "a/day5/\346\274\224\347\277\2222/main.py" "b/day5/\346\274\224\347\277\2222/main.py" index 776b70e75..2b256b6c5 100644 --- "a/day5/\346\274\224\347\277\2222/main.py" +++ "b/day5/\346\274\224\347\277\2222/main.py" @@ -11,6 +11,7 @@ import time import great_expectations as gx + class DataLoader: """データロードを行うクラス""" diff --git "a/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" "b/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" index 9e1859fdf..e5c3b5ad8 100644 Binary files "a/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" and "b/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" differ diff --git "a/day5/\346\274\224\347\277\2223/tests/test_model_inference.py" "b/day5/\346\274\224\347\277\2223/tests/test_model_inference.py" new file mode 100644 index 000000000..272d8c5e8 --- /dev/null +++ "b/day5/\346\274\224\347\277\2223/tests/test_model_inference.py" @@ -0,0 +1,36 @@ +import pytest +import time +import os +import pandas as pd +from models.main import DataLoader, ModelTester # パスはリポジトリ構成に合わせて変更 + + +def test_model_inference_accuracy(): + """モデルの推論精度をテスト""" + # モデル読み込み + model = ModelTester.load_model("models/titanic_model.pkl") + + # テストデータの読み込みと前処理 + data = DataLoader.load_titanic_data("data/Titanic.csv") + X, y = DataLoader.preprocess_titanic_data(data) + + # 精度評価 + y_pred = model.predict(X) + accuracy = (y_pred == y).mean() + + # 閾値に基づくテスト + assert accuracy >= 0.75, f"Accuracy too low: {accuracy:.4f}" + + +def test_model_inference_time(): + """モデルの推論時間をテスト""" + model = ModelTester.load_model("models/titanic_model.pkl") + data = DataLoader.load_titanic_data("data/Titanic.csv") + X, _ = DataLoader.preprocess_titanic_data(data) + + start = time.time() + _ = model.predict(X) + elapsed = time.time() - start + + assert elapsed < 1.0, f"Inference took too long: {elapsed:.4f} sec" +