Kaggle competition: IEEE PES BDC DataThon , Year-2020
<SOS> metric: rmse Kaggle data source: ieee-pes-bdc-datathon-,-year-2020<drop_column>
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier as RFC
from sklearn.linear_model import LinearRegression as LR
from sklearn.neural_network import MLPRegressor as MLPR
train=train.drop(['Ticket','Cabin'],axis=1)
 test=test.drop(['Ticket','Cabin'],axis=1 )<feature_engineering>
data_dir = '.. /input/ieee-pes-bdc-datathon-year-2020'
df = pd.read_csv(f'{data_dir}/train.csv')
 test_df = pd.read_csv(f'{data_dir}/test.csv' )
for dataset in combine:
dataset['Title']=dataset['Title'].replace(['Lady', 'Countess','Capt', 'Col','Don', 'Dr', 'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona'], 'Rare')
 dataset['Title'] = dataset['Title'].replace('Mlle', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Ms', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Mme', 'Mrs')
 train[['Title','Survived']].groupby(['Title'],as_index=False ).mean()<categorify>
data_len = len(df)
 pct = 1.0
train_len = int(1.0*data_len)
 train_df = df[:train_len]
val_df = df[train_len:]
title_mapping={'Mr':1,'Miss':2,'Mrs':3,'Master':4,'Rare':5}
for dataset in combine:
dataset['Title']=dataset['Title'].map(title_mapping)
 dataset['Title']=dataset['Title'].fillna(0)
 train.head(6)
<data_type_conversions>
X_train = train_df.drop(['ID', 'global_horizontal_irradiance'], axis=1 ).values.reshape(-1, 6)
 y_train = train_df['global_horizontal_irradiance'].values.reshape(len(train_df))
train['Age']=train['Age'].fillna(train['Age'].median(skipna=True))
test['Age']=test['Age'].fillna(test['Age'].median(skipna=True))<data_type_conversions>
X_val = val_df.drop(['ID', 'global_horizontal_irradiance'], axis=1 ).values.reshape(-1, 6)
 y_val = val_df['global_horizontal_irradiance'].values.reshape(len(val_df))
train['Age']=train['Age'].astype(int)
 test['Age']=test['Age'].astype(int )<sort_values>
X_test = test_df.drop(['ID'], axis=1 ).values.reshape(-1, 6)
 test_ID = test_df['ID'].values.reshape(len(test_df))
train['AgeBand']=pd.cut(train['Age'],5)
 train[['AgeBand','Survived']].groupby(['AgeBand'],as_index=False ).mean().sort_values(by='AgeBand',ascending=True )<feature_engineering>
reg = LR(normalize=True)
 reg.fit(X_train, y_train )
combine=[train,test]
for dataset in combine:
dataset.loc[dataset['Age']<=16,'Age']=0
dataset.loc[(dataset['Age']>16)&(dataset['Age']<=32),'Age']=1
dataset.loc[(dataset['Age']>32)&(dataset['Age']<=48),'Age']=2
dataset.loc[(dataset['Age']>48)&(dataset['Age']<=64),'Age']=3
dataset.loc[(dataset['Age']>64),'Age']=4
train.head(6 )<concatenate>
preds = reg.predict(X_test )
train=train.drop(['AgeBand'],axis=1)
 combine=[train,test]<sort_values>
regr = MLPR(random_state=1, hidden_layer_sizes =(32, 8, 2), max_iter=5, validation_fraction=0.1, learning_rate_init=0.02, verbose=True)
 regr.fit(X_train, y_train )
for dataset in combine:
dataset['FamilySize']=dataset['SibSp']+dataset['Parch']+1
train[['FamilySize','Survived']].groupby(['FamilySize'],as_index=False ).mean().sort_values(by='Survived',ascending=False)
<feature_engineering>
preds = regr.predict(X_test)
 preds = [0 if p<0 else p for p in preds]
<drop_column><EOS> 
zippedList = list(zip(test_ID, preds))
submission = pd.DataFrame(zippedList, columns = ['ID','global_horizontal_irradiance'])
 submission.to_csv('submission.csv', index=False )