Kaggle competition: Seleksi Calon Asisten GAIB
<SOS> metric: meanfscore Kaggle data source: seleksi-calon-asisten-gaib<create_dataframe>
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
cabin_notnull = df_train['Cabin'].loc[df_train['Cabin'].notnull() ].astype(str ).str[0]
cabin_notnull = pd.DataFrame([cabin_notnull, df_train['Survived'].loc[df_train['Cabin'].notnull() ]] ).T<count_values>
path_train = '.. /input/seleksidukungaib/train.csv'
path_test = '.. /input/seleksidukungaib/test.csv'
train_data = pd.read_csv(path_train)
 test_data = pd.read_csv(path_test )
cabin_notnull['Cabin'].value_counts()<drop_column>
train_data['isChurned'].value_counts()
ship.drop("Cabin", axis=1, inplace=True)
 print('Cabin column has been dropped.' )<categorify>
train_data.isna().sum()
embark_dummies_titanic = pd.get_dummies(ship['Embarked'])
 embark_dummies_titanic.drop(['S'], axis=1, inplace=True)
 ship = ship.join(embark_dummies_titanic)
 ship.drop(['Embarked'], axis=1,inplace=True)
 print('Embarked column has been dropped.C and Q columns have been added.' )<categorify>
train_data = train_data.dropna(axis=0 )
pclass_dummies_titanic = pd.get_dummies(ship['Pclass'])
 pclass_dummies_titanic.columns = ['Class_1','Class_2','Class_3']
pclass_dummies_titanic.drop(['Class_3'], axis=1, inplace=True)
 ship.drop(['Pclass'],axis=1,inplace=True)
 ship = ship.join(pclass_dummies_titanic)
 print('Pclass column has been changed.' )<feature_engineering>
train_data.isna().sum()
ship['Family'] = ship["Parch"] + ship["SibSp"]
ship['Family'].loc[ship['Family'] > 0] = 1
ship['Family'].loc[ship['Family'] == 0] = 0


ship = ship.drop(['SibSp','Parch'], axis=1)
 print('SibSp and Parch columns have been dropped.Family column has been added.' )<categorify>
data = pd.concat([train_data,test_data],ignore_index=True )
def get_person(passenger):
age, sex = passenger
return 'child' if age < 18 else sex
ship['Person'] = ship[['Age','Sex']].apply(get_person, axis=1)
 ship.drop(['Sex'],axis=1,inplace=True)
 person_dummies_titanic = pd.get_dummies(ship['Person'])
 person_dummies_titanic.columns = ['Child','Female','Male']
person_dummies_titanic.drop(['Male'], axis=1, inplace=True)
 ship = ship.join(person_dummies_titanic)
 ship.drop(['Person'],axis=1,inplace=True)
 print('Age and Sex columns have been dropped.Child and Female columns have been added.' )<feature_engineering>
date = ['date_collected','date']
bin = ['premium','super','pinEnabled']
col = date + bin
le = LabelEncoder()
for i in col:
data[i] = le.fit_transform(list(data[i].values))
ship['Title'] = ship['Name'].str.split(", ", expand=True)[1].str.split(".", expand=True)[0]
print('Title column has been created with values')
 ship.head()<count_values>
train_data = data[~data.isChurned.isnull() ]
test_data = data[data.isChurned.isnull() ]
ship['Title'].value_counts()<create_dataframe>
features = ['date_collected','num_topup_trx', 'num_recharge_trx','isActive','isVerifiedEmail','blocked','premium','super','userLevel','pinEnabled']
X = train_data[features]
y = train_data['isChurned']
ship.groupby('Title', sort=False)['Age'].agg(['mean', 'min', 'median', 'max', 'count'] )<categorify>
model = LogisticRegression()
model.fit(X,y )
ship['Title'].loc[ship['Title'] == 'the Countess'] = 'Mrs'
ship['Title'].loc[ship['Title'] == 'Ms'] = 'Mrs'
ship['Title'].loc[ship['Title'] == 'Lady'] = 'Mrs'
ship['Title'].loc[ship['Title'] == 'Dona'] = 'Mrs'
ship['Title'].loc[ship['Title'] == 'Mlle'] = 'Miss'
ship['Title'].loc[ship['Title'] == 'Mme'] = 'Miss'
print('Rare lady titles have been added to larger group titles' )<count_values>
pred = model.predict(test_data[features] )
<import_modules><EOS> 
submission = pd.DataFrame({'idx':test_data['idx'],'isChurned':pred.astype(int)})
 submission.to_csv('submission.csv',index=False )