Kaggle competition: LANL Earthquake Prediction
<SOS> metric: MAE Kaggle data source: lanl-earthquake-prediction<choose_model_class>
from fastai.tabular import *
rf = RandomForestClassifier(random_state=42, n_estimators=100 )<compute_test_metric>
path = Path(".. /input" )
def evaluate_model(model, X, y):
score = cross_val_score(rf, X, y, cv=6)
 print(score)
 print(score.mean() )<compute_test_metric>
%%time
train_df = pd.read_csv(path/'train.csv', dtype={'acoustic_data': np.int16, 'time_to_failure': np.float32} )
evaluate_model(rf, X, y )<save_to_csv>
rows = 150000
segments = int(np.floor(train_df.shape[0] / rows))
def predict_and_submit(model, X, y, x_pred, label_encoder, file_name):
model.fit(X, y)
 predictions = label_encoder.inverse_transform(model.predict(x_pred))
submission = pd.read_csv('.. /input/sample_submission.csv')
 submission['surface'] = predictions
submission.to_csv(file_name, index=False )<predict_on_test>
train_X = pd.DataFrame(index=range(segments), dtype=np.float64)
 train_y = pd.DataFrame(index=range(segments), dtype=np.float64, columns=['time_to_failure'] )
predict_and_submit(rf, X, y, pred_df, label_encoder, 'submitWithEulers01.csv' )<load_from_csv>
warnings.filterwarnings("ignore" )
X_train = pd.read_csv('.. /input/X_train.csv')
 Y_train=pd.read_csv('.. /input/y_train.csv')
 X_train.head() 
<create_dataframe>
def add_trend_feature(arr, abs_values=False):
idx = np.array(range(len(arr)))
 if abs_values:
arr = np.abs(arr)
 lr = LinearRegression()
lr.fit(idx.reshape(-1, 1), arr)
 return lr.coef_[0]
def classic_sta_lta(x, length_sta, length_lta):
sta = np.cumsum(x ** 2)
 sta = np.require(sta, dtype=np.float)
 lta = sta.copy()
sta[length_sta:] = sta[length_sta:] - sta[:-length_sta]
sta /= length_sta
lta[length_lta:] = lta[length_lta:] - lta[:-length_lta]
lta /= length_lta
sta[:length_lta - 1] = 0
dtiny = np.finfo(0.0 ).tiny
idx = lta < dtiny
lta[idx] = dtiny
return sta / lta
columns=['orientation_X','orientation_Y','orientation_Z','orientation_W','angular_velocity_X','angular_velocity_Y','angular_velocity_Z','linear_acceleration_X','linear_acceleration_Y','linear_acceleration_Z']
def feature_data(X):
data_train=pd.DataFrame()
for col in columns:
data_train[col+'_mean'] = X.groupby(['series_id'])[col].mean()
data_train[col+'_median'] = X.groupby(['series_id'])[col].median()
data_train[col+'_max'] = X.groupby(['series_id'])[col].max()
data_train[col+'_min'] = X.groupby(['series_id'])[col].min()
data_train[col+'_std'] = X.groupby(['series_id'])[col].std()
data_train[col+'_var'] = X.groupby(['series_id'])[col].var()
data_train[col + '_range'] = data_train[col + '_max'] - data_train[col + '_min']
data_train[col + '_maxtoMin'] = data_train[col + '_max'] / data_train[col + '_min']
data_train[col + '_mean_abs_chg'] = X.groupby(['series_id'])[col].apply(lambda x: np.mean(np.abs(np.diff(x))))
data_train[col + '_abs_median_chg'] = X.groupby(['series_id'])[col].apply(lambda x: np.median(np.abs(np.diff(x))))
data_train[col + '_abs_std_chg'] = X.groupby(['series_id'])[col].apply(lambda x: np.std(np.abs(x)))
 data_train[col + '_abs_max'] = X.groupby(['series_id'])[col].apply(lambda x: np.max(np.abs(x)))
 data_train[col + '_abs_min'] = X.groupby(['series_id'])[col].apply(lambda x: np.min(np.abs(x)))
 data_train[col + '_abs_avg'] =(data_train[col + '_abs_min'] + data_train[col + '_abs_max'])/2
return data_train
data_train=feature_data(X_train)
 data_train.head()
