Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
# - name: Run model tests
# run: |
# pytest day5/演習2/tests/test_model.py -v
- name: Run main.py
run: |
python day5/演習2/main.py -v

- name: Run pytest on main.py
run: |
pytest day5/演習2/main.py -v
28 changes: 23 additions & 5 deletions day5/演習2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,30 @@ class DataLoader:
def load_titanic_data(path=None):
"""Titanicデータセットを読み込む"""
if path:
return pd.read_csv(path)
# 引数にパスが指定された場合はそれを優先
if os.path.exists(path):
return pd.read_csv(path)
else:
print(f"Error: Specified path '{path}' does not exist.")
return None
else:
# ローカルのファイル
local_path = "/Users/yutsudoryo/Documents/AIE/lecture-ai-engineering/day5/演習2/data/Titanic.csv"
if os.path.exists(local_path):
return pd.read_csv(local_path)
# 引数が指定されない場合、現在のスクリプトからの相対パスを試す
# スクリプトがあるディレクトリの絶対パスを取得
script_dir = os.path.dirname(__file__)
# 'data'ディレクトリがスクリプトの隣にあると仮定
relative_path = os.path.join(script_dir, "data", "Titanic.csv")

# または、より上位の 'lecture-ai-engineering' ディレクトリ直下に 'data' がある場合
# project_root = os.path.abspath(os.path.join(script_dir, '..', '..')) # day5/演習2 から2つ上に上がる
# relative_path = os.path.join(project_root, "data", "Titanic.csv")

if os.path.exists(relative_path):
print(f"Loading data from: {relative_path}") # デバッグ用
return pd.read_csv(relative_path)
else:
print(f"Error: Data file not found at local path '{relative_path}'.")
# ここでエラーを発生させるか、Noneを返すかを決める
return None # Noneを返すと、その後の処理でNoneTypeエラーが発生する可能性がある

@staticmethod
def preprocess_titanic_data(data):
Expand Down