Kaggle competition: Predicting Molecular Properties
dataTrain = pd.read_csv(".. /input/bike-sharing-demand/train.csv")
 dataTest = pd.read_csv(".. /input/bike-sharing-demand/test.csv" )<concatenate>
sub_path = ".. /input/champstacks"
all_files = os.listdir(sub_path)
 all_files
data = dataTrain.append(dataTest)
 data.reset_index(inplace = True)
 data.drop('index', inplace = True, axis = 1 )<feature_engineering>
outs = [pd.read_csv(os.path.join(sub_path, f), index_col=0)for f in all_files]
concat_sub = pd.concat(outs, axis=1)
 cols = list(map(lambda x: "champ" + str(x), range(len(concat_sub.columns))))
concat_sub.columns = cols
concat_sub.reset_index(inplace=True)
 concat_sub.head()
ncol = concat_sub.shape[1]
data["date"] = data.datetime.apply(lambda x : x.split() [0])
 data["hour"] = data.datetime.apply(lambda x : x.split() [1].split(":")[0] ).astype("int")
 data["year"] = data.datetime.apply(lambda x : x.split() [0].split("-")[0])
 data["weekday"] = data.date.apply(lambda dateString : datetime.strptime(dateString,"%Y-%m-%d" ).weekday())
 data["month"] = data.date.apply(lambda dateString : datetime.strptime(dateString,"%Y-%m-%d" ).month)
 dataWindspeedOriginal = data["windspeed"]<feature_engineering>
concat_sub['champ_max'] = concat_sub.iloc[:, 1:ncol].max(axis=1)
 concat_sub['champ_min'] = concat_sub.iloc[:, 1:ncol].min(axis=1)
 concat_sub['champ_mean'] = concat_sub.iloc[:, 1:ncol].mean(axis=1)
 concat_sub['champ_median'] = concat_sub.iloc[:, 1:ncol].median(axis=1 )
wCol= ["season","weather","humidity","month","temp","year","atemp"]
dataWind0 = data[data["windspeed"] == 0]
dataWindNot0 = data[data["windspeed"] != 0]
dataWindNot0["windspeed"] = dataWindNot0["windspeed"].astype("str")
 rfModel_wind = RandomForestClassifier()
rfModel_wind.fit(dataWindNot0[wCol], dataWindNot0["windspeed"])
 Wind0Values = rfModel_wind.predict(X = dataWind0[wCol])
 dataWind0["windspeed"] = Wind0Values
data = dataWindNot0.append(dataWind0)
 data["windspeed"] = data["windspeed"].astype("float")
 data.reset_index(inplace=True)
 data.drop('index',inplace=True,axis=1)
<define_variables>
cutoff_lo = -37
cutoff_hi = 205
categoricalFeatureNames = ["season","holiday","workingday","weather","weekday","month","year","hour"]
numericalFeatureNames = ["temp","humidity","windspeed","atemp"]
dropFeatures = ['casual',"count","datetime","date","registered"]<data_type_conversions>
concat_sub['scalar_coupling_constant'] = concat_sub['champ_mean']
concat_sub[['id', 'scalar_coupling_constant']].to_csv('stack_mean.csv',
index=False, float_format='%.6f' )
for var in categoricalFeatureNames:
data[var] = data[var].astype("category" )<prepare_x_and_y>
concat_sub['scalar_coupling_constant'] = concat_sub['champ_median']
concat_sub[['id', 'scalar_coupling_constant']].to_csv('stack_median.csv',
index=False, float_format='%.6f' )
dataTrain = data[pd.notnull(data['count'])].sort_values(by=["datetime"])
 dataTest = data[~pd.notnull(data['count'])].sort_values(by = ["datetime"])
 datetimecol = dataTest["datetime"]
yLabels = dataTrain["count"]
yLabelsRegistered = dataTrain["registered"]
yLabelsCasual = dataTrain["casual"]<split>
concat_sub['scalar_coupling_constant'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1), 1,
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
0, concat_sub['champ_median']))
concat_sub[['id', 'scalar_coupling_constant']].to_csv('stack_pushout_median.csv',
index=False, float_format='%.6f' )
X_train, X_validate, y_train, y_validate = train_test_split(dataTrain, yLabels, test_size=0.3, random_state=42)
 dateTimeColValidate = X_validate["datetime"]<drop_column>
concat_sub['scalar_coupling_constant'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1),
concat_sub['champ_max'],
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
concat_sub['champ_min'],
concat_sub['champ_mean']))
concat_sub[['id', 'scalar_coupling_constant']].to_csv('stack_minmax_mean.csv',
index=False, float_format='%.6f' )
dataTrain = dataTrain.drop(dropFeatures,axis=1)
 dataTest = dataTest.drop(dropFeatures,axis=1)
 X_train = X_train.drop(dropFeatures,axis=1)
 X_validate = X_validate.drop(dropFeatures,axis=1 )<compute_test_metric>
concat_sub['scalar_coupling_constant'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1),
concat_sub['champ_max'],
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
concat_sub['champ_min'],
concat_sub['champ_median']))
concat_sub[['id', 'scalar_coupling_constant']].to_csv('stack_minmax_median.csv',
index=False, float_format='%.6f' )
def rmsle(y, y_,convertExp=True):
if convertExp:
y = np.exp(y),
y_ = np.exp(y_)
 log1 = np.nan_to_num(np.array([np.log(v + 1)for v in y]))
log2 = np.nan_to_num(np.array([np.log(v + 1)for v in y_]))
calc =(log1 - log2)** 2
return np.sqrt(np.mean(calc))<set_options>
sub_base = pd.read_csv('.. /input/champstacks/submission-giba-1(2 ).csv' )
<predict_on_test><EOS> 
concat_sub['champ_base'] = sub_base['scalar_coupling_constant']
concat_sub['scalar_coupling_constant'] = np.where(np.all(concat_sub.iloc[:,1:ncol] > cutoff_lo, axis=1),
concat_sub['champ_max'],
np.where(np.all(concat_sub.iloc[:,1:ncol] < cutoff_hi, axis=1),
concat_sub['champ_min'],
concat_sub['champ_base']))
concat_sub[['id', 'scalar_coupling_constant']].to_csv('stack_minmax_bestbase.csv',
index=False, float_format='%.6f' )