data_train, data_valid, Y_train, y_valid = train_test_split(data_train, Y_train, test_size=0.3)
<train_model>
def create_features(seg_id, seg, X):
xc = pd.Series(seg['acoustic_data'].values)
 zc = np.fft.fft(xc)
 X.loc[seg_id, 'mean'] = xc.mean()
X.loc[seg_id, 'std'] = xc.std()
X.loc[seg_id, 'max'] = xc.max()
X.loc[seg_id, 'min'] = xc.min()
realFFT = np.real(zc)
 imagFFT = np.imag(zc)
 X.loc[seg_id, 'Rmean'] = realFFT.mean()
X.loc[seg_id, 'Rstd'] = realFFT.std()
X.loc[seg_id, 'Rmax'] = realFFT.max()
X.loc[seg_id, 'Rmin'] = realFFT.min()
X.loc[seg_id, 'Imean'] = imagFFT.mean()
X.loc[seg_id, 'Istd'] = imagFFT.std()
X.loc[seg_id, 'Imax'] = imagFFT.max()
X.loc[seg_id, 'Imin'] = imagFFT.min()
X.loc[seg_id, 'Rmean_last_5000'] = realFFT[-5000:].mean()
X.loc[seg_id, 'Rstd__last_5000'] = realFFT[-5000:].std()
X.loc[seg_id, 'Rmax_last_5000'] = realFFT[-5000:].max()
X.loc[seg_id, 'Rmin_last_5000'] = realFFT[-5000:].min()
X.loc[seg_id, 'Rmean_last_15000'] = realFFT[-15000:].mean()
X.loc[seg_id, 'Rstd_last_15000'] = realFFT[-15000:].std()
X.loc[seg_id, 'Rmax_last_15000'] = realFFT[-15000:].max()
X.loc[seg_id, 'Rmin_last_15000'] = realFFT[-15000:].min()
X.loc[seg_id, 'mean_change_abs'] = np.mean(np.diff(xc))
X.loc[seg_id, 'mean_change_rate'] = np.mean(np.nonzero(( np.diff(xc)/ xc[:-1])) [0])
 X.loc[seg_id, 'abs_max'] = np.abs(xc ).max()
X.loc[seg_id, 'std_first_50000'] = xc[:50000].std()
X.loc[seg_id, 'std_last_50000'] = xc[-50000:].std()
X.loc[seg_id, 'std_first_10000'] = xc[:10000].std()
X.loc[seg_id, 'std_last_10000'] = xc[-10000:].std()
X.loc[seg_id, 'avg_first_50000'] = xc[:50000].mean()
X.loc[seg_id, 'avg_last_50000'] = xc[-50000:].mean()
X.loc[seg_id, 'avg_first_10000'] = xc[:10000].mean()
X.loc[seg_id, 'avg_last_10000'] = xc[-10000:].mean()
X.loc[seg_id, 'min_first_50000'] = xc[:50000].min()
X.loc[seg_id, 'min_last_50000'] = xc[-50000:].min()
X.loc[seg_id, 'min_first_10000'] = xc[:10000].min()
X.loc[seg_id, 'min_last_10000'] = xc[-10000:].min()
X.loc[seg_id, 'max_first_50000'] = xc[:50000].max()
X.loc[seg_id, 'max_last_50000'] = xc[-50000:].max()
X.loc[seg_id, 'max_first_10000'] = xc[:10000].max()
X.loc[seg_id, 'max_last_10000'] = xc[-10000:].max()
X.loc[seg_id, 'max_to_min'] = xc.max() / np.abs(xc.min())
 X.loc[seg_id, 'max_to_min_diff'] = xc.max() - np.abs(xc.min())
 X.loc[seg_id, 'sum'] = xc.sum()
X.loc[seg_id, 'mean_change_rate_first_50000'] = np.mean(np.nonzero(( np.diff(xc[:50000])/ xc[:50000][:-1])) [0])
 X.loc[seg_id, 'mean_change_rate_last_50000'] = np.mean(np.nonzero(( np.diff(xc[-50000:])/ xc[-50000:][:-1])) [0])
 X.loc[seg_id, 'mean_change_rate_first_10000'] = np.mean(np.nonzero(( np.diff(xc[:10000])/ xc[:10000][:-1])) [0])
 X.loc[seg_id, 'mean_change_rate_last_10000'] = np.mean(np.nonzero(( np.diff(xc[-10000:])/ xc[-10000:][:-1])) [0])
 X.loc[seg_id, 'q95'] = np.quantile(xc, 0.95)
 X.loc[seg_id, 'q99'] = np.quantile(xc, 0.99)
 X.loc[seg_id, 'q05'] = np.quantile(xc, 0.05)
 X.loc[seg_id, 'q01'] = np.quantile(xc, 0.01)
 X.loc[seg_id, 'abs_q95'] = np.quantile(np.abs(xc), 0.95)
 X.loc[seg_id, 'abs_q99'] = np.quantile(np.abs(xc), 0.99)
 X.loc[seg_id, 'abs_q05'] = np.quantile(np.abs(xc), 0.05)
 X.loc[seg_id, 'trend'] = add_trend_feature(xc)
 X.loc[seg_id, 'abs_trend'] = add_trend_feature(xc, abs_values=True)
 X.loc[seg_id, 'abs_mean'] = np.abs(xc ).mean()
