In [1]:
import numpy as np
import pandas as pd
from sklearn.datasets import load_boston
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import cross_val_predict
import lightgbm


boston = load_boston()
X = pd.DataFrame(
    boston.data,
    columns=boston.feature_names,
)
y = boston.target
y_log1p = np.log1p(y)


regr = lightgbm.LGBMRegressor()
p = cross_val_predict(
    regr,
    X,
    y,
)
mse_y = mean_squared_error(y, p)


p_log1p = cross_val_predict(
    regr,
    X,
    y_log1p,
)
mse_y_log1p = mean_squared_error(y, np.expm1(p_log1p))

print("対数変換なし: mse = ", mse_y)
print("対数変換あり: mse = ", mse_y_log1p)
対数変換なし: mse =  22.336888518704814
対数変換あり: mse =  18.945004147490476