Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<string_transform>
import pandas as pd
def rep_3chr(text):
chr3 = 0
for word in text.split() :
for c in set(word):
if word.rfind(c+c+c)> -1:
chr3 = 1
return chr3<feature_engineering>
train_data = pd.read_csv(".. /input/titanic/train.csv")
 test_data = pd.read_csv(".. /input/titanic/test.csv" )
train['text_chr3'] = train['text'].apply(rep_3chr)
 train['selected_text_chr3'] = train['selected_text'].apply(rep_3chr)
 train['selected_text_pred_chr3'] = train['selected_text_pred'].apply(rep_3chr )<filter>
y = train_data.Survived
X = train_data.drop(['Survived'], axis=1)
 X_test = test_data
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state=0 )
train_outlier = train[train['res'] == 0].reset_index(drop=True)
 train_outlier<define_variables>
num_cols = [cname for cname in X_train if X_train[cname].dtype in ['int64', 'float64']]
cat_cols = [cname for cname in X_train if X_train[cname].dtype == "object"]
numerical_transformer = SimpleImputer(strategy='constant')
 categorical_transformer = Pipeline(steps=[ 
('imputer', SimpleImputer(strategy='constant')) , 
('onehot', OneHotEncoder(handle_unknown='ignore'))
])
 preprocessor = ColumnTransformer(
 transformers=[ 
('num', numerical_transformer, num_cols), 
('cat', categorical_transformer, cat_cols)
 ])
 model = SVC(kernel='linear', random_state=0)
sh_out = str(round(len(train_outlier)*100/len(train),1))
print('Number of outliers is ' + sh_out + '% from training data' )<predict_on_test>
my_pipeline = Pipeline(steps=[('preprocessor', preprocessor),('model', model)])
 my_pipeline.fit(X_train, y_train)
 predictions = my_pipeline.predict(X_valid)
 mean_absolute_error(y_valid, predictions)
 final_submission = my_pipeline.predict(X_test )
<filter><EOS> 
output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': final_submission})
 output.to_csv('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )