text_plain_output_1.png
from sklearn.model_selection import KFold

import lightgbm as lgbm

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')
sample_sub = pd.read_csv('../input/sample_submission.csv')

from copy import copy
X_train = train.drop(columns=['scalar_coupling_constant']).copy()
y_train = train['scalar_coupling_constant'].copy()
X_test = test.copy()

X_train = X_train.drop(columns=['id'])
X_test = X_test.drop(columns=['id'])

from sklearn.model_selection import KFold
from sklearn.metrics import mean_absolute_error as mae
kf = KFold(n_splits=5)
fold = 0
for train_index, val_index in kf.split(X_train):
    fold += 1
    lgbm_model = lgbm.LGBMRegressor()
    lgbm_model.fit(X_train.loc[train_index, :], y_train[train_index])
    y_val = lgbm_model.predict(X_train.loc[val_index, :])
    print(f'fold{fold} score: {mae(y_train[val_index], y_val)}')