text_plain_output_1.png
from sklearn.compose import make_column_transformer

from sklearn.linear_model import LinearRegression, Lasso, Ridge, SGDRegressor, ElasticNet

from sklearn.model_selection import train_test_split, StratifiedShuffleSplit, GridSearchCV

from sklearn.pipeline import make_pipeline

import numpy as np

import pandas as pd

data = pd.read_csv('/kaggle/input/refined-data/data_hard_refined.csv')
data_full = pd.read_csv('/kaggle/input/refined-data/data_filtered.csv')

data = data.drop(['SteamUse(kBtu)'], axis=1)

objectColumns = list(data.dtypes[data.dtypes == np.object].index)
numericColumns = list(data.dtypes[data.dtypes != np.object].index)

data = data.drop(['PropertyName', 'Address'], axis=1)

data = data.drop(['OSEBuildingID', 'TaxParcelIdentificationNumber'], axis=1)

objectColumns = list(data.dtypes[data.dtypes == np.object].index)
numericColumns = list(data.dtypes[data.dtypes != np.object].index)

y_columns = ['TotalGHGEmissions', 'SiteEnergyUse(kBtu)']
X = data.drop(y_columns, axis=1)
y = data[y_columns]
for i in y_columns:
    numericColumns.remove(i)

preprocessor = make_column_transformer((RobustScaler(), numericColumns), (OneHotEncoder(handle_unknown='ignore'), objectColumns))
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = make_pipeline(preprocessor, LinearRegression())
model.fit(X_train, y_train)
print("score d'entrainement = ", model.score(X_train, y_train))
y_pred = model.predict(X_test)
print('score de la prédiction:')
print('RMSE = ', mean_absolute_error(y_test, y_pred))
print('MAE = ', np.sqrt(mean_squared_error(y_test, y_pred)))
print('median abs err = ', median_absolute_error(y_test, y_pred))