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
160 changes: 130 additions & 30 deletions day1/day1_practice.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/Yozefu0315/lecture-ai-engineering/blob/master/day1/day1_practice.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -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"
]
Expand Down Expand Up @@ -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",
Expand All @@ -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"
]
Expand All @@ -161,7 +222,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"id": "nBe41LFiELSN"
},
Expand All @@ -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"
]
Expand All @@ -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",
Expand Down Expand Up @@ -243,7 +340,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"id": "8Ek9QgahELSO"
},
Expand Down Expand Up @@ -391,7 +488,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "jWDYLk2xAlC4"
},
"source": [
"アプリケーションの機能としては、チャット機能や履歴閲覧があります。\n",
"\n",
Expand Down Expand Up @@ -555,7 +654,8 @@
],
"metadata": {
"colab": {
"provenance": []
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
Expand All @@ -567,4 +667,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
17 changes: 17 additions & 0 deletions day5/演習1/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
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
Binary file modified day5/演習2/models/titanic_model.pkl
Binary file not shown.