Task1 的baseline我们是基于经验模型(使用均值作为结果数据)来解决的问题,Task2 版本教程将使用机器学习模型解决本次问题,模型使用简单,数据不需要过多预处理;
使用机器学习方法一般主要需要从 获取数据&增强、特征提取和模型 三个方面下手。
一般的使用机器学习模型解决问题的主要步骤为探索性数据分析、数据预处理、提取特征、切分训练集与验证集、训练模型、预测结果。
一、代码详解
1、导入模块
import numpy as np
import pandas as pd
import lightgbm as lgb
from sklearn.metrics import mean_squared_log_error, mean_absolute_error, mean_squared_error
import tqdm
import sys
import os
import gc
import argparse
import warnings
warnings.filterwarnings('ignore')
2、探索性数据分析
在数据准备阶段,主要读取训练数据和测试数据,并进行基本的数据展示。
train = pd.read_csv('./data/train.csv')
test = pd.read_csv('./data/test.csv')
数据简单介绍:其中id为房屋id,dt为日标识,训练数据dt最小为11,不同id对应序列长度不同;type为房屋类型,通常而言不同类型的房屋整体消耗存在比较大的差异;target为实际电力消耗,也是我们的本次比赛的预测目标。
不同type类型对应target的柱状图
import matplotlib.pyplot as plt
# 不同type类型对应target的柱状图
type_target_df = train.groupby('type')['target'].mean().reset_index()
plt.figure(figsize=(8, 4))
plt.bar(type_target_df['type'], type_target_df['target'], color=['blue', 'green'])
plt.xlabel('Type')
plt.ylabel('Average Target Value')
plt.title('Bar Chart of T