Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<feature_engineering>
def mean_absolute_percentage_error(y_true, y_pred):
y_true, y_pred = np.array(y_true), np.array(y_pred)
 return np.mean(np.abs(( y_true - y_pred)/ y_true)) * 100
warnings.filterwarnings("ignore")
 warnings.simplefilter(action='ignore', category=FutureWarning)
 pd.set_option('display.max_columns', None)
 pd.options.display.float_format = '{:.2f}'.format
for i in test_data:
if i not in train_data.columns:
train_data[i]=np.zeros(len(train_data))<prepare_x_and_y>
train = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/train.csv")
 test = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/test.csv")
 df = train.append(test)
 print("Num of Object Variables:", df.select_dtypes(object ).shape[1])
 print("Num of Integer Variables:", df.select_dtypes("integer" ).shape[1])
 print("Num of Float Variables:", df.select_dtypes("float" ).shape[1])
 df.shape, train.shape, test.shape
X = train_data.drop(['RefId','IsBadBuy'],axis=1)
 y = train_data['IsBadBuy']<split>
def missing_values(data, plot = False, target = "SalePrice"):
mst = pd.DataFrame({"Num_Missing":data.isnull().sum() , "Missing_Ratio":data.isnull().sum() / data.shape[0]} ).sort_values("Num_Missing", ascending = False)
 mst["DataTypes"] = data[mst.index].dtypes.values
mst = mst[mst.Num_Missing > 0].reset_index().rename({"index":"Feature"}, axis = 1)
 mst = mst[mst.Feature != target]
