diff --git a/day1/day1_practice.ipynb b/day1/day1_practice.ipynb index a1dec3a9e..e18018abc 100644 --- a/day1/day1_practice.ipynb +++ b/day1/day1_practice.ipynb @@ -1,5 +1,15 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, { "cell_type": "markdown", "metadata": { @@ -59,11 +69,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "AIXMavdDEP8U" - }, - "outputs": [], + "execution_count": 1, + "metadata": { + "id": "AIXMavdDEP8U", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "7e13451d-eda6-45a1-b5e8-c6ac451744bb" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Cloning into 'lecture-ai-engineering'...\n", + "remote: Enumerating objects: 52, done.\u001b[K\n", + "remote: Total 52 (delta 0), reused 0 (delta 0), pack-reused 52 (from 1)\u001b[K\n", + "Receiving objects: 100% (52/52), 83.21 KiB | 1.63 MiB/s, done.\n", + "Resolving deltas: 100% (9/9), done.\n" + ] + } + ], "source": [ "!git clone https://github.com/matsuolab/lecture-ai-engineering.git" ] @@ -115,11 +141,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "bvEowFfg5lrq" - }, - "outputs": [], + "execution_count": 3, + "metadata": { + "id": "bvEowFfg5lrq", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "1b087006-8b84-4440-adb5-2c61806b0aa1" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Requirement already satisfied: python-dotenv in /usr/local/lib/python3.11/dist-packages (1.1.0)\n", + "/content/lecture-ai-engineering/day1\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "True" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], "source": [ "!pip install python-dotenv\n", "from dotenv import load_dotenv, find_dotenv\n", @@ -141,11 +190,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "S28XgOm0ELSM" - }, - "outputs": [], + "execution_count": 4, + "metadata": { + "id": "S28XgOm0ELSM", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "659a410f-8310-4d80-b243-7ac1a8c32e4a" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "/content/lecture-ai-engineering/day1/01_streamlit_UI\n" + ] + } + ], "source": [ "%cd /content/lecture-ai-engineering/day1/01_streamlit_UI" ] @@ -161,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "nBe41LFiELSN" }, @@ -182,11 +243,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "aYw1q0iXELSN" - }, - "outputs": [], + "execution_count": 6, + "metadata": { + "id": "aYw1q0iXELSN", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "32f147d4-b8e6-4d4b-f1bf-efecd367dde6" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Authtoken saved to configuration file: /root/.config/ngrok/ngrok.yml\n" + ] + } + ], "source": [ "!ngrok authtoken $$NGROK_TOKEN" ] @@ -202,11 +275,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "f-E7ucR6ELSN" - }, - "outputs": [], + "execution_count": 8, + "metadata": { + "id": "f-E7ucR6ELSN", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "e2ed84b0-95fd-4fb8-ad1e-7134c279b7d8" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "公開URL: https://03dc-34-172-63-208.ngrok-free.app\n", + "\n", + "Collecting usage statistics. To deactivate, set browser.gatherUsageStats to false.\n", + "\u001b[0m\n", + "\u001b[0m\n", + "\u001b[34m\u001b[1m You can now view your Streamlit app in your browser.\u001b[0m\n", + "\u001b[0m\n", + "\u001b[34m Local URL: \u001b[0m\u001b[1mhttp://localhost:8501\u001b[0m\n", + "\u001b[34m Network URL: \u001b[0m\u001b[1mhttp://172.28.0.12:8501\u001b[0m\n", + "\u001b[34m External URL: \u001b[0m\u001b[1mhttp://34.172.63.208:8501\u001b[0m\n", + "\u001b[0m\n", + "\u001b[34m Stopping...\u001b[0m\n", + "^C\n" + ] + } + ], "source": [ "from pyngrok import ngrok\n", "\n", @@ -243,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "8Ek9QgahELSO" }, @@ -391,7 +488,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "jWDYLk2xAlC4" + }, "source": [ "アプリケーションの機能としては、チャット機能や履歴閲覧があります。\n", "\n", @@ -555,7 +654,8 @@ ], "metadata": { "colab": { - "provenance": [] + "provenance": [], + "include_colab_link": true }, "kernelspec": { "display_name": "Python 3", @@ -567,4 +667,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file diff --git "a/day5/\346\274\224\347\277\2221/main.py" "b/day5/\346\274\224\347\277\2221/main.py" index 08be7c6ab..9a8a7dcf1 100644 --- "a/day5/\346\274\224\347\277\2221/main.py" +++ "b/day5/\346\274\224\347\277\2221/main.py" @@ -51,6 +51,21 @@ def train_and_evaluate( accuracy = accuracy_score(y_test, predictions) return model, accuracy +# 推論精度と推論時間を評価 +def evaluate_inference_performance(model, X_test, y_test): + start_time = time.time() + predictions = model.predict(X_test) + end_time = time.time() + + total_time = end_time - start_time + avg_time_per_sample = total_time / len(X_test) + + accuracy = accuracy_score(y_test, predictions) + + print("\n=== 推論性能評価 ===") + print(f"精度(accuracy): {accuracy:.4f}") + print(f"全体推論時間: {total_time:.4f}秒") + print(f"1件あたり平均推論時間: {avg_time_per_sample * 1000:.4f} ms") # モデル保存 def log_model(model, accuracy, params): @@ -112,6 +127,8 @@ def log_model(model, accuracy, params): random_state=model_random_state, ) + evaluate_inference_performance(model, X_test, y_test) # ← ★ 追加呼び出し + # モデル保存 log_model(model, accuracy, params) 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..135bacca5 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/models/titanic_model.pkl" "b/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" index 9e1859fdf..02a80d86e 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