Kaggle competition: Mercedes-Benz Greener Manufacturing
gender_submission = pd.read_csv(".. /input/titanic/gender_submission.csv")
 test = pd.read_csv(".. /input/titanic/test.csv")
 train = pd.read_csv(".. /input/titanic/train.csv" )<load_from_csv>
%matplotlib inline
test2 = pd.read_csv(".. /input/titanic/test.csv" )<set_options>
test = pd.read_csv(".. /input/test.csv")
 train = pd.read_csv(".. /input/train.csv")
 sample_submission = pd.read_csv(".. /input/sample_submission.csv" )
warnings.simplefilter('ignore')
<count_missing_values>
print(train.isnull().values.any() , test.isnull().values.any() )
print('Train columns with null values:
', train.isnull().sum())
 print("-" * 10)
 print('Test columns with null values:
', test.isnull().sum())
 print("-" * 10 )<drop_column>
cat_columns = ["X0", "X1", "X2", "X3", "X4", "X5", "X6", "X8"]
le0 = LabelEncoder()
le0.fit(list(train.X0)+list(test.X0))
train.X0 = le0.transform(train.X0)
 test.X0 = le0.transform(test.X0)
 le1 = LabelEncoder()
le1.fit(list(train.X1)+list(test.X1))
train.X1 = le1.transform(train.X1)
 test.X1 = le1.transform(test.X1)
 le2 = LabelEncoder()
le2.fit(list(train.X2)+list(test.X2))
train.X2 = le2.transform(train.X2)
 test.X2 = le2.transform(test.X2)
 le3 = LabelEncoder()
le3.fit(list(train.X3)+list(test.X3))
train.X3 = le3.transform(train.X3)
 test.X3 = le3.transform(test.X3)
 le4 = LabelEncoder()
le4.fit(list(train.X4)+list(test.X4))
train.X4 = le4.transform(train.X4)
 test.X4 = le4.transform(test.X4)
 le5 = LabelEncoder()
le5.fit(list(train.X5)+list(test.X5))
train.X5 = le5.transform(train.X5)
 test.X5 = le5.transform(test.X5)
 le6 = LabelEncoder()
le6.fit(list(train.X6)+list(test.X6))
train.X6 = le6.transform(train.X6)
 test.X6 = le6.transform(test.X6)
 le8 = LabelEncoder()
le8.fit(list(train.X8)+list(test.X8))
train.X8 = le8.transform(train.X8)
 test.X8 = le8.transform(test.X8)
dropping = ['PassengerId', 'Ticket','Cabin','Fare']
train.drop(dropping,axis=1, inplace=True)
 test.drop(dropping,axis=1, inplace=True)
 train.head()<feature_engineering>
train.drop(constant_columns, axis=1, inplace=True)
 test.drop(constant_columns, axis=1, inplace=True )
data = [train,test]
for dataset in data:
dataset['Embarked'].fillna(dataset['Embarked'].mode() [0],inplace=True)
 Embarked = np.zeros(len(dataset))
Embarked[dataset['Embarked']== 'C'] = 1
Embarked[dataset['Embarked']== 'Q'] = 2
Embarked[dataset['Embarked']== 'S'] = 3
dataset['Embarked'] = Embarked<data_type_conversions>
train_y = pd.DataFrame(train["y"])
 train_x = train.drop(["y"], axis=1 )
train['Age'].fillna(train['Age'].median() , inplace = True)
 test['Age'].fillna(test['Age'].median() , inplace = True )<count_missing_values>
for col_name in cat_columns:
print(col_name, train[col_name].nunique() )
print('Train columns with null values:
', train.isnull().sum())
 print("-" * 10)
 print('Test columns with null values:
', test.isnull().sum())
 print("-" * 10 )<feature_engineering>
train_x.X4.value_counts()
data = [train,test]
for dataset in data:
dataset['Age'] = dataset['Age']
dataset.loc[ dataset['Age'] <= 11, 'Age'] = 0
dataset.loc[(dataset['Age'] > 11)&(dataset['Age'] <= 18), 'Age'] = 1
dataset.loc[(dataset['Age'] > 18)&(dataset['Age'] <= 22), 'Age'] = 2
dataset.loc[(dataset['Age'] > 22)&(dataset['Age'] <= 27), 'Age'] = 3
dataset.loc[(dataset['Age'] > 27)&(dataset['Age'] <= 33), 'Age'] = 4
dataset.loc[(dataset['Age'] > 33)&(dataset['Age'] <= 40), 'Age'] = 5
dataset.loc[(dataset['Age'] > 40)&(dataset['Age'] <= 66), 'Age'] = 6
dataset.loc[ dataset['Age'] > 66, 'Age'] = 6
train['Age'].value_counts()<feature_engineering>
from sklearn.ensemble import RandomForestRegressor
from xgboost import XGBRegressor
<feature_engineering><EOS> 
XGBR = XGBRegressor()
XGBR.fit(train_x, train_y, verbose=False)
 predicts = XGBR.predict(test)
 submission = pd.DataFrame({'ID': test.ID, 'y': predicts})
 submission.to_csv('submission.csv', index=False )