How to use _group_string method in autotest

Best Python code snippet using autotest_python

csv_encoder.py

Source:csv_encoder.py Github

copy

Full Screen

...26class SpreadsheetCsvEncoder(CsvEncoder):27 def _total_index(self, group, num_columns):28 row_index, column_index = group['header_indices']29 return row_index * num_columns + column_index30 def _group_string(self, group):31 result = '%s / %s' % (group['pass_count'], group['complete_count'])32 if group['incomplete_count'] > 0:33 result += ' (%s incomplete)' % group['incomplete_count']34 if 'extra_info' in group:35 result = '\n'.join([result] + group['extra_info'])36 return result37 def _build_value_table(self):38 value_table = [''] * self._num_rows * self._num_columns39 for group in self._response['groups']:40 total_index = self._total_index(group, self._num_columns)41 value_table[total_index] = self._group_string(group)42 return value_table43 def _header_string(self, header_value):44 return '/'.join(header_value)45 def _process_value_table(self, value_table, row_headers):46 total_index = 047 for row_index in xrange(self._num_rows):48 row_header = self._header_string(row_headers[row_index])49 row_end_index = total_index + self._num_columns50 row_values = value_table[total_index:row_end_index]51 self._append_output_row([row_header] + row_values)52 total_index += self._num_columns53 def encode(self):54 header_values = self._response['header_values']55 assert len(header_values) == 2...

Full Screen

Full Screen

present.py

Source:present.py Github

copy

Full Screen

...22 res['model'] = model_name23 results += metrics24 self.results = results25 26 def _group_string(self, res):27 # create a string from the concatenation of values defined in the group28 s = '#'.join('%s=%s' %(key, str(res[key])) for key in self.group if key in res)29 return s30 31 def filter_and_group(self):32 # filter results according to condition33 results_filtered = [res for res in self.results if not False in 34 [res[key] == val for key, val in self.condition.items()]]35 # find the posible value combinations to group by36 group_strings = set( self._group_string(res) for res in results_filtered)37 # create a dictionary with results for each group38 results_dic = {group_string: {'x': [], 'y': []} for group_string in group_strings}39 for res in results_filtered:40 res_string = self._group_string(res)41 results_dic[res_string]['x'].append(res[self.x])42 results_dic[res_string]['y'].append(res[self.y])43 # sort the results of the group according to x44 for res_string, res_group in results_dic.items():45 x = np.array(res_group['x'])46 y = np.array(res_group['y'])47 sort_indices = np.argsort(x)48 res_group['x'] = x[sort_indices]49 res_group['y'] = y[sort_indices]50 return results_dic51 52 def plot(self, xlim=(), ylim=(), legend_loc=0):53 # get results_dic54 results_dic = self.filter_and_group()...

Full Screen

Full Screen

problem_3.py

Source:problem_3.py Github

copy

Full Screen

1import numpy as np2from scipy import sparse3from sklearn.covariance import EmpiricalCovariance4from sklearn.datasets import load_svmlight_file5from sklearn.linear_model import LogisticRegression6from sklearn.preprocessing import MultiLabelBinarizer7from skmultilearn.problem_transform import LabelPowerset8from FINALS.pb3.trainBR import get_instance_f19class GroupClassifier:10 def __init__(self, label_groups, no_of_labels) -> None:11 super().__init__()12 self.no_of_labels = no_of_labels13 self.label_groups = label_groups14 self.classifiers = []15 def fit(self, features, labels):16 for label_group in self.label_groups:17 temp_labels = np.zeros((features.shape[0], self.no_of_labels), dtype=int)18 for ix, x in enumerate(features):19 for _label in label_group:20 temp_labels[ix, _label] = labels[ix, _label]21 _classifier = LabelPowerset(LogisticRegression(solver='liblinear', penalty="l1", C=0.1,22 multi_class='ovr',23 tol=1e-8, max_iter=100))24 _classifier.fit(features, sparse.csr_matrix(temp_labels))25 self.classifiers.append(_classifier)26 def predict(self, features):27 predictions = np.zeros((features.shape[0], self.no_of_labels))28 for _classifier in self.classifiers:29 temp_pred = ([list(line.nonzero()[1]) for line in _classifier.predict(features)])30 for ix, _pred in enumerate(temp_pred):31 if _pred:32 predictions[ix, _pred] = 133 return predictions34def create_groups(y):35 label_covariance = EmpiricalCovariance().fit(y).covariance_36 _groups = []37 _groups_set = set()38 for i in range(10):39 _group = []40 for j in range(10):41 if i != j and j > i and label_covariance[i][j] >= 0.0024:42 _group.append(j)43 _group_string = str(sorted(_group))44 if _group and _group_string not in _groups_set:45 _groups.append(_group)46 _groups_set.add(_group_string)47 return _groups48x_train, y_train = load_svmlight_file("all_train.csv", multilabel=True, n_features=30, zero_based=True)49x_test, y_test = load_svmlight_file("all_test.csv", multilabel=True, n_features=30, zero_based=True)50tran = MultiLabelBinarizer()51y_train2 = tran.fit_transform(y_train)52y_test2 = tran.fit_transform(y_test)53groups = create_groups(np.append(y_train2, y_test2, axis=0))54groups = [[0, 1, 2], [3, 4, 5, 9], [6, 7, 8]]55print("Groups=>", groups)56group_classifier = GroupClassifier(groups, 10)57group_classifier.fit(x_train, y_train2)58y_train_pred = group_classifier.predict(x_train)59tr1, tr2 = get_instance_f1(y_train_pred, y_train)60print("datasets\taccuracy\tf1")61print("train\t" + str(tr1) + "\t" + str(tr2))62y_test_pred = group_classifier.predict(x_test)63test1, test2 = get_instance_f1(y_test_pred, y_test)...

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 autotest 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