





import numpy as np
import pandas as pd
from sklearn.preprocessing import Normalizer
from sklearn.svm import SVR
from statsmodels.tsa.statespace.sarimax import SARIMAX


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     float:
		lowerCamelCase   : List[Any]								=np.array([[1, item, train_mtch[i]] for i, item in enumerate(SCREAMING_SNAKE_CASE_		)]		)
		lowerCamelCase   : Dict								=np.array(SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : List[Any]								=np.dot(np.dot(np.linalg.inv(np.dot(x.transpose()							,       SCREAMING_SNAKE_CASE_		)		)							,       x.transpose()		)							,       SCREAMING_SNAKE_CASE_		)
		return abs(beta[0] + test_dt[0] * beta[1] + test_mtch[0] + beta[2]		)


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     float:
		lowerCamelCase   : Optional[int]								=(1, 2, 1)
		lowerCamelCase   : Dict								=(1, 1, 0, 7)
		lowerCamelCase   : Union[str, Any]								=SARIMAX(
		    SCREAMING_SNAKE_CASE_							,       exog=SCREAMING_SNAKE_CASE_							,       order=SCREAMING_SNAKE_CASE_							,       seasonal_order=SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : Any								=model.fit(disp=SCREAMING_SNAKE_CASE_							,       maxiter=6_0_0							,       method='''nm'''		)
		lowerCamelCase   : List[Any]								=model_fit.predict(1							,       len(SCREAMING_SNAKE_CASE_		)							,       exog=[test_match]		)
		return result[0]


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     float:
		lowerCamelCase   : Dict								=SVR(kernel='''rbf'''							,       C=1							,       gamma=0.1							,       epsilon=0.1		)
		regressor.fit(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : int								=regressor.predict(SCREAMING_SNAKE_CASE_		)
		return y_pred[0]


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     float:
		train_user.sort()
		lowerCamelCase   : Dict								=np.percentile(SCREAMING_SNAKE_CASE_							,       2_5		)
		lowerCamelCase   : Any								=np.percentile(SCREAMING_SNAKE_CASE_							,       7_5		)
		lowerCamelCase   : Optional[int]								=qa - qa
		lowerCamelCase   : List[Any]								=qa - (iqr * 0.1)
		return low_lim


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     bool:
		lowerCamelCase   : Optional[Any]								=0
		lowerCamelCase   : Dict								=0
		for i in list_vote:
				if i > actual_result:
						lowerCamelCase   : str								=not_safe + 1
				else:
						if abs(abs(SCREAMING_SNAKE_CASE_		) - abs(SCREAMING_SNAKE_CASE_		)		) <= 0.1:
								safe += 1
						else:
								not_safe += 1
		return safe > not_safe


if __name__ == "__main__":
				# data_input_df = pd.read_csv("ex_data.csv", header=None)
				snake_case_							=			[[1_8_2_3_1, 0.0, 1], [2_2_6_2_1, 1.0, 2], [1_5_6_7_5, 0.0, 3], [2_3_5_8_3, 1.0, 4]]
				snake_case_							=			pd.DataFrame(
				    data_input, columns=['''total_user''', '''total_even''', '''days''']
				)
				snake_case_							=			Normalizer().fit_transform(data_input_df.values)
				# split data
				snake_case_							=			normalize_df[:, 2].tolist()
				snake_case_							=			normalize_df[:, 0].tolist()
				snake_case_							=			normalize_df[:, 1].tolist()

				# for svr (input variable = total date and total match)
				snake_case_							=			normalize_df[:, [1, 2]].tolist()
				snake_case_							=			x[: len(x) - 1]
				snake_case_							=			x[len(x) - 1 :]

				# for linear regression & sarimax
				snake_case_							=			total_date[: len(total_date) - 1]
				snake_case_							=			total_user[: len(total_user) - 1]
				snake_case_							=			total_match[: len(total_match) - 1]

				snake_case_							=			total_date[len(total_date) - 1 :]
				snake_case_							=			total_user[len(total_user) - 1 :]
				snake_case_							=			total_match[len(total_match) - 1 :]

				# voting system with forecasting
				snake_case_							=			[
				    linear_regression_prediction(
				        trn_date, trn_user, trn_match, tst_date, tst_match
				    ),
				    sarimax_predictor(trn_user, trn_match, tst_match),
				    support_vector_regressor(x_train, x_test, trn_user),
				]

				# check the safety of today's data
				snake_case_							=			'''''' if data_safety_checker(res_vote, tst_user) else '''not '''
				print('''Today\'s data is {not_str}safe.''')








import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
				from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import MobileNetVaImageProcessor
class        snake_case_		(			_A):







		def 			__lowercase   (		self   )				->   Optional[Any]:
				lowerCamelCase   : Optional[Any]								=self.config_class(**self.inputs_dict   )
				self.parent.assertTrue(hasattr(__lowercase			,     '''tf_padding'''   )   )
				self.parent.assertTrue(hasattr(__lowercase			,     '''depth_multiplier'''   )   )

class        snake_case_		:







		def __init__(		self			,     __lowercase			,     __lowercase=1_3			,     __lowercase=3			,     __lowercase=3_2			,     __lowercase=0.2_5			,     __lowercase=8			,     __lowercase=8			,     __lowercase=6			,     __lowercase=3_2			,     __lowercase=True			,     __lowercase=True			,     __lowercase=True			,     __lowercase="relu6"			,     __lowercase=1_2_8_0			,     __lowercase=0.1			,     __lowercase=0.0_2			,     __lowercase=True			,     __lowercase=True			,     __lowercase=1_0			,     __lowercase=None			,     )				->   int:
				lowerCamelCase   : Union[str, Any]								=parent
				lowerCamelCase   : Union[str, Any]								=batch_size
				lowerCamelCase   : int								=num_channels
				lowerCamelCase   : str								=image_size
				lowerCamelCase   : List[Any]								=depth_multiplier
				lowerCamelCase   : Dict								=depth_divisible_by
				lowerCamelCase   : Optional[Any]								=min_depth
				lowerCamelCase   : Optional[Any]								=expand_ratio
				lowerCamelCase   : List[str]								=tf_padding
				lowerCamelCase   : int								=output_stride
				lowerCamelCase   : Optional[Any]								=first_layer_is_expansion
				lowerCamelCase   : List[Any]								=finegrained_output
				lowerCamelCase   : int								=hidden_act
				lowerCamelCase   : List[str]								=last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier   )
				lowerCamelCase   : str								=classifier_dropout_prob
				lowerCamelCase   : int								=use_labels
				lowerCamelCase   : Optional[int]								=is_training
				lowerCamelCase   : int								=num_labels
				lowerCamelCase   : Dict								=initializer_range
				lowerCamelCase   : Tuple								=scope







		def 			__lowercase   (		self   )				->   List[str]:
				lowerCamelCase   : Tuple								=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

				lowerCamelCase   : Tuple								=None
				lowerCamelCase   : Any								=None
				if self.use_labels:
						lowerCamelCase   : int								=ids_tensor([self.batch_size]			,     self.num_labels   )
						lowerCamelCase   : List[str]								=ids_tensor([self.batch_size, self.image_size, self.image_size]			,     self.num_labels   )

				lowerCamelCase   : Optional[Any]								=self.get_config()

				return config, pixel_values, labels, pixel_labels







		def 			__lowercase   (		self   )				->   Optional[Any]:
				return MobileNetVaConfig(
				    num_channels=self.num_channels			,     image_size=self.image_size			,     depth_multiplier=self.depth_multiplier			,     depth_divisible_by=self.depth_divisible_by			,     min_depth=self.min_depth			,     expand_ratio=self.expand_ratio			,     output_stride=self.output_stride			,     first_layer_is_expansion=self.first_layer_is_expansion			,     finegrained_output=self.finegrained_output			,     hidden_act=self.hidden_act			,     tf_padding=self.tf_padding			,     classifier_dropout_prob=self.classifier_dropout_prob			,     initializer_range=self.initializer_range			,     )







		def 			__lowercase   (		self			,     __lowercase			,     __lowercase			,     __lowercase			,     __lowercase   )				->   Dict:
				lowerCamelCase   : Optional[Any]								=MobileNetVaModel(config=__lowercase   )
				model.to(__lowercase   )
				model.eval()
				lowerCamelCase   : int								=model(__lowercase   )
				self.parent.assertEqual(
				    result.last_hidden_state.shape			,     (
				        self.batch_size,
				        self.last_hidden_size,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )			,     )
				self.parent.assertEqual(
				    result.pooler_output.shape			,     (self.batch_size, self.last_hidden_size)			,     )







		def 			__lowercase   (		self			,     __lowercase			,     __lowercase			,     __lowercase			,     __lowercase   )				->   List[Any]:
				lowerCamelCase   : Optional[Any]								=self.num_labels
				lowerCamelCase   : Optional[int]								=MobileNetVaForImageClassification(__lowercase   )
				model.to(__lowercase   )
				model.eval()
				lowerCamelCase   : Any								=model(__lowercase			,     labels=__lowercase   )
				self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_labels)   )







		def 			__lowercase   (		self			,     __lowercase			,     __lowercase			,     __lowercase			,     __lowercase   )				->   str:
				lowerCamelCase   : int								=self.num_labels
				lowerCamelCase   : List[Any]								=MobileNetVaForSemanticSegmentation(__lowercase   )
				model.to(__lowercase   )
				model.eval()
				lowerCamelCase   : List[str]								=model(__lowercase   )
				self.parent.assertEqual(
				    result.logits.shape			,     (
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )			,     )
				lowerCamelCase   : Union[str, Any]								=model(__lowercase			,     labels=__lowercase   )
				self.parent.assertEqual(
				    result.logits.shape			,     (
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )			,     )







		def 			__lowercase   (		self   )				->   Optional[Any]:
				lowerCamelCase   : Any								=self.prepare_config_and_inputs()
				lowerCamelCase		,   lowerCamelCase		,   lowerCamelCase		,   lowerCamelCase   : str								=config_and_inputs
				lowerCamelCase   : Dict								={'''pixel_values''': pixel_values}
				return config, inputs_dict

@require_torch
class        snake_case_		(			_A						,					_A						,					unittest.TestCase):
		lowerCamelCase    :Union[str, Any]						=     (
		    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
		    if is_torch_available()
		    else ()
		)
		lowerCamelCase    :Any						=     (
		    {
		        "feature-extraction": MobileNetVaModel,
		        "image-classification": MobileNetVaForImageClassification,
		        "image-segmentation": MobileNetVaForSemanticSegmentation,
		    }
		    if is_torch_available()
		    else {}
		)

		lowerCamelCase    :List[str]						=     False
		lowerCamelCase    :Dict						=     False
		lowerCamelCase    :Any						=     False
		lowerCamelCase    :Dict						=     False







		def 			__lowercase   (		self   )				->   Any:
				lowerCamelCase   : Union[str, Any]								=MobileNetVaModelTester(self   )
				lowerCamelCase   : List[str]								=MobileNetVaConfigTester(self			,     config_class=__lowercase			,     has_text_modality=__lowercase   )







		def 			__lowercase   (		self   )				->   int:
				self.config_tester.run_common_tests()







		@unittest.skip(reason='''MobileNetV2 does not use inputs_embeds'''   )
		def 			__lowercase   (		self   )				->   Dict:
				pass







		@unittest.skip(reason='''MobileNetV2 does not support input and output embeddings'''   )
		def 			__lowercase   (		self   )				->   Optional[Any]:
				pass







		@unittest.skip(reason='''MobileNetV2 does not output attentions'''   )
		def 			__lowercase   (		self   )				->   List[Any]:
				pass







		def 			__lowercase   (		self   )				->   List[Any]:
				lowerCamelCase		,   lowerCamelCase   : Optional[Any]								=self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
						lowerCamelCase   : int								=model_class(__lowercase   )
						lowerCamelCase   : Any								=inspect.signature(model.forward   )
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						lowerCamelCase   : str								=[*signature.parameters.keys()]

						lowerCamelCase   : Optional[Any]								=['''pixel_values''']
						self.assertListEqual(arg_names[:1]			,     __lowercase   )







		def 			__lowercase   (		self   )				->   Optional[Any]:
				lowerCamelCase   : Optional[Any]								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*__lowercase   )







		def 			__lowercase   (		self   )				->   str:
				def check_hidden_states_output(__lowercase			,     __lowercase			,     __lowercase   ):
						lowerCamelCase   : Dict								=model_class(__lowercase   )
						model.to(__lowercase   )
						model.eval()

						with torch.no_grad():
								lowerCamelCase   : Tuple								=model(**self._prepare_for_class(__lowercase			,     __lowercase   )   )

						lowerCamelCase   : Union[str, Any]								=outputs.hidden_states

						lowerCamelCase   : Tuple								=1_6
						self.assertEqual(len(__lowercase   )			,     __lowercase   )

				lowerCamelCase		,   lowerCamelCase   : Union[str, Any]								=self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
						lowerCamelCase   : int								=True
						check_hidden_states_output(__lowercase			,     __lowercase			,     __lowercase   )

						# check that output_hidden_states also work using config
						del inputs_dict["output_hidden_states"]
						lowerCamelCase   : Optional[int]								=True

						check_hidden_states_output(__lowercase			,     __lowercase			,     __lowercase   )







		def 			__lowercase   (		self   )				->   List[Any]:
				lowerCamelCase   : List[str]								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*__lowercase   )







		def 			__lowercase   (		self   )				->   int:
				lowerCamelCase   : Any								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_semantic_segmentation(*__lowercase   )







		@slow
		def 			__lowercase   (		self   )				->   List[Any]:
				for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowerCamelCase   : Dict								=MobileNetVaModel.from_pretrained(__lowercase   )
						self.assertIsNotNone(__lowercase   )


