How to use _get_intercept method in gabbi

Best Python code snippet using gabbi_python

linear.py

Source:linear.py Github

copy

Full Screen

...7 def assemble(self):8 return self._build_ast()9 def _build_ast(self):10 coef = utils.to_2d_array(self._get_coef())11 intercept = utils.to_1d_array(self._get_intercept())12 if coef.shape[0] == 1:13 return self._final_transform(_linear_to_ast(coef[0], intercept[0]))14 exprs = [15 self._final_transform(_linear_to_ast(coef[idx], intercept[idx]))16 for idx in range(coef.shape[0])17 ]18 return ast.VectorVal(exprs)19 def _final_transform(self, ast_to_transform):20 return ast_to_transform21 def _get_intercept(self):22 raise NotImplementedError23 def _get_coef(self):24 raise NotImplementedError25class SklearnLinearModelAssembler(BaseLinearModelAssembler):26 def _get_intercept(self):27 return getattr(self.model, "intercept_", np.zeros(self._get_coef().shape[0]))28 def _get_coef(self):29 return self.model.coef_30class StatsmodelsLinearModelAssembler(BaseLinearModelAssembler):31 def __init__(self, model):32 super().__init__(model)33 const_idx = self.model.model.data.const_idx34 if const_idx is None and self.model.k_constant:35 raise ValueError("Unknown constant position")36 self.const_idx = const_idx37 def _get_intercept(self):38 return (self.model.params[self.const_idx]39 if self.model.k_constant40 else 0.0)41 def _get_coef(self):42 idxs = np.arange(len(self.model.params))43 return (44 self.model.params[idxs != self.const_idx]45 if self.model.k_constant46 else self.model.params)47class ProcessMLEModelAssembler(BaseLinearModelAssembler):48 def _get_intercept(self):49 return 0.050 def _get_coef(self):51 return self.model.params[:self.model.k_exog]52class GLMMixin:53 def _final_transform(self, ast_to_transform):54 link_function = self._get_link_function_name()55 link_function_lower = link_function.lower()56 supported_inversed_funs = self._get_supported_inversed_funs()57 if link_function_lower not in supported_inversed_funs:58 raise ValueError(f"Unsupported link function '{link_function}'")59 fun = supported_inversed_funs[link_function_lower]60 return fun(ast_to_transform)61 def _get_link_function_name(self):62 raise NotImplementedError...

Full Screen

Full Screen

suite.py

Source:suite.py Github

copy

Full Screen

...32 """Override TestSuite run to start suite-level fixtures.33 To avoid exception confusion, use a null Fixture when there34 are no fixtures.35 """36 fixtures, intercept, host, port, prefix = self._get_intercept()37 try:38 with fixture.nest([fix() for fix in fixtures]):39 if intercept:40 with interceptor.Urllib3Interceptor(41 intercept, host, port, prefix):42 result = super(GabbiSuite, self).run(result, debug)43 else:44 result = super(GabbiSuite, self).run(result, debug)45 except unittest.SkipTest as exc:46 for test in self._tests:47 result.addSkip(test, str(exc))48 # If we have an exception in the nested fixtures, that means49 # there's been an exception somewhere in the cycle other50 # than a specific test (as that would have been caught51 # already), thus from a fixture. If that exception were to52 # continue to raise here, then some test runners would53 # swallow it and the traceback of the failure would be54 # undiscoverable. To ensure the traceback is reported (via55 # the testrunner) to a human, the first test in the suite is56 # marked as having an error (it's fixture failed) and then57 # the entire suite is skipped, and the result stream told58 # we're done. If there are no tests (an empty suite) the59 # exception is re-raised.60 except Exception:61 if self._tests:62 result.addError(self._tests[0], sys.exc_info())63 for test in self._tests:64 result.addSkip(test, 'fixture failure')65 result.stop()66 else:67 raise68 return result69 def start(self, result, tests=None):70 """Start fixtures when using pytest."""71 tests = tests or []72 fixtures, intercept, host, port, prefix = self._get_intercept()73 self.used_fixtures = []74 try:75 for fix in fixtures:76 fix_object = fix()77 fix_object.__enter__()78 self.used_fixtures.append(fix_object)79 except unittest.SkipTest as exc:80 # Disable the already collected tests that we now wish81 # to skip.82 for test in tests:83 test.run = noop84 test.add_marker('skip')85 result.addSkip(self, str(exc))86 if intercept:87 intercept_fixture = interceptor.Urllib3Interceptor(88 intercept, host, port, prefix)89 intercept_fixture.__enter__()90 self.used_fixtures.append(intercept_fixture)91 def stop(self):92 """Stop fixtures when using pytest."""93 for fix in reversed(self.used_fixtures):94 fix.__exit__(None, None, None)95 def _get_intercept(self):96 fixtures = [fixture.GabbiFixture]97 intercept = host = port = prefix = None98 try:99 first_test = self._find_first_full_test()100 fixtures = first_test.fixtures101 host = first_test.host102 port = first_test.port103 prefix = first_test.prefix104 intercept = first_test.intercept105 # Unbind a passed in WSGI application. During the106 # metaclass building process intercept becomes bound.107 try:108 intercept = intercept.__func__109 except AttributeError:...

Full Screen

Full Screen

regression_tester.py

Source:regression_tester.py Github

copy

Full Screen

...24 rstring = ''25 if not self.is_skl:26 rstring = str(self.regression)27 else:28 rstring = '{0} {1}'.format(self._get_intercept(),29 self._get_coef())30 print('-' * 20, self.key, '-' * 20)31 print('P = ', rstring)32 def prints(self, dataset):33 data = self.data_cache[dataset]34 X, Y = self.split(data)35 print('S = {0:.2f} % C = {1:.2f}'36 .format(*Stats().calculate(37 self.regression, X, Y, self.precision)))38 def printy(self, dataset, count=10):39 if not count:40 return41 data = self.data_cache[dataset]42 X, Y = self.split(data)43 for i, y in ((i, y) for i, y in44 enumerate(self.regression.predict(X)) if i < count):45 print('Ye = {0:.2f}, Yr = {1}'.format(y, Y[i]))46 def split(self, data):47 lt = int(self.is_skl)48 X = [f[lt:-1] for f in data]49 Y = [f[-1] for f in data]50 return X, Y51 def _get_intercept(self):52 if hasattr(self.regression, 'intercept_'):53 return self.regression.intercept_54 if hasattr(self.regression, 'intercepts_'):55 return (str(self.regression.intercepts_)56 .replace('\n', '')57 .replace('\t', '')58 .replace(' ', '')59 .replace('array', ''))60 raise Exception('Solver not supported')61 def _get_coef(self):62 if hasattr(self.regression, 'coef_'):63 return str(self.regression.coef_).replace('\n', '')64 if hasattr(self.regression, 'coefs_'):65 return (str(self.regression.coefs_)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run gabbi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful