Problem 80. Test for balanced parentheses

Given the input inStr, give the boolean output out indicating whether all the parentheses are balanced.

Examples:

  • If inStr is '(()', the output is false.
  • If inStr is '(xyz)(ab)' the output is true.
  • If inStr is ')(', the output is false.

The string may include characters other than ( and ), but you should ignore them.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
final_valid_predictions = {} final_test_predictions = [] scores = [] log_losses = [] balanced_log_losses = [] weights = [] for fold in range(5): train_df = df[df['fold'] != fold] valid_df = df[df['fold'] == fold] valid_ids = valid_df.Id.values.tolist() X_train, y_train = train_df.drop(['Id', 'Class', 'fold'], axis=1), train_df['Class'] X_valid, y_valid = valid_df.drop(['Id', 'Class', 'fold'], axis=1), valid_df['Class'] lgb = LGBMClassifier(boosting_type='goss', learning_rate=0.06733232950390658, n_estimators = 50000, early_stopping_round = 300, random_state=42, subsample=0.6970532011679706, colsample_bytree=0.6055755840633003, class_weight='balanced', metric='none', is_unbalance=True, max_depth=8) lgb.fit(X_train, y_train, eval_set=(X_valid, y_valid), verbose=1000, eval_metric=lgb_metric) y_pred = lgb.predict_proba(X_valid) preds_test = lgb.predict_proba(test_df.drop(['Id'], axis=1).values) final_test_predictions.append(preds_test) final_valid_predictions.update(dict(zip(valid_ids, y_pred))) logloss = log_loss(y_valid, y_pred) balanced_logloss = balanced_log_loss(y_valid, y_pred[:, 1]) log_losses.append(logloss) balanced_log_losses.append(balanced_logloss) weights.append(1/balanced_logloss) print(f"Fold: {fold}, log loss: {round(logloss, 3)}, balanced los loss: {round(balanced_logloss, 3)}") print() print("Log Loss") print(log_losses) print(np.mean(log_losses), np.std(log_losses)) print() print("Balanced Log Loss") print(balanced_log_losses) print(np.mean(balanced_log_losses), np.std(balanced_log_losses)) print() print("Weights") print(weights)
07-08
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值