def 					A__	(       )   ->     List[Any]:
		lowerCamelCase   : List[str]								=Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
		return image



@require_torch
@require_vision
class        snake_case_		(			unittest.TestCase):







		@cached_property
		def 			__lowercase   (		self   )				->   int:
				return (
				    MobileNetVaImageProcessor.from_pretrained('''google/mobilenet_v2_1.0_224'''   ) if is_vision_available() else None
				)







		@slow
		def 			__lowercase   (		self   )				->   int:
				lowerCamelCase   : Tuple								=MobileNetVaForImageClassification.from_pretrained('''google/mobilenet_v2_1.0_224'''   ).to(__lowercase   )

				lowerCamelCase   : Dict								=self.default_image_processor
				lowerCamelCase   : Dict								=prepare_img()
				lowerCamelCase   : List[Any]								=image_processor(images=__lowercase			,     return_tensors='''pt'''   ).to(__lowercase   )

				# forward pass
				with torch.no_grad():
						lowerCamelCase   : Any								=model(**__lowercase   )

				# verify the logits
				lowerCamelCase   : Optional[Any]								=torch.Size((1, 1_0_0_1)   )
				self.assertEqual(outputs.logits.shape			,     __lowercase   )

				lowerCamelCase   : Optional[Any]								=torch.tensor([0.2_4_4_5, -1.1_9_9_3, 0.1_9_0_5]   ).to(__lowercase   )

				self.assertTrue(torch.allclose(outputs.logits[0, :3]			,     __lowercase			,     atol=1e-4   )   )







		@slow
		def 			__lowercase   (		self   )				->   List[Any]:
				lowerCamelCase   : Optional[Any]								=MobileNetVaForSemanticSegmentation.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''   )
				lowerCamelCase   : Union[str, Any]								=model.to(__lowercase   )

				lowerCamelCase   : List[Any]								=MobileNetVaImageProcessor.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''   )

				lowerCamelCase   : Any								=prepare_img()
				lowerCamelCase   : Dict								=image_processor(images=__lowercase			,     return_tensors='''pt'''   ).to(__lowercase   )

				# forward pass
				with torch.no_grad():
						lowerCamelCase   : Optional[Any]								=model(**__lowercase   )
				lowerCamelCase   : List[str]								=outputs.logits

				# verify the logits
				lowerCamelCase   : int								=torch.Size((1, 2_1, 6_5, 6_5)   )
				self.assertEqual(logits.shape			,     __lowercase   )

				lowerCamelCase   : List[Any]								=torch.tensor(
				    [
				        [[1_7.5_7_9_0, 1_7.7_5_8_1, 1_8.3_3_5_5], [1_8.3_2_5_7, 1_8.4_2_3_0, 1_8.8_9_7_3], [1_8.6_1_6_9, 1_8.8_6_5_0, 1_9.2_1_8_7]],
				        [[-2.1_5_9_5, -2.0_9_7_7, -2.3_7_4_1], [-2.4_2_2_6, -2.3_0_2_8, -2.6_8_3_5], [-2.7_8_1_9, -2.5_9_9_1, -2.7_7_0_6]],
				        [[4.2_0_5_8, 4.8_3_1_7, 4.7_6_3_8], [4.4_1_3_6, 5.0_3_6_1, 4.9_3_8_3], [4.5_0_2_8, 4.9_6_4_4, 4.8_7_3_4]],
				    ]			,     device=__lowercase			,     )

				self.assertTrue(torch.allclose(logits[0, :3, :3, :3]			,     __lowercase			,     atol=1e-4   )   )