X.loc[seg_id, 'abs_std'] = np.abs(xc ).std()
X.loc[seg_id, 'mad'] = xc.mad()
X.loc[seg_id, 'kurt'] = xc.kurtosis()
X.loc[seg_id, 'skew'] = xc.skew()
X.loc[seg_id, 'Hilbert_mean'] = np.abs(hilbert(xc)).mean()
X.loc[seg_id, 'Hann_window_mean'] =(convolve(xc, hann(150), mode='same')/ sum(hann(150)) ).mean()
X.loc[seg_id, 'classic_sta_lta1_mean'] = classic_sta_lta(xc, 500, 10000 ).mean()
X.loc[seg_id, 'classic_sta_lta2_mean'] = classic_sta_lta(xc, 5000, 100000 ).mean()
X.loc[seg_id, 'classic_sta_lta3_mean'] = classic_sta_lta(xc, 3333, 6666 ).mean()
X.loc[seg_id, 'classic_sta_lta4_mean'] = classic_sta_lta(xc, 10000, 25000 ).mean()
X.loc[seg_id, 'Moving_average_700_mean'] = xc.rolling(window=700 ).mean().mean(skipna=True)
 X.loc[seg_id, 'Moving_average_1500_mean'] = xc.rolling(window=1500 ).mean().mean(skipna=True)
 X.loc[seg_id, 'Moving_average_3000_mean'] = xc.rolling(window=3000 ).mean().mean(skipna=True)
 X.loc[seg_id, 'Moving_average_6000_mean'] = xc.rolling(window=6000 ).mean().mean(skipna=True)
 ewma = pd.Series.ewm
X.loc[seg_id, 'exp_Moving_average_300_mean'] =(ewma(xc, span=300 ).mean() ).mean(skipna=True)
 X.loc[seg_id, 'exp_Moving_average_3000_mean'] = ewma(xc, span=3000 ).mean().mean(skipna=True)
 X.loc[seg_id, 'exp_Moving_average_30000_mean'] = ewma(xc, span=6000 ).mean().mean(skipna=True)
 no_of_std = 2
X.loc[seg_id, 'MA_700MA_std_mean'] = xc.rolling(window=700 ).std().mean()
X.loc[seg_id,'MA_700MA_BB_high_mean'] =(X.loc[seg_id, 'Moving_average_700_mean'] + no_of_std * X.loc[seg_id, 'MA_700MA_std_mean'] ).mean()
X.loc[seg_id,'MA_700MA_BB_low_mean'] =(X.loc[seg_id, 'Moving_average_700_mean'] - no_of_std * X.loc[seg_id, 'MA_700MA_std_mean'] ).mean()
X.loc[seg_id, 'MA_400MA_std_mean'] = xc.rolling(window=400 ).std().mean()
X.loc[seg_id,'MA_400MA_BB_high_mean'] =(X.loc[seg_id, 'Moving_average_700_mean'] + no_of_std * X.loc[seg_id, 'MA_400MA_std_mean'] ).mean()
X.loc[seg_id,'MA_400MA_BB_low_mean'] =(X.loc[seg_id, 'Moving_average_700_mean'] - no_of_std * X.loc[seg_id, 'MA_400MA_std_mean'] ).mean()
X.loc[seg_id, 'MA_1000MA_std_mean'] = xc.rolling(window=1000 ).std().mean()
X.loc[seg_id, 'iqr'] = np.subtract(*np.percentile(xc, [75, 25]))
X.loc[seg_id, 'q999'] = np.quantile(xc,0.999)
 X.loc[seg_id, 'q001'] = np.quantile(xc,0.001)
 X.loc[seg_id, 'ave10'] = stats.trim_mean(xc, 0.1)
 for windows in [10, 100, 1000]:
x_roll_std = xc.rolling(windows ).std().dropna().values
x_roll_mean = xc.rolling(windows ).mean().dropna().values
X.loc[seg_id, 'ave_roll_std_' + str(windows)] = x_roll_std.mean()
X.loc[seg_id, 'std_roll_std_' + str(windows)] = x_roll_std.std()
X.loc[seg_id, 'max_roll_std_' + str(windows)] = x_roll_std.max()
X.loc[seg_id, 'min_roll_std_' + str(windows)] = x_roll_std.min()
X.loc[seg_id, 'q01_roll_std_' + str(windows)] = np.quantile(x_roll_std, 0.01)
 X.loc[seg_id, 'q05_roll_std_' + str(windows)] = np.quantile(x_roll_std, 0.05)
 X.loc[seg_id, 'q95_roll_std_' + str(windows)] = np.quantile(x_roll_std, 0.95)
 X.loc[seg_id, 'q99_roll_std_' + str(windows)] = np.quantile(x_roll_std, 0.99)
 X.loc[seg_id, 'av_change_abs_roll_std_' + str(windows)] = np.mean(np.diff(x_roll_std))
X.loc[seg_id, 'av_change_rate_roll_std_' + str(windows)] = np.mean(np.nonzero(( np.diff(x_roll_std)/ x_roll_std[:-1])) [0])
 X.loc[seg_id, 'abs_max_roll_std_' + str(windows)] = np.abs(x_roll_std ).max()
X.loc[seg_id, 'std_roll_mean_' + str(windows)] = x_roll_mean.std()
X.loc[seg_id, 'max_roll_mean_' + str(windows)] = x_roll_mean.max()
X.loc[seg_id, 'min_roll_mean_' + str(windows)] = x_roll_mean.min()
X.loc[seg_id, 'q01_roll_mean_' + str(windows)] = np.quantile(x_roll_mean, 0.01)
 X.loc[seg_id, 'q05_roll_mean_' + str(windows)] = np.quantile(x_roll_mean, 0.05)
 X.loc[seg_id, 'q95_roll_mean_' + str(windows)] = np.quantile(x_roll_mean, 0.95)
 X.loc[seg_id, 'q99_roll_mean_' + str(windows)] = np.quantile(x_roll_mean, 0.99)
 X.loc[seg_id, 'av_change_abs_roll_mean_' + str(windows)] = np.mean(np.diff(x_roll_mean))
X.loc[seg_id, 'av_change_rate_roll_mean_' + str(windows)] = np.mean(np.nonzero(( np.diff(x_roll_mean)/ x_roll_mean[:-1])) [0])
 X.loc[seg_id, 'abs_max_roll_mean_' + str(windows)] = np.abs(x_roll_mean ).max()
model = LogisticRegression(solver = 'lbfgs',max_iter=500,multi_class='multinomial')
 model.fit(data_train,Y_train['surface'] )<compute_train_metric>
for seg_id in tqdm(range(segments)) :
seg = train_df.iloc[seg_id*rows:seg_id*rows+rows]
create_features(seg_id, seg, train_X)
 train_y.loc[seg_id, 'time_to_failure'] = seg['time_to_failure'].values[-1]
Y_pred_train=model.predict(data_train)
 accuracy = metrics.accuracy_score(Y_train['surface'], Y_pred_train)
 print('Accuracy training: {:.2f}'.format(accuracy))
Y_pred_valid=model.predict(data_valid)
 accuracy = metrics.accuracy_score(y_valid['surface'], Y_pred_valid)
 print('Accuracy validation: {:.2f}'.format(accuracy))<compute_train_metric>
submission = pd.read_csv(path/'sample_submission.csv', index_col='seg_id')
 test_X = pd.DataFrame(columns=train_X.columns, dtype=np.float64, index=submission.index )
nn_model = MLPClassifier(hidden_layer_sizes=(200, 100,50,), activation='tanh', solver='adam', alpha=0.01,learning_rate_init=0.001, max_iter=800)
 nn_model.fit(data_train,Y_train['surface'])
 Y_pred_train=nn_model.predict(data_train)
 accuracy = metrics.accuracy_score(Y_train['surface'], Y_pred_train)
 print('Accuracy: {:.2f}'.format(accuracy))
