text_html_output_1.png
import numpy as np

import pandas as pd

import warnings

import gc
import numpy as np
import pandas as pd
from tqdm.notebook import tqdm
import time
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
from sklearn.svm import SVR as skSVR
from cuml.svm import SVR as cuSVR
def smape(y_true, y_pred, agg=True):
    smap = np.zeros(len(y_true))
    num = np.abs(y_true - y_pred)
    dem = (np.abs(y_true) + np.abs(y_pred)) / 2
    pos_ind = (y_true != 0) | (y_pred != 0)
    smap[pos_ind] = num[pos_ind] / dem[pos_ind]
    if agg == True:
        return 100 * np.mean(smap)
    else:
        return 100 * smap
BASE = '../input/godaddy-microbusiness-density-forecasting/'
VERSION = 29

COLS = ['GEO_ID', 'NAME', 'S0101_C01_026E']
df2017 = pd.read_csv('../input/census-data-for-godaddy/ACSST5Y2017.S0101-Data.csv', usecols=COLS)
df2017 = df2017.iloc[1:]
df2017['S0101_C01_026E'] = df2017['S0101_C01_026E'].astype('int')
df2018 = pd.read_csv('../input/census-data-for-godaddy/ACSST5Y2018.S0101-Data.csv', usecols=COLS)
df2018 = df2018.iloc[1:]
df2018['S0101_C01_026E'] = df2018['S0101_C01_026E'].astype('int')
df2019 = pd.read_csv('../input/census-data-for-godaddy/ACSST5Y2019.S0101-Data.csv', usecols=COLS)
df2019 = df2019.iloc[1:]
df2019['S0101_C01_026E'] = df2019['S0101_C01_026E'].astype('int')
df2020 = pd.read_csv('../input/census-data-for-godaddy/ACSST5Y2020.S0101-Data.csv', usecols=COLS)
df2020 = df2020.iloc[1:]
df2020['S0101_C01_026E'] = df2020['S0101_C01_026E'].astype('int')
df2021 = pd.read_csv('../input/census-data-for-godaddy/ACSST5Y2021.S0101-Data.csv', usecols=COLS)
df2021 = df2021.iloc[1:]
df2021['S0101_C01_026E'] = df2021['S0101_C01_026E'].astype('int')
df2017['cfips'] = df2017.GEO_ID.apply(lambda x: int(x.split('US')[-1]))
df2018['cfips'] = df2018.GEO_ID.apply(lambda x: int(x.split('US')[-1]))
df2019['cfips'] = df2019.GEO_ID.apply(lambda x: int(x.split('US')[-1]))
df2020['cfips'] = df2020.GEO_ID.apply(lambda x: int(x.split('US')[-1]))
df2021['cfips'] = df2021.GEO_ID.apply(lambda x: int(x.split('US')[-1]))
df2017['year'] = 2017 + 2
df2018['year'] = 2018 + 2
df2019['year'] = 2019 + 2
df2020['year'] = 2020 + 2
df2021['year'] = 2021 + 2
K = pd.concat((df2017, df2018, df2019, df2020, df2021))
del K['GEO_ID'], K['NAME']
K = K.rename(columns={'S0101_C01_026E': 'K'})
K

K = K.sort_values(['cfips', 'year']).reset_index(drop=True)
K['lag'] = K.groupby('cfips')['K'].shift(1)
K['up'] = (K['K'] - K['lag']) / K['K']
K['up'] = K['up'].fillna(0)
K['utrend'] = 1 * (K['up'] > 0.0005)
K['dtrend'] = 1 * (K['up'] < -0.0005)
K