Kaggle competition: House Prices - Advanced Regression Techniques
train_data['IsBadBuy'].value_counts()<count_values>
train_data = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test_data = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv')
 print(f'train shape : {train_data.shape} , test data : {test_data.shape}' )
train_data['Model'].value_counts()<drop_column>
x = train_data.iloc[:,0:80]
y = train_data.iloc[:,-1]
df = pd.concat([x,test_data],axis = 0)
 df = df.drop(['Id'], axis=1 )
train_data.drop('Model',axis=1,inplace=True)
 test_data.drop("Model",axis=1,inplace=True )<count_values>
drop_features = ['MSSubClass','OverallCond','BsmtFinType2','BsmtFinSF2','LowQualFinSF','BsmtHalfBath','PoolArea','MiscVal','MoSold', 'YrSold','GarageArea',
'1stFlrSF','TotRmsAbvGrd','GarageYrBlt','LotArea','Alley','LandContour','LandSlope','Heating','Electrical','BsmtExposure','BldgType',
'Utilities','Functional']
df.drop(drop_features,axis=1,inplace=True)
train_data['Trim'].value_counts()<drop_column>
def missing_values(data):
values = data.isnull().sum().sort_values(ascending = False)
 percentage =(data.isnull().sum() /data.isnull().count() *100 ).sort_values(ascending = False)
 missing_df = pd.concat([values,percentage], axis=1, keys=['Values', 'Percentage%'])
 return missing_df
missing_df = missing_values(df)
 missing_df.head(25 )
train_data.drop('Trim',inplace=True,axis=1)
 test_data.drop('Trim',inplace=True,axis=1 )<count_values>
df.drop([ 'PoolQC','MiscFeature','Fence','FireplaceQu'], axis=1, inplace=True)
 num_colums = ['LotFrontage','MasVnrArea','BsmtFullBath','BsmtFinSF1','TotalBsmtSF','BsmtUnfSF','GarageCars']
for col in num_colums:
df[col].fillna(df[col].mean() , inplace = True)
 catg_colums = ['GarageCond','GarageFinish','GarageQual','GarageType','BsmtCond','BsmtQual','BsmtFinType1','MasVnrType','MSZoning','Exterior1st','Exterior2nd',
'SaleType','KitchenQual']
for col in catg_colums:
df[col].fillna(df[col].value_counts().index[0], inplace=True )
train_data['SubModel'].value_counts()<drop_column>
df = pd.get_dummies(df, drop_first=True)
 df.head()
train_data.drop('SubModel',inplace=True,axis=1)
 test_data.drop('SubModel',inplace=True,axis=1 )<count_values>
minmax = MinMaxScaler()
normal_df = pd.DataFrame(minmax.fit_transform(df))
train_data['Color'].value_counts()<count_values>
train = normal_df.iloc[:1455,:].values
test = normal_df.iloc[1455:,:].values
test_data['Color'].value_counts()<data_type_conversions>
from sklearn.linear_model import LinearRegression,BayesianRidge,Ridge,Lasso,HuberRegressor,ElasticNet
from sklearn.ensemble import RandomForestRegressor,AdaBoostRegressor,BaggingRegressor,GradientBoostingRegressor
from catboost import CatBoostRegressor
from sklearn.svm import SVR
from lightgbm import LGBMRegressor
from xgboost import XGBRegressor
from mlxtend.regressor import StackingCVRegressor
import tensorflow as tf
from sklearn.model_selection import cross_val_score, KFold
from sklearn.metrics import mean_squared_error,make_scorer,r2_score
from sklearn.model_selection import RandomizedSearchCV
from keras.callbacks import ModelCheckpoint
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
train_data['Color'].fillna(value='Color_Unknown',inplace=True)
 test_data['Color'].fillna(value='Color_Unknown',inplace=True )<count_missing_values>
parameters = {'alpha':[0.001,0.01,0.1,1,2,3,40,50,100,200, 230, 250,265, 270, 275, 290, 300, 500]}
ridge_1 = Ridge()
randomSearch = RandomizedSearchCV(ridge_1, param_distributions=parameters, n_jobs=-1, cv=10)
 randomSearch.fit(train,y)
 bestpara = randomSearch.best_params_
def model(reg,train,label):

 cross_val = KFold(n_splits=10 ,shuffle= True , random_state= 0)
 rmsle = make_scorer(r2_score)
 validation = cross_val_score(reg ,train, label, cv=cross_val, scoring=rmsle,n_jobs=-1)
 return validation.mean()
model_1 = BayesianRidge()
score_1 = model(model_1,train,y)
 model_2 = CatBoostRegressor()
score_2 = model(model_2,train,y)
 ridge = Ridge(alpha=1)
 score = model(ridge,train,y)

stack_model = StackingCVRegressor(regressors=(model_1,model_2), meta_regressor=ridge)
 final_score = model(stack_model,train,y)
 stack_gen = stack_model.fit(train,y )
print("Number of null values in Color column "+str(train_data['Color'].isnull().sum()))
print("Number of null values in Color column "+str(test_data['Color'].isnull().sum()))<count_values>
print('Bayesian Ridge Accuracy = {0:.2f}%'.format(score_1*100))
print('CatBoost Accuracy = {0:.2f}%'.format(score_2*100))
print('Ridge Accuracy = {0:.2f}%'.format(score*100))
print('Stack Accuracy = {0:.2f}%'.format(final_score*100))
<count_values><EOS> 
test_pred = stack_gen.predict(test)
 submission = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/sample_submission.csv')
 submission['SalePrice'] = np.floor(np.expm1(test_pred))
submission = submission[['Id', 'SalePrice']]
submission.to_csv('blend_submission.csv',index=False)
 print('submission file is created' )