text_html_output_1.png
from sklearn.model_selection import train_test_split, KFold

import lightgbm as lgbm

import numpy as np

import pandas as pd

df = pd.read_csv('/kaggle/input/playground-series-s3e9/train.csv')
df.drop(columns='id', inplace=True)

df_add = pd.read_csv('/kaggle/input/predict-concrete-strength/ConcreteStrengthData.csv')
df_add.rename(columns={'CementComponent ': 'CementComponent'}, inplace=True)
df = pd.concat([df, df_add])

df_test = pd.read_csv('/kaggle/input/playground-series-s3e9/test.csv')
df_test.drop(columns='id', inplace=True)

y = df.pop('Strength')
df['tot_comp'] = df.iloc[:, :7].sum(axis=1)
df['coarse_fine'] = df.CoarseAggregateComponent / df.FineAggregateComponent
df['Aggregate'] = df['CoarseAggregateComponent'] + df['FineAggregateComponent']
df['Slag_Cement'] = df['BlastFurnaceSlag'] / df['CementComponent']
df['Ash_Cement'] = df['FlyAshComponent'] / df['CementComponent']
df['Plastic_Cement'] = df['SuperplasticizerComponent'] / df['CementComponent']
df['Age_Water'] = df['AgeInDays'] / df['WaterComponent']
df_test['tot_comp'] = df_test.iloc[:, :7].sum(axis=1)
df_test['coarse_fine'] = df_test.CoarseAggregateComponent / df_test.FineAggregateComponent
df_test['Aggregate'] = df_test['CoarseAggregateComponent'] + df_test['FineAggregateComponent']
df_test['Slag_Cement'] = df_test['BlastFurnaceSlag'] / df_test['CementComponent']
df_test['Ash_Cement'] = df_test['FlyAshComponent'] / df_test['CementComponent']
df_test['Plastic_Cement'] = df_test['SuperplasticizerComponent'] / df_test['CementComponent']
df_test['Age_Water'] = df_test['AgeInDays'] / df_test['WaterComponent']

splitter = KFold(n_splits=5, shuffle=True, random_state=231)

df_lgbm = lgbm.Dataset(df, label=y)
model_cv = lgbm.cv({'random_state': 97}, train_set=df_lgbm, num_boost_round=50, folds=splitter, nfold=5, metrics='rmse', return_cvbooster=True, eval_train_metric=True)

predictions = pd.DataFrame(np.array(model_cv['cvbooster'].predict(df_test)).T)

subs = pd.read_csv('/kaggle/input/playground-series-s3e9/sample_submission.csv')
subs.head()