"""
 logistic_regr.py  (author: Anson Wong / git: ankonzoid)
"""
class logistic_regr:
	def __init__(self):
		self.model = LogisticRegression(penalty="l2")
		self.flag = False
		self.flag_y_pred = None
	def fit(self, X, y):
		y_unique = list(set(y))
		if len(y_unique) == 1:
			self.flag = True
			self.flag_y_pred = y_unique[0]
		else:
			self.model.fit(X, y)
	def predict(self, X):
		if self.flag:
			return self.flag_y_pred * np.ones((len(X),), dtype=int)
		else:
			return self.model.predict(X)
	def loss(self, X, y, y_pred):
		return mean_squared_error(y, y_pred)