text_plain_output_1.png
from lightgbm import LGBMRegressor

from math import sqrt

from sklearn.compose import ColumnTransformer

from sklearn.impute import SimpleImputer

from sklearn.metrics import mean_squared_log_error

from sklearn.model_selection import train_test_split

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import StandardScaler, OneHotEncoder

import pandas as pd

train = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/train.csv', index_col=[0])
test = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/test.csv', index_col=[0])
sample = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/sample_submission.csv', index_col=[0])

train_clean = train.drop(columns=['MiscFeature', 'Fence', 'PoolQC', 'FireplaceQu', 'Alley'])
X = train_clean.drop(columns=['SalePrice'])
y = train_clean[['SalePrice']]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

num_feat = X_train.select_dtypes(include='number').columns.to_list()
cat_feat = X_train.select_dtypes(exclude='number').columns.to_list()
num_pipe = Pipeline([('imputer', SimpleImputer(strategy='mean')), ('scaler', StandardScaler())])
cat_pipe = Pipeline([('imputer', SimpleImputer(strategy='most_frequent')), ('encoder', OneHotEncoder(handle_unknown='ignore'))])
ct = ColumnTransformer(remainder='drop', transformers=[('numerical', num_pipe, num_feat), ('categorical', cat_pipe, cat_feat)])
model = Pipeline([('transformer', ct), ('predictor', LGBMRegressor())])

model.fit(X_train, y_train)

y_pred_train = model.predict(X_train)
y_pred_test = model.predict(X_test)

print('In sample error: ', sqrt(mean_squared_log_error(y_pred_train, y_train)))
print('Out sample error: ', sqrt(mean_squared_log_error(y_pred_test, y_test)))