Kaggle competition: Titanic - Machine Learning from Disaster
optimal_values = threshold_search(y_val, preds_val)
 best_threshold = optimal_values['threshold']
best_score = optimal_values['matthews_correlation']<load_from_csv>
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
 train_data.head()
meta_test = pd.read_csv('.. /input/vsb-power-line-fault-detection/metadata_test.csv')
 X_test_input = np.load(".. /input/folk-base-neural-network-using-lstm/X_test.npy")
 features_test = np.load(".. /input/folk-base-neural-network-using-lstm/features_test.npy")
 submission = pd.read_csv('.. /input/vsb-power-line-fault-detection/sample_submission.csv' )<predict_on_test>
test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 test_data.head()
preds_test = []
for i in range(N_SPLITS):
model.load_weights('weights_{}.h5'.format(i))
pred = model.predict([X_test_input, features_test], batch_size=300, verbose=1)
 pred_3 = []
for pred_scalar in pred:
for i in range(3):
pred_3.append(pred_scalar)
 preds_test.append(pred_3)
<compute_test_metric>
women = train_data.loc[train_data.Sex == 'female']["Survived"]
rate_women = sum(women)/len(women)
 print("% of women who survived:", rate_women )
optimal_values = threshold_search(y_val, preds_val)
 best_threshold = optimal_values['threshold']
best_score = optimal_values['matthews_correlation'] 
<data_type_conversions>
men = train_data.loc[train_data.Sex == 'male']["Survived"]
rate_men = sum(men)/len(men)
 print("% of men who survived:", rate_men )
preds_test =(np.squeeze(np.mean(preds_test, axis=0)) > best_threshold ).astype(np.int)
 preds_test.shape<save_to_csv>
train_data["Age"] = train_data["Age"].fillna(train_data["Age"].median())
 train_data["Embarked"] = train_data["Embarked"].fillna('S')
 train_data.loc[train_data["Embarked"] == "S", "Embarked"] = 0
train_data.loc[train_data["Embarked"] == "C", "Embarked"] = 1
train_data.loc[train_data["Embarked"] == "Q", "Embarked"] = 2
train_data.loc[train_data["Sex"] == "male", "Sex"] = 0
train_data.loc[train_data["Sex"] == "female", "Sex"] = 1
submission['target'] = preds_test
submission.to_csv('submission.csv', index=False)
 submission.head()<load_from_csv>
test_data["Age"] = test_data["Age"].fillna(test_data["Age"].median())
 test_data["Fare"] = test_data["Fare"].fillna(test_data["Fare"].median())
 test_data.loc[test_data["Embarked"] == "S", "Embarked"] = 0
test_data.loc[test_data["Embarked"] == "C", "Embarked"] = 1
test_data.loc[test_data["Embarked"] == "Q", "Embarked"] = 2
test_data.loc[test_data["Sex"] == "male", "Sex"] = 0
test_data.loc[test_data["Sex"] == "female", "Sex"] = 1
v_raw_train = pq.read_pandas('.. /input/vsb-power-line-fault-detection/train.parquet' ).to_pandas().values
meta_train = np.loadtxt('.. /input/vsb-power-line-fault-detection/metadata_train.csv', skiprows=1, delimiter=',')
 y_train = meta_train[:, 3].astype(bool)
 print(v_raw_train.shape )<define_search_space>
y = train_data["Survived"]
features = ["Pclass", "Sex", 'Age',"SibSp", "Parch",'Embarked']
X = pd.get_dummies(train_data[features])
 X_test = pd.get_dummies(test_data[features])
 RF1 = RandomForestClassifier(n_estimators=700, max_depth=7, max_features=5 , n_jobs=-1)
 adaboost = AdaBoostClassifier(RF1,n_estimators=10)
 adaboost.fit(X, y )
def compute_spectra(v_raw, *, m = 1000):

 percentile =(100, 99, 95, 0, 1, 5)
 n = v_raw.shape[1]
length = v_raw.shape[0] // m
n_spectra = len(percentile)
 mean_signal = np.zeros(( n, length), dtype='float32')
 percentile_spectra = np.zeros(( n, length, n_spectra), dtype='float32')
 print('computing spectra...', flush=True)
 for i in tqdm(range(n)) :
v = v_raw[:, i].astype('float32' ).reshape(-1, m)/ 128.0
mean = np.mean(v, axis=1)
 s = np.abs(np.percentile(v, percentile, axis=1)- mean)
 h = np.percentile(s, 5.0)
 s = np.maximum(0.0, s - h)
 mean_signal[i, :] = mean
percentile_spectra[i, :, :] = s.T
d = {}
d['mean'] = mean_signal
d['percentile'] = percentile_spectra
return d
spec_train = compute_spectra(v_raw_train)
 print('done.' )<init_hyperparams>
scores = model_selection.cross_val_score(adaboost, X, y, cv=10)
 print('The scores mean is :',scores.mean())
 print('The Best Score:',scores.max())
 predictions = adaboost.predict(X_test )
<normalization><EOS> 
output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
 output.to_csv('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )