diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4aad9943..e8d39180a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,6 @@ name: ML Pipeline CI on: - # push: - # branches: [ main, master ] pull_request: branches: [ main, master ] @@ -11,31 +9,40 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - + - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.10' - + - name: Install dependencies 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 run: | flake8 day5/演習3 --count --select=E9,F63,F7,F82 --show-source --statistics flake8 day5/演習3 --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics - + - name: Format check with black run: | black --check day5/演習3 - + - name: Run data tests run: | + export PYTHONPATH="${PYTHONPATH}:$(pwd)" pytest day5/演習3/tests/test_data.py -v - + - name: Run model tests run: | + export PYTHONPATH="${PYTHONPATH}:$(pwd)" pytest day5/演習3/tests/test_model.py -v + + - name: Run model inference tests + run: | + export PYTHONPATH="${PYTHONPATH}:$(pwd)" + pytest day5/演習3/tests/test_model_inference.py -v + pytest day5/演習3/tests/test_model_inference.py -v --disable-warnings 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..d76cd3606 --- /dev/null +++ "b/day5/\346\274\224\347\277\2223/tests/test_model_inference.py" @@ -0,0 +1,29 @@ +import os +import time +from day5.演習2.main import DataLoader, ModelTester + +# モデルファイルパスの明示的な指定 +MODEL_DIR = os.path.join(os.path.dirname(__file__), "../models") +MODEL_PATH = os.path.join(MODEL_DIR, "titanic_model.pkl") +DATA_PATH = os.path.join(os.path.dirname(__file__), "../data/Titanic.csv") + + +def test_model_inference_accuracy(): + """モデルの推論精度が0.75以上であることを検証""" + model = ModelTester.load_model(MODEL_PATH) + data = DataLoader.load_titanic_data(DATA_PATH) + 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(): + """モデルの推論が1秒以内に完了することを検証""" + model = ModelTester.load_model(MODEL_PATH) + data = DataLoader.load_titanic_data(DATA_PATH) + X, y = 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"