HeartbeatClassification是天池数据比赛的一道题目。
记录学习过程。
从近几年的各大数据竞赛中可以看到模型融合的身影,本文主要有“十折交叉法”,“lgb",将数据集分为训练集、验证集、测试集。
导入第三方包:
# 导入第三方包
import os
import gc
import math
import pandas as pd
import numpy as np
import lightgbm as lgb
import xgboost as xgb
from catboost import CatBoostRegressor
from sklearn.linear_model import SGDRegressor,LinearRegression,Ridge
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import StratifiedKFold,KFold
from sklearn.metrics import log_loss
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder
from tqdm import tqdm
import matplotlib.pyplot as plt
import time
import warnings
warnings.filterwarnings('ignore')
读取数据
train=pd.read_csv('\Train.csv')
test=pd.read_csv('\TestA.csv')
train.head()
test.head()
数据预处理
#为了减少数据内存,其他数据集也可使用
def reduce_mem_usage(df):
start_mem=df.memory_usage().sum()/1024**2
print('Memory usage of dataframe is {:.2f} MB'.format(start_mem))
for col in df.columns:
col_type=df[col].dtype
if col_type !=object:
c_min=df[col].min()
c_max=df[col].max()
if str(col_type)[:3]=='int':
if c_min>np.iinfo(np.int8).min and c_max<np.iinfo(np.int8).max:
df[col]=df[col].astype(np.int8)
elif c_min>np.iinfo(np.int16).min and c_max<np.iinfo(np.int16).max:
df[col]=df[col].astype(np.int16