{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n# Use the kagglehub client library to attach Kaggle resources like competitions, datasets, and models to your session\n# Learn more about kagglehub: https://github.com/Kaggle/kagglehub/blob/main/README.md\n\nimport kagglehub\n# kagglehub.dataset_download('<owner>/<dataset-slug>')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:26.562505Z","iopub.execute_input":"2026-07-24T09:43:26.565032Z","iopub.status.idle":"2026-07-24T09:43:28.341798Z","shell.execute_reply.started":"2026-07-24T09:43:26.564976Z","shell.execute_reply":"2026-07-24T09:43:28.341185Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"path = '/kaggle/input/store-sales-time-series-forecasting/'\ntrain = pd.read_csv('/kaggle/input/competitions/Store-Sales-Forecasting/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:28.343167Z","iopub.execute_input":"2026-07-24T09:43:28.343518Z","iopub.status.idle":"2026-07-24T09:43:30.116277Z","shell.execute_reply.started":"2026-07-24T09:43:28.343491Z","shell.execute_reply":"2026-07-24T09:43:30.115590Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.117067Z","iopub.execute_input":"2026-07-24T09:43:30.117280Z","iopub.status.idle":"2026-07-24T09:43:30.137934Z","shell.execute_reply.started":"2026-07-24T09:43:30.117258Z","shell.execute_reply":"2026-07-24T09:43:30.137052Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.read_csv(\"/kaggle/input/competitions/Store-Sales-Forecasting/test.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.138856Z","iopub.execute_input":"2026-07-24T09:43:30.139127Z","iopub.status.idle":"2026-07-24T09:43:30.173481Z","shell.execute_reply.started":"2026-07-24T09:43:30.139105Z","shell.execute_reply":"2026-07-24T09:43:30.172428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"date\"] = pd.to_datetime(train[\"date\"])\ntest[\"date\"] = pd.to_datetime(test[\"date\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.174658Z","iopub.execute_input":"2026-07-24T09:43:30.175034Z","iopub.status.idle":"2026-07-24T09:43:30.391444Z","shell.execute_reply.started":"2026-07-24T09:43:30.175002Z","shell.execute_reply":"2026-07-24T09:43:30.390397Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"dayofweek\"] = train[\"date\"].dt.dayofweek\ntest[\"dayofweek\"] = test[\"date\"].dt.dayofweek","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.392488Z","iopub.execute_input":"2026-07-24T09:43:30.392720Z","iopub.status.idle":"2026-07-24T09:43:30.469080Z","shell.execute_reply.started":"2026-07-24T09:43:30.392694Z","shell.execute_reply":"2026-07-24T09:43:30.468331Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nsales_by_day = train.groupby(\"dayofweek\")[\"sales\"].mean()\n\nsales_by_day.plot(kind=\"bar\")\nplt.xlabel(\"Day of Week\")\nplt.ylabel(\"Average Sales\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.471381Z","iopub.execute_input":"2026-07-24T09:43:30.471588Z","iopub.status.idle":"2026-07-24T09:43:30.729432Z","shell.execute_reply.started":"2026-07-24T09:43:30.471568Z","shell.execute_reply":"2026-07-24T09:43:30.728603Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"holidays_events = pd.read_csv(\"/kaggle/input/competitions/Store-Sales-Forecasting/holidays_events.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.730458Z","iopub.execute_input":"2026-07-24T09:43:30.731180Z","iopub.status.idle":"2026-07-24T09:43:30.741376Z","shell.execute_reply.started":"2026-07-24T09:43:30.731151Z","shell.execute_reply":"2026-07-24T09:43:30.740423Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"holiday = holidays_events[[\"date\", \"type\", \"transferred\"]].copy()\n\nholiday[\"date\"] = pd.to_datetime(holiday[\"date\"])\n\ntrain = train.merge(\n    holiday,\n    on=\"date\",\n    how=\"left\"\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:30.742464Z","iopub.execute_input":"2026-07-24T09:43:30.742665Z","iopub.status.idle":"2026-07-24T09:43:31.203365Z","shell.execute_reply.started":"2026-07-24T09:43:30.742647Z","shell.execute_reply":"2026-07-24T09:43:31.202420Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"is_holiday\"] = train[\"type\"].notnull().astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:31.204401Z","iopub.execute_input":"2026-07-24T09:43:31.204604Z","iopub.status.idle":"2026-07-24T09:43:31.266462Z","shell.execute_reply.started":"2026-07-24T09:43:31.204586Z","shell.execute_reply":"2026-07-24T09:43:31.265736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.groupby(\n    [\"dayofweek\", \"is_holiday\"]\n)[\"sales\"].mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:31.267399Z","iopub.execute_input":"2026-07-24T09:43:31.267651Z","iopub.status.idle":"2026-07-24T09:43:31.385349Z","shell.execute_reply.started":"2026-07-24T09:43:31.267625Z","shell.execute_reply":"2026-07-24T09:43:31.384275Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\npivot = train.pivot_table(\n    values=\"sales\",\n    index=\"dayofweek\",\n    columns=\"is_holiday\",\n    aggfunc=\"mean\"\n)\n\npivot.plot(kind=\"bar\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:31.386306Z","iopub.execute_input":"2026-07-24T09:43:31.386510Z","iopub.status.idle":"2026-07-24T09:43:31.617093Z","shell.execute_reply.started":"2026-07-24T09:43:31.386490Z","shell.execute_reply":"2026-07-24T09:43:31.616125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.groupby([\"dayofweek\", \"is_holiday\"]).size()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:31.618114Z","iopub.execute_input":"2026-07-24T09:43:31.618853Z","iopub.status.idle":"2026-07-24T09:43:31.709286Z","shell.execute_reply.started":"2026-07-24T09:43:31.618825Z","shell.execute_reply":"2026-07-24T09:43:31.708352Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"date\"] = pd.to_datetime(train[\"date\"])\n\ntrain_data = train[train[\"date\"] < \"2017-01-01\"]\nvalid_data = train[train[\"date\"] >= \"2017-01-01\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:31.710825Z","iopub.execute_input":"2026-07-24T09:43:31.711177Z","iopub.status.idle":"2026-07-24T09:43:31.976037Z","shell.execute_reply.started":"2026-07-24T09:43:31.711151Z","shell.execute_reply":"2026-07-24T09:43:31.975306Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"date\"] = pd.to_datetime(train[\"date\"])\n\ntrain_data = train[train[\"date\"] < \"2017-01-01\"]\nvalid_data = train[train[\"date\"] >= \"2017-01-01\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:31.977016Z","iopub.execute_input":"2026-07-24T09:43:31.977267Z","iopub.status.idle":"2026-07-24T09:43:32.278931Z","shell.execute_reply.started":"2026-07-24T09:43:31.977242Z","shell.execute_reply":"2026-07-24T09:43:32.277391Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = [\"dayofweek\"]\n\nX_train = train_data[features]\ny_train = train_data[\"sales\"]\n\nX_valid = valid_data[features]\ny_valid = valid_data[\"sales\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:32.281048Z","iopub.execute_input":"2026-07-24T09:43:32.281301Z","iopub.status.idle":"2026-07-24T09:43:32.293238Z","shell.execute_reply.started":"2026-07-24T09:43:32.281283Z","shell.execute_reply":"2026-07-24T09:43:32.292153Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeRegressor\n\nmodel = DecisionTreeRegressor(random_state=42)\nmodel.fit(X_train, y_train)\n\npred = model.predict(X_valid)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:32.294668Z","iopub.execute_input":"2026-07-24T09:43:32.295314Z","iopub.status.idle":"2026-07-24T09:43:33.480579Z","shell.execute_reply.started":"2026-07-24T09:43:32.295287Z","shell.execute_reply":"2026-07-24T09:43:33.479310Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import root_mean_squared_log_error\n\nscore1 = root_mean_squared_log_error(y_valid, pred)\nprint(score1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.481566Z","iopub.execute_input":"2026-07-24T09:43:33.482031Z","iopub.status.idle":"2026-07-24T09:43:33.500745Z","shell.execute_reply.started":"2026-07-24T09:43:33.482010Z","shell.execute_reply":"2026-07-24T09:43:33.499970Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"曜日のみの制度↑","metadata":{}},{"cell_type":"code","source":"features = [\"dayofweek\", \"is_holiday\"]\n\nX_train = train_data[features]\nX_valid = valid_data[features]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.501594Z","iopub.execute_input":"2026-07-24T09:43:33.501780Z","iopub.status.idle":"2026-07-24T09:43:33.516344Z","shell.execute_reply.started":"2026-07-24T09:43:33.501762Z","shell.execute_reply":"2026-07-24T09:43:33.515515Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = DecisionTreeRegressor(random_state=42)\nmodel.fit(X_train, y_train)\n\npred = model.predict(X_valid)\n\nscore2 = root_mean_squared_log_error(y_valid, pred)\nprint(score2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.517399Z","iopub.execute_input":"2026-07-24T09:43:33.517633Z","iopub.status.idle":"2026-07-24T09:43:33.732469Z","shell.execute_reply.started":"2026-07-24T09:43:33.517611Z","shell.execute_reply":"2026-07-24T09:43:33.731723Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"曜日と祝日のみの制度↑","metadata":{}},{"cell_type":"code","source":"train[\"month\"] = train[\"date\"].dt.month","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.733991Z","iopub.execute_input":"2026-07-24T09:43:33.734174Z","iopub.status.idle":"2026-07-24T09:43:33.787349Z","shell.execute_reply.started":"2026-07-24T09:43:33.734157Z","shell.execute_reply":"2026-07-24T09:43:33.786334Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"monthly_sales = train.groupby(\"month\")[\"sales\"].mean()\nprint(monthly_sales)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.791141Z","iopub.execute_input":"2026-07-24T09:43:33.791391Z","iopub.status.idle":"2026-07-24T09:43:33.839716Z","shell.execute_reply.started":"2026-07-24T09:43:33.791370Z","shell.execute_reply":"2026-07-24T09:43:33.838785Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nmonthly_sales = train.groupby(\"month\")[\"sales\"].mean()\n\nplt.figure(figsize=(8,5))\nmonthly_sales.plot(kind=\"bar\")\n\nplt.xlabel(\"Month\")\nplt.ylabel(\"Average Sales\")\nplt.title(\"Average Sales by Month\")\nplt.xticks(rotation=0)\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.840590Z","iopub.execute_input":"2026-07-24T09:43:33.840808Z","iopub.status.idle":"2026-07-24T09:43:33.994388Z","shell.execute_reply.started":"2026-07-24T09:43:33.840786Z","shell.execute_reply":"2026-07-24T09:43:33.993721Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"date\"] = pd.to_datetime(train[\"date\"])\n\ntrain[\"dayofweek\"] = train[\"date\"].dt.dayofweek\ntrain[\"month\"] = train[\"date\"].dt.month\n\ntrain_data = train[train[\"date\"] < \"2017-01-01\"]\nvalid_data = train[train[\"date\"] >= \"2017-01-01\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:33.995232Z","iopub.execute_input":"2026-07-24T09:43:33.995493Z","iopub.status.idle":"2026-07-24T09:43:34.362258Z","shell.execute_reply.started":"2026-07-24T09:43:33.995471Z","shell.execute_reply":"2026-07-24T09:43:34.361609Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = [\n    \"dayofweek\",\n    \"is_holiday\",\n    \"month\"\n]\n\nX_train = train_data[features]\ny_train = train_data[\"sales\"]\n\nX_valid = valid_data[features]\ny_valid = valid_data[\"sales\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:34.362969Z","iopub.execute_input":"2026-07-24T09:43:34.363152Z","iopub.status.idle":"2026-07-24T09:43:34.383486Z","shell.execute_reply.started":"2026-07-24T09:43:34.363136Z","shell.execute_reply":"2026-07-24T09:43:34.382718Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeRegressor\nfrom sklearn.metrics import root_mean_squared_log_error\n\nmodel = DecisionTreeRegressor(random_state=42)\nmodel.fit(X_train, y_train)\n\npred = model.predict(X_valid)\n\nscore3 = root_mean_squared_log_error(y_valid, pred)\nprint(\"RMSLE:\", score3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:34.384454Z","iopub.execute_input":"2026-07-24T09:43:34.384687Z","iopub.status.idle":"2026-07-24T09:43:34.901522Z","shell.execute_reply.started":"2026-07-24T09:43:34.384669Z","shell.execute_reply":"2026-07-24T09:43:34.900712Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"曜日、祝日、月のみの精度","metadata":{}},{"cell_type":"markdown","source":"**ここから7/17**","metadata":{}},{"cell_type":"code","source":"oil = pd.read_csv(\"/kaggle/input/competitions/Store-Sales-Forecasting/oil.csv\")\noil.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:34.902792Z","iopub.execute_input":"2026-07-24T09:43:34.903144Z","iopub.status.idle":"2026-07-24T09:43:34.927003Z","shell.execute_reply.started":"2026-07-24T09:43:34.903115Z","shell.execute_reply":"2026-07-24T09:43:34.925949Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"oil[\"date\"] = pd.to_datetime(oil[\"date\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:34.927913Z","iopub.execute_input":"2026-07-24T09:43:34.928126Z","iopub.status.idle":"2026-07-24T09:43:34.933439Z","shell.execute_reply.started":"2026-07-24T09:43:34.928108Z","shell.execute_reply":"2026-07-24T09:43:34.932318Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = train.merge(oil, on=\"date\", how=\"left\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:34.934915Z","iopub.execute_input":"2026-07-24T09:43:34.935252Z","iopub.status.idle":"2026-07-24T09:43:35.296260Z","shell.execute_reply.started":"2026-07-24T09:43:34.935227Z","shell.execute_reply":"2026-07-24T09:43:35.295277Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.297464Z","iopub.execute_input":"2026-07-24T09:43:35.297785Z","iopub.status.idle":"2026-07-24T09:43:35.309190Z","shell.execute_reply.started":"2026-07-24T09:43:35.297751Z","shell.execute_reply":"2026-07-24T09:43:35.308242Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"dcoilwtico\"] = train[\"dcoilwtico\"].ffill()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.310300Z","iopub.execute_input":"2026-07-24T09:43:35.310579Z","iopub.status.idle":"2026-07-24T09:43:35.338718Z","shell.execute_reply.started":"2026-07-24T09:43:35.310549Z","shell.execute_reply":"2026-07-24T09:43:35.337656Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"dcoilwtico\"] = train[\"dcoilwtico\"].bfill()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.339688Z","iopub.execute_input":"2026-07-24T09:43:35.339951Z","iopub.status.idle":"2026-07-24T09:43:35.354783Z","shell.execute_reply.started":"2026-07-24T09:43:35.339930Z","shell.execute_reply":"2026-07-24T09:43:35.353766Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = [\n    \"dayofweek\",\n    \"is_holiday\",\n    \"month\",\n    \"dcoilwtico\"\n]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.356053Z","iopub.execute_input":"2026-07-24T09:43:35.356394Z","iopub.status.idle":"2026-07-24T09:43:35.361836Z","shell.execute_reply.started":"2026-07-24T09:43:35.356364Z","shell.execute_reply":"2026-07-24T09:43:35.360977Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"dcoilwtico\"] = train[\"dcoilwtico\"].bfill()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.363028Z","iopub.execute_input":"2026-07-24T09:43:35.363315Z","iopub.status.idle":"2026-07-24T09:43:35.393261Z","shell.execute_reply.started":"2026-07-24T09:43:35.363283Z","shell.execute_reply":"2026-07-24T09:43:35.391971Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(oil.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.394345Z","iopub.execute_input":"2026-07-24T09:43:35.394582Z","iopub.status.idle":"2026-07-24T09:43:35.399922Z","shell.execute_reply.started":"2026-07-24T09:43:35.394562Z","shell.execute_reply":"2026-07-24T09:43:35.398911Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.400946Z","iopub.execute_input":"2026-07-24T09:43:35.401594Z","iopub.status.idle":"2026-07-24T09:43:35.417006Z","shell.execute_reply.started":"2026-07-24T09:43:35.401574Z","shell.execute_reply":"2026-07-24T09:43:35.415823Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data = train[train[\"date\"] < \"2017-01-01\"]\nvalid_data = train[train[\"date\"] >= \"2017-01-01\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.418034Z","iopub.execute_input":"2026-07-24T09:43:35.418325Z","iopub.status.idle":"2026-07-24T09:43:35.642814Z","shell.execute_reply.started":"2026-07-24T09:43:35.418292Z","shell.execute_reply":"2026-07-24T09:43:35.641689Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = [\n    \"dayofweek\",\n    \"is_holiday\",\n    \"month\",\n    \"dcoilwtico\"\n]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.644221Z","iopub.execute_input":"2026-07-24T09:43:35.644534Z","iopub.status.idle":"2026-07-24T09:43:35.649865Z","shell.execute_reply.started":"2026-07-24T09:43:35.644504Z","shell.execute_reply":"2026-07-24T09:43:35.649006Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = train_data[features]\nX_valid = valid_data[features]\n\nmodel.fit(X_train, y_train)\npred = model.predict(X_valid)\n\nscore = root_mean_squared_log_error(y_valid, pred)\nprint(score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:35.650862Z","iopub.execute_input":"2026-07-24T09:43:35.651138Z","iopub.status.idle":"2026-07-24T09:43:36.912921Z","shell.execute_reply.started":"2026-07-24T09:43:35.651111Z","shell.execute_reply":"2026-07-24T09:43:36.912056Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = [\n    \"dayofweek\",\n    \"is_holiday\",\n    \"month\",\n]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:36.914542Z","iopub.execute_input":"2026-07-24T09:43:36.915128Z","iopub.status.idle":"2026-07-24T09:43:36.919661Z","shell.execute_reply.started":"2026-07-24T09:43:36.915090Z","shell.execute_reply":"2026-07-24T09:43:36.918326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = train_data[features]\nX_valid = valid_data[features]\n\nmodel.fit(X_train, y_train)\npred = model.predict(X_valid)\n\nscore = root_mean_squared_log_error(y_valid, pred)\nprint(score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:36.920811Z","iopub.execute_input":"2026-07-24T09:43:36.921082Z","iopub.status.idle":"2026-07-24T09:43:37.505563Z","shell.execute_reply.started":"2026-07-24T09:43:36.921062Z","shell.execute_reply":"2026-07-24T09:43:37.504289Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from lightgbm import LGBMRegressor","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:37.506627Z","iopub.execute_input":"2026-07-24T09:43:37.506856Z","iopub.status.idle":"2026-07-24T09:43:40.108764Z","shell.execute_reply.started":"2026-07-24T09:43:37.506830Z","shell.execute_reply":"2026-07-24T09:43:40.107939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = LGBMRegressor(\n    n_estimators=800,\n    learning_rate=0.1,\n    random_state=42\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:40.109740Z","iopub.execute_input":"2026-07-24T09:43:40.110019Z","iopub.status.idle":"2026-07-24T09:43:40.115234Z","shell.execute_reply.started":"2026-07-24T09:43:40.109988Z","shell.execute_reply":"2026-07-24T09:43:40.114240Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:43:40.116159Z","iopub.execute_input":"2026-07-24T09:43:40.116390Z","iopub.status.idle":"2026-07-24T09:44:13.707179Z","shell.execute_reply.started":"2026-07-24T09:43:40.116369Z","shell.execute_reply":"2026-07-24T09:44:13.706428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pred = model.predict(X_valid)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:44:13.708365Z","iopub.execute_input":"2026-07-24T09:44:13.708638Z","iopub.status.idle":"2026-07-24T09:44:18.759755Z","shell.execute_reply.started":"2026-07-24T09:44:13.708615Z","shell.execute_reply":"2026-07-24T09:44:18.758894Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\n\npred = np.maximum(pred, 0)\n\nscore = root_mean_squared_log_error(y_valid, pred)\nprint(score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-24T09:44:18.761003Z","iopub.execute_input":"2026-07-24T09:44:18.761303Z","iopub.status.idle":"2026-07-24T09:44:18.781760Z","shell.execute_reply.started":"2026-07-24T09:44:18.761271Z","shell.execute_reply":"2026-07-24T09:44:18.780602Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"model = LGBMRegressor(\n    n_estimators=100,\n    learning_rate=0.1,\n    random_state=42\n)\nこのとき3.3358428421125477\n\nmodel = LGBMRegressor(\n    n_estimators=500,\n    learning_rate=0.1,\n    random_state=42\n)\nこのとき3.3352128149653617","metadata":{}}]}