Y_pred_valid=nn_model.predict(data_valid)
 accuracy = metrics.accuracy_score(y_valid['surface'], Y_pred_valid)
 print('Accuracy validation: {:.2f}'.format(accuracy))<train_model>
for seg_id in tqdm(test_X.index):
seg = pd.read_csv(path/f'test/{seg_id}.csv')
 create_features(seg_id, seg, test_X )
forest = RandomForestClassifier(n_estimators=600)
 forest.fit(data_train,Y_train['surface'])
 Y_pred_train=forest.predict(data_train)
 accuracy = metrics.accuracy_score(Y_train['surface'], Y_pred_train)
 print('Accuracy training: {:.2f}'.format(accuracy))
Y_pred_valid=forest.predict(data_valid)
 accuracy = metrics.accuracy_score(y_valid['surface'], Y_pred_valid)
 print('Accuracy validation: {:.2f}'.format(accuracy))<save_to_csv>
df = pd.concat([train_X, train_y], axis=1 )
X_test=pd.read_csv('.. /input/X_test.csv')
 data_test=feature_data(X_test)
 Y_pred_test=forest.predict(data_test)
 result = pd.DataFrame()
result['series_id'] = data_test.index.values
result['surface'] = Y_pred_test
result.head()
result.to_csv('submission.csv',sep=',',index=False )<load_from_csv>
df.to_feather("df")
 test_X.to_hdf('df_test.h5', key="df_test")
 df = pd.read_feather("df")
 test_df = pd.read_hdf('df_test.h5', key="df_test" )
df_train = pd.read_csv(".. /input/X_train.csv")
 df_train.head()<load_from_csv>
dep_var = 'time_to_failure'
cont_names = None
cat_names = None
procs = [FillMissing, Categorify, Normalize]
df_test = pd.read_csv(".. /input/X_test.csv")
 df_test.head()<count_missing_values>
data = TabularDataBunch.from_df(path, df, dep_var, valid_idx=range(0,800), procs=procs, test_df=test_df )
df_train["series_id"].is_monotonic<load_from_csv>
data.show_batch(rows=10 )
df_y = pd.read_csv(".. /input/y_train.csv")
 df_y.head()<count_unique_values>
learn = tabular_learner(data, layers=[200,100], model_dir=Path("/"))
df_y.nunique()<categorify>
lr = 1e-02
encoder = LabelEncoder()
y = encoder.fit_transform(df_y["surface"])
 y_count = len(list(encoder.classes_))<define_variables>
learn.fit_one_cycle(5, slice(lr))
label_mapping = {i: l for i, l in enumerate(encoder.classes_)}<define_variables>
learn.save('stage-1' )
3810*128<feature_engineering>
learn.load('stage-1');
df_train["target"] = y.repeat(128 )<compute_test_metric>
learn.fit_one_cycle(10, slice(2e-05))
def process_outliers(df, outlier_cols):
def fz_raw(x):
zscore =(x - x.mean())/x.std()
z_upper = x.mean() +3*x.std()
z_upper = np.repeat(z_upper, 128)
 z_lower = x.mean() -3*x.std()
z_lower = np.repeat(z_lower, 128)
 return np.array(( zscore, z_upper, z_lower))
cols_to_drop = []
for col in tqdm(outlier_cols):
a = df[col].values
series_groups = df.groupby("series_id")
 xyz = series_groups[col].apply(fz_raw)
 xyz_c = np.concatenate(xyz, axis=1)
 z = xyz_c[0]
mask = z >= 3
a[mask] = xyz_c[1][mask]
mask = z <= -3
a[mask] = xyz_c[2][mask]<drop_column>
preds, _ = learn.get_preds(ds_type=DatasetType.Test )
outlier_cols = [col_name for col_name in df_train.columns if col_name not in ["row_id", "series_id", "measurement_number"]]
outlier_cols.remove("orientation_X")
 outlier_cols.remove("orientation_Y")
 outlier_cols.remove("orientation_Z")
 outlier_cols.remove("orientation_W")
 outlier_cols.remove("target")
<feature_engineering>
subm_df = pd.DataFrame(test_df["seg_id"] )
process_outliers(df_train, outlier_cols )<sort_values>
subm_df["time_to_failure"] = preds.numpy()
process_outliers(df_test, outlier_cols )<normalization>
subm_df.to_csv('submission.csv', index=False )
def quaternion_to_euler(x, y, z, w):
t0 = +2.0 *(w * x + y * z)
 t1 = +1.0 - 2.0 *(x * x + y * y)
 X = math.atan2(t0, t1)
 t2 = +2.0 *(w * y - z * x)
 t2 = +1.0 if t2 > +1.0 else t2
