

'''simple docstring'''


import warnings

from ...utils import is_sklearn_available, requires_backends


if is_sklearn_available():
     from scipy.stats import pearsonr, spearmanr
     from sklearn.metrics import fa_score, matthews_corrcoef


lowerCAmelCase__						:       Union[str, Any]										=						(
    """This metric will be removed from the library soon, metrics should be handled with the 🤗 Evaluate """
    """library. You can have a look at this example script for pointers: """
    """https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py"""
)




def 	_a       (				__lowerCAmelCase		:      Dict   ,							__lowerCAmelCase		:      Dict     ):

  """simple docstring"""

  warnings.warn(lowerCamelCase_   ,							lowerCamelCase_     )
  requires_backends(lowerCamelCase_   ,							'''sklearn'''     )
  return (preds == labels).mean()




def 	_a       (				__lowerCAmelCase		:      Optional[int]   ,							__lowerCAmelCase		:      Tuple     ):

  """simple docstring"""

  warnings.warn(lowerCamelCase_   ,							lowerCamelCase_     )
  requires_backends(lowerCamelCase_   ,							'''sklearn'''     )
  snake_case__						:       Any       						=  simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )
  snake_case__						:       Any       						=  fa_score(y_true=lowerCamelCase_   ,							y_pred=lowerCamelCase_     )
  return {
      "acc": acc,
      "f1": fa,
      "acc_and_f1": (acc + fa) / 2,
  }




def 	_a       (				__lowerCAmelCase		:      Tuple   ,							__lowerCAmelCase		:      List[str]     ):

  """simple docstring"""

  warnings.warn(lowerCamelCase_   ,							lowerCamelCase_     )
  requires_backends(lowerCamelCase_   ,							'''sklearn'''     )
  snake_case__						:       Optional[int]       						=  pearsonr(lowerCamelCase_   ,							lowerCamelCase_     )[0]
  snake_case__						:       List[str]       						=  spearmanr(lowerCamelCase_   ,							lowerCamelCase_     )[0]
  return {
      "pearson": pearson_corr,
      "spearmanr": spearman_corr,
      "corr": (pearson_corr + spearman_corr) / 2,
  }




def 	_a       (				__lowerCAmelCase		:      Dict   ,							__lowerCAmelCase		:      int   ,							__lowerCAmelCase		:      str     ):

  """simple docstring"""

  warnings.warn(lowerCamelCase_   ,							lowerCamelCase_     )
  requires_backends(lowerCamelCase_   ,							'''sklearn'''     )
  assert len(lowerCamelCase_     ) == len(lowerCamelCase_     ), F"""Predictions and labels have mismatched lengths {len(lowerCamelCase_     )} and {len(lowerCamelCase_     )}"""
  if task_name == "cola":
    return {"mcc": matthews_corrcoef(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "sst-2":
    return {"acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "mrpc":
    return acc_and_fa(lowerCamelCase_   ,							lowerCamelCase_     )
  elif task_name == "sts-b":
    return pearson_and_spearman(lowerCamelCase_   ,							lowerCamelCase_     )
  elif task_name == "qqp":
    return acc_and_fa(lowerCamelCase_   ,							lowerCamelCase_     )
  elif task_name == "mnli":
    return {"mnli/acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "mnli-mm":
    return {"mnli-mm/acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "qnli":
    return {"acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "rte":
    return {"acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "wnli":
    return {"acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  elif task_name == "hans":
    return {"acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  else:
    raise KeyError(lowerCamelCase_     )





def 	_a       (				__lowerCAmelCase		:      List[Any]   ,							__lowerCAmelCase		:      str   ,							__lowerCAmelCase		:      Optional[Any]     ):

  """simple docstring"""

  warnings.warn(lowerCamelCase_   ,							lowerCamelCase_     )
  requires_backends(lowerCamelCase_   ,							'''sklearn'''     )
  if len(lowerCamelCase_     ) != len(lowerCamelCase_     ):
    raise ValueError(F"""Predictions and labels have mismatched lengths {len(lowerCamelCase_     )} and {len(lowerCamelCase_     )}"""     )
  if task_name == "xnli":
    return {"acc": simple_accuracy(lowerCamelCase_   ,							lowerCamelCase_     )}
  else:
    raise KeyError(lowerCamelCase_     )






'''simple docstring'''


def 	_a       (				__lowerCAmelCase		:      float   ,							__lowerCAmelCase		:      float   ,							__lowerCAmelCase		:      int     ):

		"""simple docstring"""

		if principal <= 0:
				raise Exception('''Principal borrowed must be > 0'''     )
		if rate_per_annum < 0:
				raise Exception('''Rate of interest must be >= 0'''     )
		if years_to_repay <= 0 or not isinstance(__lowerCAmelCase   ,							__lowerCAmelCase     ):
				raise Exception('''Years to repay must be an integer > 0'''     )

		# Yearly rate is divided by 12 to get monthly rate
		snake_case__						:       int       						=  rate_per_annum / 12

		# Years to repay is multiplied by 12 to get number of payments as payment is monthly
		snake_case__						:       Tuple       						=  years_to_repay * 12

		return (
		    principal
		    * rate_per_month
		    * (1 + rate_per_month) ** number_of_payments
		    / ((1 + rate_per_month) ** number_of_payments - 1)
		)


if __name__ == "__main__":
					import doctest

					doctest.testmod()



