<jupyter_start><jupyter_text>Setup<jupyter_code>!pip install sklearn --upgrade -q
!pip install catboost -q
import numpy as np
import pandas as pd
import sklearn
from sklearn.tree import DecisionTreeRegressor
from sklearn.pipeline import Pipeline
from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.compose import ColumnTransformer
from sklearn.metrics import mean_absolute_error
from xgboost import XGBRegressor
from sklearn.ensemble import RandomForestRegressor, ExtraTreesRegressor
from catboost import CatBoostRegressor
import lightgbm as lgb<jupyter_output><empty_output><jupyter_text>Preprocessing<jupyter_code>train_df = pd.read_csv(r"../input/ventilator-pressure-prediction/train.csv")
train_ids = train_df["id"]
train_df = train_df.drop(columns=["breath_id", "id"])
y = train_df["pressure"]
X = train_df.drop(columns=["pressure"])
num_attribs = ["time_step", "u_in"]
cat_attribs = ["R", "C", "u_out"]

num_pipeline = Pipeline([
    ("imputer", SimpleImputer(strategy="median")),
    ("standard_scaler", StandardScaler())
])


full_pipeline = ColumnTransformer([
    ("num_pipeline", num_pipeline, num_attribs),
    ("1hot_encoder", OneHotEncoder(), cat_attribs)
])

X_tfm = full_pipeline.fit_transform(X)<jupyter_output><empty_output><jupyter_text>Training<jupyter_code>xgb_clf = XGBRegressor(tree_method='gpu_hist')
cb_clf = CatBoostRegressor(task_type="GPU", )
lgbm_params = {
    "objective":"regression",
}
train_fold_df = pd.read_csv(r"../input/always-splitting-data-first/train_folds.csv")
train_fold_df
lgbm_5_fold = {}
train_fold_df = pd.read_csv(r"../input/always-splitting-data-first/train_folds.csv")

for fold in range(5):
    lgbm_y = train_fold_df[train_fold_df.kfold == fold]["pressure"][:160000]
    X = train_fold_df[train_fold_df.kfold == fold].drop(columns=["id", "breath_id", "kfold", "pressure"])[:160000]
    lgbm_X_tfm = full_pipeline.transform(X)
    
    X_train = lgb.Dataset(lgbm_X_tfm, label=lgbm_y.values)
    lgb_clf = lgb.train(lgbm_params, X_train, num_boost_round=10000)
    lgbm_5_fold[fold] = lgb_clf

# xgb_clf.fit(X_tfm, y.values)
# cb_clf.fit(X_tfm, y.values)
xgb_clf.fit(X_tfm, y.values)
cb_clf.fit(X_tfm, y.values)<jupyter_output><empty_output><jupyter_text>Inference<jupyter_code>test_df = pd.read_csv(r"../input/ventilator-pressure-prediction/test.csv")
test_ids = test_df["id"]
test_df = test_df.drop(columns=["id"])
X_test = full_pipeline.fit_transform(test_df)
preds = xgb_clf.predict(X_test)
preds_1 = cb_clf.predict(X_test)
preds = (preds + preds_1)/2
lgbm_preds = []
for fold, lgbm in lgbm_5_fold.items():
    preds = lgbm.predict(X_test)
    lgbm_preds.append(preds)
    break
preds_final = lgbm_preds[0] + preds
preds_final<jupyter_output><empty_output><jupyter_text>Submission<jupyter_code>submission = pd.DataFrame({
    "id": test_ids,
    "pressure": preds
})
submission.to_csv("submission.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1306649024148197, 'fraction_numerical': 0.008600727753886867, 'mean_word_length': 7.0, 'pattern_counts': {'":': 3, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '572375', 'license': 'MIT', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1180, 'n_words': 177, 'path': 'src/xgboost-ens-lgbm.ipynb', 'repo_name': 'alckasoc/Google-Ventilation-Pressure-Competition', 'size': '3023'}