t2 = -1.0 if t2 < -1.0 else t2
Y = math.asin(t2)
 t3 = +2.0 *(w * z + x * y)
 t4 = +1.0 - 2.0 *(y * y + z * z)
 Z = math.atan2(t3, t4)
 return X, Y, Z
def fe(actual):
new = pd.DataFrame()
actual['total_angular_velocity'] =(actual['angular_velocity_X'] ** 2 + actual['angular_velocity_Y'] ** 2 + actual['angular_velocity_Z'] ** 2)** 0.5
actual['total_linear_acceleration'] =(actual['linear_acceleration_X'] ** 2 + actual['linear_acceleration_Y'] ** 2 + actual['linear_acceleration_Z'] ** 2)** 0.5
actual['acc_vs_vel'] = actual['total_linear_acceleration'] / actual['total_angular_velocity']
df = actual
xyz = np.vectorize(quaternion_to_euler )(df['orientation_X'], df['orientation_Y'], df['orientation_Z'], df['orientation_W'])
 actual['euler_x'] = xyz[0]
actual['euler_y'] = xyz[1]
actual['euler_z'] = xyz[2]
actual['total_angle'] =(actual['euler_x'] ** 2 + actual['euler_y'] ** 2 + actual['euler_z'] ** 2)** 5
actual['angle_vs_acc'] = actual['total_angle'] / actual['total_linear_acceleration']
actual['angle_vs_vel'] = actual['total_angle'] / actual['total_angular_velocity']
series_groups = df.groupby("series_id")
 def f1(x):
return np.mean(np.diff(np.abs(np.diff(x))))
def f2(x):
return np.mean(np.abs(np.diff(x)))
 def fx_raw(x):
diff = np.diff(x)
 diff = np.concatenate([[np.nan], diff])
 abs_diff = np.abs(diff)
 abs_diff_diff = np.abs(np.diff(abs_diff))
abs_diff_diff = np.concatenate([[np.nan], abs_diff_diff])
 raw_array = np.array(( abs_diff, abs_diff_diff, diff))
return raw_array
def fx_sum(x):
abs_max = np.max(np.abs(x))
abs_min = np.min(np.abs(x))
abs_diff = np.abs(np.diff(x))
abs_diff_avg = np.mean(abs_diff)
 abs_diff_diff = np.abs(np.diff(abs_diff))
abs_diff_diff_avg = np.mean(abs_diff_diff)
 sum_diff = np.sum(np.diff(x))
sum_abs_diff = np.sum(abs_diff)
 count_diffs = np.count_nonzero(x)
 sum_array = np.array(( abs_max, abs_min, abs_diff_avg, abs_diff_diff_avg,
sum_diff, sum_abs_diff, count_diffs))
return sum_array
for col in tqdm(actual.columns):
if col in ['row_id', 'series_id', 'measurement_number', 'target']:
continue
new[col + '_mean'] = series_groups[col].mean()
new[col + '_min'] = series_groups[col].min()
new[col + '_max'] = series_groups[col].max()
new[col + '_std'] = series_groups[col].std()
new[col + '_max_to_min'] = new[col + '_max'] / new[col + '_min']
xyz = series_groups[col].apply(fx_sum)
 rows = len(series_groups)
 col_count = len(xyz[0])
 xyz_sum = np.concatenate(xyz ).reshape(rows, col_count)
 column_names = [col+"_abs_max", col+"_abs_min",
col+"_abs_diff_avg", col+"_abs_diff_diff_avg",
col+"_sum_diff", col+"_sum_abs_diff",
col+"_count_diff"
]
df_xyz_sum = pd.DataFrame(xyz_sum, columns=column_names)
 new = pd.concat([new, df_xyz_sum], axis=1)
 xyz = series_groups[col].apply(fx_raw)
 xyz_c = np.concatenate(xyz, axis=1)
 df_xyz_raw = pd.DataFrame({col+"_abs_diff": xyz_c[0],
col+"_abs_diff_diff": xyz_c[1],
col+"_diff": xyz_c[2]
})
 actual = pd.concat([actual, df_xyz_raw], axis=1)
 return new, actual<feature_engineering>
!kaggle competitions submit LANL-Earthquake-Prediction -f {'submission.csv'} -m "More features"