print("Number of Variables include Missing Values:", mst.shape[0], "
")
 if mst[mst.Missing_Ratio >= 1.0].shape[0] > 0:
print("Full Missing Variables:",mst[mst.Missing_Ratio >= 1.0].Feature.tolist())
 data.drop(mst[mst.Missing_Ratio >= 1.0].Feature.tolist() , axis = 1, inplace = True)
 print("Full missing variables are deleted!", "
")
 if plot:
plt.figure(figsize =(25, 8))
p = sns.barplot(mst.Feature, mst.Missing_Ratio)
 for rotate in p.get_xticklabels() :
rotate.set_rotation(90)
 print(mst, "
")
 missing_values(df, plot = True, target = "SalePrice" )
X_train,X_test,y_train,y_test = train_test_split(X,y )<train_model>
cat_missing = ["Alley", 'BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1','BsmtFinType2','Fence', "MiscFeature",
"FireplaceQu", "GarageFinish","GarageCond", "GarageQual", "GarageType", "MasVnrType"]
for i in cat_missing:
df[i] = np.where(df[i].isnull() , "None", df[i])
 missing_values(df, plot = False, target = "SalePrice" )
knn = KNeighborsClassifier(n_neighbors=7)
 knn.fit(X_train,y_train)
 knn.score(X_test,y_test )<predict_on_test>
df["GarageYrBlt"]= np.where(( df.GarageYrBlt.isnull() == True)&(df.GarageArea == 0), df.YearBuilt,df.GarageYrBlt )
prediction = knn.predict(test_data.drop("RefId",axis=1)) 
<create_dataframe>
def quick_missing_imp(data, num_method = "median", cat_length = 20, target = "SalePrice"):
variables_with_na = [col for col in data.columns if data[col].isnull().sum() > 0]
temp_target = data[target]
print("
print(data[variables_with_na].isnull().sum() , "
")
 data = data.apply(lambda x: x.fillna(x.mode() [0])if(x.dtype == "O" and len(x.unique())<= cat_length)else x, axis=0)
 if num_method == "mean":
data = data.apply(lambda x: x.fillna(x.mean())if x.dtype != "O" else x, axis=0)
 elif num_method == "median":
data = data.apply(lambda x: x.fillna(x.median())if x.dtype != "O" else x, axis=0)
 data[target] = temp_target
print("
Imputation method is 'MODE' for categorical variables!")
 print(" Imputation method is '" + num_method.upper() + "' for numeric variables!
")
 print(data[variables_with_na].isnull().sum() , "
")
 return data
df = quick_missing_imp(df, num_method = "median", cat_length = 17 )
submission = pd.DataFrame(data=prediction,columns=["IsBadBuy"])
 submission["RefId"] = test_data["RefId"]
submission.set_index("RefId",inplace=True )<save_to_csv>
ordinal_vars = [
"LotShape", "OverallQual", "OverallCond", "ExterQual", "ExterCond", "BsmtQual",
"BsmtCond", "BsmtExposure", "BsmtFinType1", "BsmtFinType2", "HeatingQC", "KitchenQual", "Functional",
"FireplaceQu", "GarageQual", "GarageCond", "Fence", "Electrical"
]
def ordinal(serie, category):
numeric = np.arange(1, len(category)+1, 1)
 zip_iterator = zip(category, numeric)
 mapping = dict(zip_iterator)
 serie = serie.map(mapping)
 return serie
def transform_ordinal(data, ordinal_vars, category):
for i in ordinal_vars:
data[i] = ordinal(data[i], category = category)
 transform_ordinal(
 df,
ordinal_vars = ["ExterQual", "ExterCond", "HeatingQC","KitchenQual"],
category = ["Po", "Fa", "TA", "Gd" ,"Ex"] 
)
 transform_ordinal(
 df,
ordinal_vars = ["BsmtQual", "BsmtCond", "FireplaceQu","GarageCond", "GarageQual"],
category = ["None", "Po", "Fa", "TA", "Gd","Ex"] 
)
 transform_ordinal(
 df,
ordinal_vars = ["BsmtFinType1", "BsmtFinType2"],
category = ["None", "Unf", "LwQ", "Rec", "BLQ", "ALQ","GLQ"] 
)
 df["LotShape"] = ordinal(df["LotShape"], category = ["IR3", "IR2", "IR1","Reg"])
 df["BsmtExposure"] = ordinal(df["BsmtExposure"], category = ["None", "No", "Mn", "Av","Gd"])
 df["Functional"] = ordinal(df["Functional"], category = ["Sal", "Sev", "Maj2", "Maj1", "Mod", "Min2", "Min1","Typ"])
 df["Fence"] = ordinal(df["Fence"], category = ["None", "MnWw", "GdWo", "MnPrv","GdPrv"])
 df["Electrical"] = ordinal(df["Electrical"], category = ['SBrkr', 'FuseA', 'FuseF', 'FuseP', 'Mix'])
 print("Ordinal transformation completed!" )
submission.to_csv("submission.csv" )<load_from_csv>
for i in ["Street", "Utilities", "LandSlope", "MiscFeature"]:
print(df[i].value_counts() )
train_data = pd.read_csv("/kaggle/input/DontGetKicked/training.csv")
 train_data.head()<load_from_csv>
def cat_eda(data, cat_length, target = "SalePrice"):
dataframe = data.copy()
more_cat_cols = [col for col in dataframe.columns if len(dataframe[col].unique())< cat_length]
for i in more_cat_cols:
print(i, ":", len(dataframe[i].value_counts()), "Unique Category -", str(dataframe[i].dtype))
print(pd.DataFrame({"COUNT": dataframe[i].value_counts() ,
"RATIO": dataframe[i].value_counts() / len(dataframe),
"TARGET_MEDIAN": dataframe.groupby(i)[target].median() ,
"TARGET_COUNT": dataframe.groupby(i)[target].count() ,
"TARGET_STD": dataframe.groupby(i)[target].std() }), end="
")
 print("
print("Object Variables:",dataframe[more_cat_cols].select_dtypes("object" ).columns.tolist() , "
")
 print("Integer Variables:",dataframe[more_cat_cols].select_dtypes("integer" ).columns.tolist() , "
")
 print("Float Variables:",dataframe[more_cat_cols].select_dtypes("float" ).columns.tolist() , "
")
 cat_eda(df, cat_length=17 )
test_data = pd.read_csv("/kaggle/input/DontGetKicked/test.csv")
 test_data.head()<count_missing_values>
drop_list = ["Street", "Utilities", "LandSlope", "MiscFeature", "PoolArea"]
for col in drop_list:
df.drop(col, axis=1, inplace=True )
train_data.isnull().sum()<count_missing_values>
df2["TotalQual"] = df2[["OverallQual", "OverallCond", "ExterQual", "ExterCond", "BsmtCond", "BsmtFinType1",
"BsmtFinType2", "HeatingQC", "KitchenQual", "Functional", "FireplaceQu", "GarageQual", "GarageCond", "Fence"]].sum(axis = 1)
 df2["BsmtQual"] = df2[["BsmtCond", "BsmtFinType1", "BsmtFinType2"]].sum(axis = 1)
 df2["TotalGarageQual"] = df2[["GarageQual", "GarageCond"]].sum(axis = 1)
 df2["Overall"] = df2[["OverallQual", "OverallCond"]].sum(axis = 1)
 df2["Exter"] = df2[["ExterQual", "ExterCond"]].sum(axis = 1)
 df2["ExtraQual"] = df2[["Fence", "FireplaceQu", "Functional", "HeatingQC"]].sum(axis = 1)
 df2["Qual"] = df2[["OverallQual", "ExterQual", "GarageQual", "Fence", "BsmtFinType1", "BsmtFinType2", "KitchenQual", "FireplaceQu"]].sum(axis = 1)
 df2["Cond"] = df2[["OverallCond", "ExterCond", "GarageCond", "BsmtCond", "HeatingQC", "Functional"]].sum(axis = 1 )
test_data.isnull().sum()<count_values>
cat_eda(df2[ordinal_vars+["SalePrice"]], cat_length=17 )
train_data['IsBadBuy'].value_counts()<count_values>
df2["LotShape"] = np.where(df2.LotShape == 1, 2, df2["LotShape"])
 df2["OverallQual"] = np.where(df2.OverallQual.isin([1,2]), 3, df2["OverallQual"])
 df2["OverallCond"] = np.where(df2.OverallCond.isin([1,2]), 3, df2["OverallCond"])
 df2["OverallCond"] = np.where(df2.OverallCond.isin([7,8]), 6, df2["OverallCond"])
 df2["ExterCond"] = np.where(df2.ExterCond.isin([1,2]), 0, 1)
 df2["BsmtQual"] = np.where(df2.BsmtQual.isin([3,6]), 7, df2["BsmtQual"])
 df2["BsmtQual"] = np.where(df2.BsmtQual.isin([17,18]), 16, df2["BsmtQual"])
 df2["BsmtQual"] = np.where(df2.BsmtQual.isin([9,10,11]), 12, df2["BsmtQual"])
 df2["BsmtCond"] = np.where(df2.BsmtCond == 1, 2, df2["BsmtCond"])
 df2["HeatingQC"] = np.where(df2.HeatingQC == 1, 2, df2["HeatingQC"])
 df2["Functional"] = np.where(df2.Functional == 8, 1, 0)
 df2["GarageQual"] = np.where(df2.GarageQual == 1, 2, df2["GarageQual"])
 df2["GarageQual"] = np.where(df2.GarageQual == 6, 5, df2["GarageQual"])
 df2["GarageCond"] = np.where(df2.GarageCond == 1, 2, df2["GarageCond"])
 df2["GarageCond"] = np.where(df2.GarageCond == 6, 5, df2["GarageCond"])
 df2["Fence"] = np.where(df2.Fence.isin([2,4]), 3, df2["Fence"])
 df2["Electrical"] = np.where(df2["Electrical"].isin([5, 4]), 3, df2["Electrical"] )
train_data['Model'].value_counts()
train_data.drop("Model",axis=1,inplace=True)
 test_data.drop("Model",axis=1,inplace=True )<drop_column>
cat_eda(df2[ordinal_vars+["SalePrice"]], cat_length=17 )
train_data.drop("Trim",axis=1,inplace=True)
 test_data.drop("Trim",axis=1,inplace=True)
 train_data.drop("SubModel",axis=1,inplace=True)
 test_data.drop("SubModel",axis=1,inplace=True )<count_values>
df2["TotalFlrSF"] = df2["1stFlrSF"] + df2["2ndFlrSF"]
df2["TotalBsmtFin"] = df2.BsmtFinSF1+df2.BsmtFinSF2
df2["BsmtFinRatio"] =(df2.TotalBsmtFin / df2.TotalBsmtSF ).fillna(0)
 df2["Basement"] = np.where(df2.TotalBsmtSF < 1 , 0, 1)
 df2["PorchArea"] = df2.OpenPorchSF + df2.EnclosedPorch + df2.ScreenPorch + df2["3SsnPorch"] + df2.WoodDeckSF
df2["TotalHouseArea"] = df2.TotalFlrSF + df2.TotalBsmtSF
df2["TotalSqFeet"] = df2.GrLivArea + df2.TotalBsmtSF
df2["BsmtRoom"] = np.where(( df2.BsmtFinSF1 > 0)&(df2.BsmtFinSF2 < 1), 1, np.nan)
 df2["BsmtRoom"] = np.where(( df2.BsmtFinSF1 < 1)&(df2.BsmtFinSF2 > 0), 1, df2["BsmtRoom"])
 df2["BsmtRoom"] = np.where(( df2.BsmtFinSF1 < 1)&(df2.BsmtFinSF2 < 1), 0, df2["BsmtRoom"])
 df2["BsmtRoom"] = np.where(( df2.BsmtFinSF1 > 0)&(df2.BsmtFinSF2 > 0), 2, df2["BsmtRoom"])
 df2["Floor"] = np.where(( df2["2ndFlrSF"] < 1), 1, 2)
 df2["FullBath"] = np.where(df2.FullBath == 4, 3, df2.FullBath)
 df2["BsmtFullBath"] = np.where(df2.BsmtFullBath == 3, 2, df2.BsmtFullBath)
 df2["TotalFullBath"] = df2.BsmtFullBath + df2.FullBath
df2["TotalHalfBath"] = df2.BsmtHalfBath + df2.HalfBath
df2["TotalBath"] = df2["TotalFullBath"] +(df2["TotalHalfBath"]*0.5)
 df2["TotalBath"] = np.where(df2.TotalBath.isin([6,7]), 5, df2.TotalBath)
 df2["Fireplaces"] = np.where(df2.Fireplaces > 3, 3, df2.Fireplaces)
 df2["GarageAreaRatio"] =(df2.GarageArea / df2.GarageCars ).fillna(0)
 df2["GarageCars"] = np.where(df2.GarageCars > 3, 3, df2.GarageCars)
 df2["TotRmsAbvGrd"] = np.where(df2.TotRmsAbvGrd > 12, 12, df2.TotRmsAbvGrd)
 df2["TotRmsAbvGrd"] = np.where(df2.TotRmsAbvGrd == 2, 3, df2.TotRmsAbvGrd)
 df2["LotRatio"] = df2.GrLivArea / df2.LotArea
df2["RatioArea"] = df2.TotalHouseArea / df2.LotArea
df2["GarageLotRatio"] = df2.GarageArea / df2.LotArea
df2["MasVnrRatio"] = df2.MasVnrArea / df2.TotalHouseArea
df2["DifArea"] =(df2.LotArea - df2["1stFlrSF"] - df2.GarageArea - df2.PorchArea - df2.WoodDeckSF)
 df2["LowQualFinSFRatio"] = df2.LowQualFinSF / df2.TotalHouseArea
df2["OverallGrade"] = df2["OverallQual"] * df2["OverallCond"]
df2["GarageGrade"] = df2["GarageQual"] * df2["GarageCond"]
df2["ExterGrade"] = df2["ExterQual"] * df2["ExterCond"]
df2["KitchenScore"] = df2["KitchenAbvGr"] * df2["KitchenQual"]
df2["FireplaceScore"] = df2["Fireplaces"] * df2["FireplaceQu"]
df2["HasMasVnrType"] = np.where(df2.MasVnrType == "None", 0, 1)
 df2["BoughtOffPlan"] = np.where(df2.SaleCondition == "Partial", 1, 0 )
train_data["Color"].value_counts(dropna=False )<count_values>
df2.YearRemodAdd = np.where(df2.YearBuilt > df2.YearRemodAdd, df2.YearBuilt, df2.YearRemodAdd)
 df2.YrSold = np.where(df2.YearBuilt > df2.YrSold, df2.YearBuilt, df2.YrSold)
 df2.YrSold = np.where(df2.YearRemodAdd > df2.YrSold, df2.YearRemodAdd, df2.YrSold)
 df2["Restoration"] = df2.YearRemodAdd - df2.YearBuilt
df2["HouseAge"] = df2.YrSold - df2.YearBuilt
df2["RestorationAge"] = df2.YrSold - df2.YearRemodAdd
df2["GarageAge"] = df2.GarageYrBlt - df2.YearBuilt
df2["GarageRestorationAge"] = np.abs(df2.GarageYrBlt - df2.YearRemodAdd)
 df2["GarageSold"] = df2.YrSold - df2.GarageYrBlt
df2.GarageYrBlt = np.where(df2.GarageAge < 0, df2.YearBuilt, df2.GarageYrBlt)
 df2.GarageYrBlt = np.where(( df2.GarageYrBlt == 2207), df2.YearBuilt, df2.GarageYrBlt)
 df2["GarageAge"] = df2.GarageYrBlt - df2.YearBuilt
df2["GarageSold"] = df2.YrSold - df2.GarageYrBlt
df2["Remodeled"] = np.where(df2.YearBuilt == df2.YearRemodAdd, 0 ,1)
 df2["IsNewHouse"] = np.where(df2.YearBuilt == df2.YrSold, 1 ,0)
 df2["YearBuiltCut"] = pd.cut(df2.YearBuilt, 15, labels = np.arange(1,16,1))
df2["GarageYearBuiltCut"] = pd.cut(df2.YearBuilt, 15, labels = np.arange(1,16,1))
df2["RemodAddCut"] = pd.cut(df2.YearRemodAdd, 10, labels = np.arange(1, 11, 1))
df2["GreatDepression"] = np.where(( df2.YearBuilt >=1929)&(df2.YearBuilt <= 1939), 1,0)
 df2["BeforeGreatDepression"] = np.where(( df2.YearBuilt <1929), 1,0)
 df2["Mortgage"] = np.where(( df2.YearBuilt >=2007)&(df2.YearBuilt <= 2010), 1,0)
 df2["MortgageRestoration"] = np.where(( df2.YearRemodAdd >=2007)&(df2.YearRemodAdd <= 2010), 1,0)
 for i in ["GreatDepression","BeforeGreatDepression", "Mortgage","MortgageRestoration"]:
print(df2.groupby(i ).SalePrice.agg(["count", "median"]), "
")
 df2.drop(["YearBuilt", "GarageYrBlt", "YearRemodAdd"], axis = 1, inplace = True )
test_data["Color"].value_counts(dropna=False )<categorify>
cat_eda(df2[set(df2.columns ).difference(ordinal_vars)], cat_length=17 )
train_data["Color"].fillna(value="ColorUnknown",inplace=True)
 test_data["Color"].fillna(value="ColorUnknown",inplace=True )<count_values>
cat_eda(df2[set(df2.columns ).difference(ordinal_vars)], cat_length=17 )
train_data["Transmission"].value_counts(dropna=False )<rename_columns>
def label_encoder(dataframe):
labelencoder = preprocessing.LabelEncoder()
label_cols = [col for col in dataframe.columns if dataframe[col].dtypes == "O"
and len(dataframe[col].value_counts())== 2]
for col in label_cols:
dataframe[col] = labelencoder.fit_transform(dataframe[col])
 return dataframe
df2 = label_encoder(df2)
 cat_cols = [col for col in df2.columns if df2[col].dtypes == 'O']
def one_hot_encoder(dataframe, categorical_cols, nan_as_category=True):
original_columns = list(dataframe.columns)
 dataframe = pd.get_dummies(dataframe, columns=categorical_cols, dummy_na=nan_as_category, drop_first=True)
 new_columns = [c for c in dataframe.columns if c not in original_columns]
return dataframe, new_columns
df2, new_cols_ohe = one_hot_encoder(df2, cat_cols, nan_as_category=False)
 df2.shape
train_data["Transmission"].replace("Manual","MANUAL",inplace=True )<count_values>
train_model = df2[df2.Id.isin(train.Id)]
test_model = df2[df2.Id.isin(test.Id)]
test_model.drop("SalePrice", axis = 1, inplace = True)
 X = train_model.drop(['SalePrice', "Id"], axis=1)
 y = train_model[["SalePrice"]]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=46)
 lgb_param = {
"nthread": -1,
"objective": "regression",
"metric": "rmse",
"verbose": -1,
}
reg = lgb.LGBMRegressor(
 random_state=46, **lgb_param 
)
 reg.fit(X_train,y_train,
eval_set=[(X_train, y_train),(X_test, y_test)],
eval_metric = ["rmse", "mae"],
eval_names=["Train", "Valid"],
early_stopping_rounds=10,
verbose=10,
categorical_feature='auto')
 print("")
 print("Train RMSE:", "{:,.2f}".format(np.sqrt(mean_squared_error(y_train, reg.predict(X_train)))))
 print("Train RMSE:", "{:,.2f}".format(np.sqrt(mean_squared_error(y_test, reg.predict(X_test)))) , "
")
 print("Train MAE:", "{:,.2f}".format(mean_absolute_error(y_train, reg.predict(X_train))))
print("Valid MAE:", "{:,.2f}".format(mean_absolute_error(y_test, reg.predict(X_test))), "
")
 print("Train MAPE:", "{:,.2f}".format(mean_absolute_percentage_error(y_train, reg.predict(X_train))))
print("Valid MAPE:", "{:,.2f}".format(mean_absolute_percentage_error(y_test, reg.predict(X_test))), "
")
 print("Train R^2:", "{:,.2f}".format(r2_score(y_train, reg.predict(X_train))))
print("Valid R^2:", "{:,.2f}".format(r2_score(y_test, reg.predict(X_test))))
test_data["Transmission"].value_counts(dropna=False )<data_type_conversions>
lgb_param = {
"nthread": -1,
"objective": "regression",
"metric": "rmse",
"verbose": -1,
}
reg = lgb.LGBMRegressor(
 random_state=46, **lgb_param 
)
 reg.fit(X,y)
 print("Train RMSE:","{:,.2f}".format(np.sqrt(mean_squared_error(y, reg.predict(X)))))
 print("Train MAE:", "{:,.2f}".format(mean_absolute_error(y, reg.predict(X))), "
")
 print("CV RMSE:", "{:,.2f}".format(np.sqrt(-cross_val_score(reg, X, y, cv=10, scoring="neg_mean_squared_error")).mean()))
print("CV MAE:", "{:,.2f}".format(-cross_val_score(reg, X, y, cv=10, scoring="neg_mean_absolute_error" ).mean()))
train_data["Transmission"].fillna(value="Trans_unk",inplace=True)
 test_data["Transmission"].fillna(value="Trans_unk",inplace=True )<count_values>
lgb_param = {
"nthread": -1,
"objective": "regression",
"metric": "rmse",
"verbose": -1
}
reg = lgb.LGBMRegressor(
 random_state=46, **lgb_param 
)
 reg.fit(X_train,y_train)
 print("Train RMSE:", "{:,.2f}".format(np.sqrt(mean_squared_error(y_train, reg.predict(X_train)))))
 print("Train MAE:", "{:,.2f}".format(mean_absolute_error(y_train, reg.predict(X_train))), "
")
 print("CV RMSE:", "{:,.2f}".format(np.sqrt(-cross_val_score(reg, X_train, y_train, cv=10, scoring="neg_mean_squared_error")).mean()))
print("CV MAE:", "{:,.2f}".format(-cross_val_score(reg, X_train, y_train, cv=10, scoring="neg_mean_absolute_error" ).mean()), "
")
 print("Valid RMSE:", "{:,.2f}".format(np.sqrt(mean_squared_error(y_test, reg.predict(X_test)))))
 print("Valid MAE:", "{:,.2f}".format(mean_absolute_error(y_test, reg.predict(X_test))), "
" )
train_data["WheelTypeID"].value_counts(dropna=False)
 train_data.drop("WheelTypeID",axis=1,inplace=True)
 test_data.drop("WheelTypeID",axis=1,inplace=True )<count_values>
params = {
'learning_rate': [0.1, 0.09, 0.08, 0.07, 0.05],
'max_depth': [-1] + np.arange(5, 36, 1),
'num_leaves':np.arange(20, 81, 1),
'n_estimators':[50, 100, 500, 1000, 3000, 5000, 10000],
'max_bin':np.arange(150, 301, 1),
'min_data_in_leaf':np.arange(15, 61, 1),
"feature_fraction_seed":np.arange(2, 1001, 1),
"feature_fraction":np.arange(0.1, 1.01, 0.01),
"bagging_freq":[0],
"bagging_fraction":[1],
"min_sum_hessian_in_leaf":[1e-2,1e-3, 1e-4, 1e-5, 1e-6],
"lambda_l1":np.arange(0.0, 1.1, 0.1),
"lambda_l2":np.arange(0.0, 1.1, 0.1),
"min_gain_to_split ": np.arange(0, 101, 1)
 }
reg = lgb.LGBMRegressor(
 random_state=46, objective = "rmse", metric = "rmse" 
)
 rs = RandomizedSearchCV(reg, params, random_state=46, n_jobs=-1, cv = 10, scoring = "neg_mean_squared_error")
 rs_lgbm = rs.fit(X_train, y_train,
eval_set=[(X_train, y_train),(X_test, y_test)],
eval_metric = ["rmse", "mae"],
eval_names=["Train"],
early_stopping_rounds=10,
verbose=10,
categorical_feature='auto')
 print("")
 print("Train RMSE:", "{:,.2f}".format(np.sqrt(mean_squared_error(y_train, rs_lgbm.predict(X_train)))))
 print("Train MAE:", "{:,.2f}".format(mean_absolute_error(y_train, rs_lgbm.predict(X_train))), "
")
 print("CV RMSE:", "{:,.2f}".format(np.sqrt(-rs_lgbm.cv_results_["mean_test_score"] ).mean()))
print("CV RMSE STD:", "{:,.2f}".format(np.sqrt(rs_lgbm.cv_results_["std_test_score"] ).mean()), "
")
 print("Test RMSE:", "{:,.2f}".format(np.sqrt(mean_squared_error(y_test, rs_lgbm.predict(X_test)))))
 print("Test MAE:", "{:,.2f}".format(mean_absolute_error(y_test, rs_lgbm.predict(X_test))), "
")
 print("--------------------------------------")
 print("
print("--------------------------------------")
 print(rs_lgbm.best_params_ )
train_data["WheelType"].value_counts(dropna=False )<data_type_conversions>
res.sort_values("AbsoluteError", ascending = False ).head(20 )
<count_values><EOS> 
train_model = df2[df2.Id.isin(train.Id)]
test_model = df2[df2.Id.isin(test.Id)]
test_model.drop("SalePrice", axis = 1, inplace = True)
 X = train_model.drop(['SalePrice', "Id"], axis=1)
 y = train_model[["SalePrice"]]
final = lgb.LGBMRegressor(
 random_state=46, objective = "regression", metric = "rmse",
**rs_lgbm.best_params_ 
)
 final.fit(X,y,
eval_set=[(X,y)],
eval_metric = ["rmse", "mae"],
eval_names=["Train"],
early_stopping_rounds=10,
verbose=1000,
categorical_feature='auto')
 submission = pd.DataFrame({"Id": test_model.Id, "SalePrice":final.predict(test_model.drop("Id", axis = 1)) })
 submission.to_csv("submission.csv", index = None )