Skip to content
Open
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
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Binary file modified day5/演習1/models/titanic_model.pkl
Binary file not shown.
21 changes: 16 additions & 5 deletions day5/演習2/black_check.py
Original file line number Diff line number Diff line change
@@ -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
return a + b
1 change: 1 addition & 0 deletions day5/演習2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
import great_expectations as gx


class DataLoader:
"""データロードを行うクラス"""

Expand Down
Binary file modified day5/演習2/models/titanic_model.pkl
Binary file not shown.
36 changes: 36 additions & 0 deletions day5/演習3/tests/test_model_inference.py
Original file line number Diff line number Diff line change
@@ -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"