2021科大讯飞_环境空气质量评价挑战赛_LineRegression_baseline0.04385


前言

没事的话就也来参加一下这些比赛吧,只要进入前20%就有证书发啦,以后说不定有用噢


一、环境空气质量评价挑战赛

在这里插入图片描述
数据预览:
在这里插入图片描述

参赛链接
这是一个时间序列问题,数据是没有缺失的,是一个典型的回归问题,后续可能考虑提升树啊,XGBoost,lightGBM,DNN,LSTM等等

好吧,更一下这里有个XGBoost的链接,不过只有0.08的分数。
https://blog.csdn.net/qq_44694861/article/details/118240970

二、源码

1.LineRegression

代码如下(示例):

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import KFold
from sklearn.metrics import mean_squared_error


def rmse(y_true, y_pred):
    return mean_squared_error(y_true=y_true, y_pred=y_pred) ** 0.5

train = pd.read_csv('C:/Usersx/Desktop/环境空气质量评价挑战赛/初赛_训练集/保定2016年.csv')
test = pd.read_csv('C:/Usersx/Desktop/环境空气质量评价挑战赛/初赛_测试集/石家庄20160701-20170701.csv')

data = pd.concat([train, test]).reset_index(drop=True)
data['month'] = data['日期'].apply(lambda x: str(x).split('/')[1])
data_onehot = pd.get_dummies(data['质量等级'])
data = pd.concat([data, data_onehot], axis=1)

feature = [
    'AQI', 'PM2.5', 'PM10', 'SO2', 'CO', 'NO2', 'O3_8h',
    'month', '严重污染', '中度污染', '优', '良', '轻度污染', '重度污染'
]
label = 'IPRC'

train = data[:train.shape[0]]
test = data[train.shape[0]:]


oof_train = np.zeros((train.shape[0],))
oof_test = np.zeros((test.shape[0],))

kf = KFold(n_splits=2, random_state=66, shuffle=True)
for index, (tr_index, vl_index) in enumerate(kf.split(train)):
    X_train, X_valid = train.iloc[tr_index][feature].values, train.iloc[vl_index][feature].values
    y_train, y_valid = train.iloc[tr_index][label], train.iloc[vl_index][label]

    lf = LinearRegression()
    lf.fit(X_train, y_train)

    oof_train[vl_index] = lf.predict(X_valid)
    oof_test = oof_test + lf.predict(test[feature].values) / kf.n_splits

r = rmse(train[label], oof_train)
print('RMSE:%f'%r)

submit = test[['日期']]
submit = submit.reset_index()
submit.drop('index', axis=1, inplace=True)

temp = pd.DataFrame(oof_test)
submit = pd.concat([submit,temp],axis=1)

submit.columns = ['date', 'IPRC']
submit.to_csv('C:/Usersx/Desktop/环境空气质量评价挑战赛/submit.csv', index=False)

总结

提示:返回分数一般是0.04左右啦。
在这里插入图片描述

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是狮子搏兔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值