Best Python code snippet using lemoncheesecake
varyParameters.py
Source:varyParameters.py
...56 while (epoch < training_epochs):57 epoch = epoch + 158 for minibatch_index in xrange(n_train_batches):59 minibatch_avg_cost1 = r_train_fn(minibatch_index)60 predict_y, origin_y = r_get_test_label() 61 print 'first results from right DBN , presion, recall, F1, accuracy: '62 print >> saveFile,'origin_y: ',origin_y63 print >> saveFile,'predict_y: ',predict_y64 predict_y = change2PrimaryC(predict_y)65 origin_y = change2PrimaryC(origin_y)66 print >> saveFile,'first results from right DBN , presion, recall, F1, accuracy: '67 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)68 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)69 70 r_sigmoid_layers,r_output,r_params = rDBN.getParams(train_set_x)71 r_sigmoid_layersT,r_outputT,r_paramsT = rDBN.getParams(test_set_x)72 print shape(r_sigmoid_layers())73 74 new_features = []75 l_features = []76 new_featuresT = []77 for x in topic_x:78 l_features = append(l_features,x)79# l_features = [l_sigmoid_layers()[i] for i in xrange(len_left)]80# new_features = map(list,zip(*(map(list,zip(*a))+map(list,zip(*b)))))81 print shape(l_features)82 for r_feature in r_sigmoid_layers():83 new_features.append(append(l_features,r_feature))84 for r_feature in r_sigmoid_layersT():85 new_featuresT.append(append(l_features,r_feature))86 print shape(new_features),shape(new_featuresT)87 88# sim_result = similarity(r_sigmoid_layers(),topic_x)89# new_features = []90# for i in xrange(len(sim_result)):91# feature = append(topic_x[sim_result[i]],(r_sigmoid_layers()[i]))92# new_features.append(feature)93# sim_result = similarity(r_sigmoid_layersT(),topic_x)94# new_featuresT = []95# for i in xrange(len(sim_result)):96# feature = append(topic_x[sim_result[i]],(r_sigmoid_layersT()[i]))97# new_featuresT.append(feature)98# print shape(new_features),shape(new_featuresT)99 100 101 n_dim = shape(new_features)[1]102 shared_x = theano.shared(numpy.asarray(new_features,dtype=theano.config.floatX),borrow=True)103 shared_y = theano.shared(numpy.asarray(new_featuresT,dtype=theano.config.floatX),borrow=True)104 105 layers=[100]106 print >> saveFile,'top layer hidden units: ',layers107 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)108 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)109 for i in xrange(dbn.n_layers):110 for epoch in xrange(pretraining_epochs):111 c = []112 for batch_index in xrange(n_train_batches):113 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))114# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),115# print numpy.mean(c)116 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]117 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(118 datasets=datasets, batch_size=batch_size,119 learning_rate=finetune_lr)120 epoch = 0121 while (epoch < training_epochs):122 epoch = epoch + 1123 for minibatch_index in xrange(n_train_batches):124 minibatch_avg_cost = train_fn(minibatch_index)125 predict_y, origin_y = get_test_label() 126 print 'second results from LDADBN, presion, recall, F1, accuracy: '127 print >> saveFile,'predict_y: ',predict_y128 predict_y = change2PrimaryC(predict_y)129 origin_y = change2PrimaryC(origin_y)130 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '131 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)132 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)133 134 layers=[200]135 print >> saveFile,'top layer hidden units: ',layers136 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)137 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)138 for i in xrange(dbn.n_layers):139 for epoch in xrange(pretraining_epochs):140 c = []141 for batch_index in xrange(n_train_batches):142 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))143# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),144# print numpy.mean(c)145 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]146 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(147 datasets=datasets, batch_size=batch_size,148 learning_rate=finetune_lr)149 epoch = 0150 while (epoch < training_epochs):151 epoch = epoch + 1152 for minibatch_index in xrange(n_train_batches):153 minibatch_avg_cost = train_fn(minibatch_index)154 predict_y, origin_y = get_test_label() 155 print 'second results from LDADBN, presion, recall, F1, accuracy: '156 print >> saveFile,'predict_y: ',predict_y157 predict_y = change2PrimaryC(predict_y)158 origin_y = change2PrimaryC(origin_y)159 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '160 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)161 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)162 163 layers=[300]164 print >> saveFile,'top layer hidden units: ',layers165 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)166 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)167 for i in xrange(dbn.n_layers):168 for epoch in xrange(pretraining_epochs):169 c = []170 for batch_index in xrange(n_train_batches):171 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))172# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),173# print numpy.mean(c)174 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]175 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(176 datasets=datasets, batch_size=batch_size,177 learning_rate=finetune_lr)178 epoch = 0179 while (epoch < training_epochs):180 epoch = epoch + 1181 for minibatch_index in xrange(n_train_batches):182 minibatch_avg_cost = train_fn(minibatch_index)183 predict_y, origin_y = get_test_label() 184 print 'second results from LDADBN, presion, recall, F1, accuracy: '185 print >> saveFile,'predict_y: ',predict_y186 predict_y = change2PrimaryC(predict_y)187 origin_y = change2PrimaryC(origin_y)188 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '189 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)190 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)191 192 layers=[400]193 print >> saveFile,'top layer hidden units: ',layers194 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)195 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)196 for i in xrange(dbn.n_layers):197 for epoch in xrange(pretraining_epochs):198 c = []199 for batch_index in xrange(n_train_batches):200 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))201# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),202# print numpy.mean(c)203 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]204 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(205 datasets=datasets, batch_size=batch_size,206 learning_rate=finetune_lr)207 epoch = 0208 while (epoch < training_epochs):209 epoch = epoch + 1210 for minibatch_index in xrange(n_train_batches):211 minibatch_avg_cost = train_fn(minibatch_index)212 predict_y, origin_y = get_test_label() 213 print 'second results from LDADBN, presion, recall, F1, accuracy: '214 print >> saveFile,'predict_y: ',predict_y215 predict_y = change2PrimaryC(predict_y)216 origin_y = change2PrimaryC(origin_y)217 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '218 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)219 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)220 221 layers=[500]222 print >> saveFile,'top layer hidden units: ',layers223 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)224 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)225 for i in xrange(dbn.n_layers):226 for epoch in xrange(pretraining_epochs):227 c = []228 for batch_index in xrange(n_train_batches):229 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))230# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),231# print numpy.mean(c)232 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]233 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(234 datasets=datasets, batch_size=batch_size,235 learning_rate=finetune_lr)236 epoch = 0237 while (epoch < training_epochs):238 epoch = epoch + 1239 for minibatch_index in xrange(n_train_batches):240 minibatch_avg_cost = train_fn(minibatch_index)241 predict_y, origin_y = get_test_label() 242 print 'second results from LDADBN, presion, recall, F1, accuracy: '243 print >> saveFile,'predict_y: ',predict_y244 predict_y = change2PrimaryC(predict_y)245 origin_y = change2PrimaryC(origin_y)246 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '247 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)248 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)249 250 layers=[600]251 print >> saveFile,'top layer hidden units: ',layers252 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)253 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)254 for i in xrange(dbn.n_layers):255 for epoch in xrange(pretraining_epochs):256 c = []257 for batch_index in xrange(n_train_batches):258 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))259# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),260# print numpy.mean(c)261 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]262 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(263 datasets=datasets, batch_size=batch_size,264 learning_rate=finetune_lr)265 epoch = 0266 while (epoch < training_epochs):267 epoch = epoch + 1268 for minibatch_index in xrange(n_train_batches):269 minibatch_avg_cost = train_fn(minibatch_index)270 predict_y, origin_y = get_test_label() 271 print 'second results from LDADBN, presion, recall, F1, accuracy: '272 print >> saveFile,'predict_y: ',predict_y273 predict_y = change2PrimaryC(predict_y)274 origin_y = change2PrimaryC(origin_y)275 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '276 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)277 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)278 279 layers=[700]280 print >> saveFile,'top layer hidden units: ',layers281 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)282 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)283 for i in xrange(dbn.n_layers):284 for epoch in xrange(pretraining_epochs):285 c = []286 for batch_index in xrange(n_train_batches):287 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))288# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),289# print numpy.mean(c)290 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]291 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(292 datasets=datasets, batch_size=batch_size,293 learning_rate=finetune_lr)294 epoch = 0295 while (epoch < training_epochs):296 epoch = epoch + 1297 for minibatch_index in xrange(n_train_batches):298 minibatch_avg_cost = train_fn(minibatch_index)299 predict_y, origin_y = get_test_label() 300 print 'second results from LDADBN, presion, recall, F1, accuracy: '301 print >> saveFile,'predict_y: ',predict_y302 predict_y = change2PrimaryC(predict_y)303 origin_y = change2PrimaryC(origin_y)304 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '305 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)306 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)307 308 layers=[800]309 print >> saveFile,'top layer hidden units: ',layers310 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)311 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)312 for i in xrange(dbn.n_layers):313 for epoch in xrange(pretraining_epochs):314 c = []315 for batch_index in xrange(n_train_batches):316 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))317# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),318# print numpy.mean(c)319 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]320 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(321 datasets=datasets, batch_size=batch_size,322 learning_rate=finetune_lr)323 epoch = 0324 while (epoch < training_epochs):325 epoch = epoch + 1326 for minibatch_index in xrange(n_train_batches):327 minibatch_avg_cost = train_fn(minibatch_index)328 predict_y, origin_y = get_test_label() 329 print 'second results from LDADBN, presion, recall, F1, accuracy: '330 print >> saveFile,'predict_y: ',predict_y331 predict_y = change2PrimaryC(predict_y)332 origin_y = change2PrimaryC(origin_y)333 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '334 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)335 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)336 337 layers=[900]338 print >> saveFile,'top layer hidden units: ',layers339 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)340 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)341 for i in xrange(dbn.n_layers):342 for epoch in xrange(pretraining_epochs):343 c = []344 for batch_index in xrange(n_train_batches):345 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))346# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),347# print numpy.mean(c)348 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]349 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(350 datasets=datasets, batch_size=batch_size,351 learning_rate=finetune_lr)352 epoch = 0353 while (epoch < training_epochs):354 epoch = epoch + 1355 for minibatch_index in xrange(n_train_batches):356 minibatch_avg_cost = train_fn(minibatch_index)357 predict_y, origin_y = get_test_label() 358 print 'second results from LDADBN, presion, recall, F1, accuracy: '359 print >> saveFile,'predict_y: ',predict_y360 predict_y = change2PrimaryC(predict_y)361 origin_y = change2PrimaryC(origin_y)362 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '363 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)364 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)365 366 layers=[1000]367 print >> saveFile,'top layer hidden units: ',layers368 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)369 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)370 for i in xrange(dbn.n_layers):371 for epoch in xrange(pretraining_epochs):372 c = []373 for batch_index in xrange(n_train_batches):374 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))375# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),376# print numpy.mean(c)377 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]378 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(379 datasets=datasets, batch_size=batch_size,380 learning_rate=finetune_lr)381 epoch = 0382 while (epoch < training_epochs):383 epoch = epoch + 1384 for minibatch_index in xrange(n_train_batches):385 minibatch_avg_cost = train_fn(minibatch_index)386 predict_y, origin_y = get_test_label() 387 print 'second results from LDADBN, presion, recall, F1, accuracy: '388 print >> saveFile,'predict_y: ',predict_y389 predict_y = change2PrimaryC(predict_y)390 origin_y = change2PrimaryC(origin_y)391 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '392 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)393 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)394 395 layers=[1100]396 print >> saveFile,'top layer hidden units: ',layers397 dbn = DBN(n_ins=n_dim, hidden_layers_sizes=layers,n_outs=26)398 pretraining_fns = dbn.pretraining_function(shared_x, batch_size, k)399 for i in xrange(dbn.n_layers):400 for epoch in xrange(pretraining_epochs):401 c = []402 for batch_index in xrange(n_train_batches):403 c.append(pretraining_fns[i](index=batch_index,lr=pretrain_lr))404# print 'Final Pre-training layer %i, epoch %d, cost ' % (i, epoch),405# print numpy.mean(c)406 datasets = [(shared_x,train_set_y),(shared_y,test_set_y)]407 train_fn, test_score, get_test_label, features = dbn.build_finetune_functions(408 datasets=datasets, batch_size=batch_size,409 learning_rate=finetune_lr)410 epoch = 0411 while (epoch < training_epochs):412 epoch = epoch + 1413 for minibatch_index in xrange(n_train_batches):414 minibatch_avg_cost = train_fn(minibatch_index)415 predict_y, origin_y = get_test_label() 416 print 'second results from LDADBN, presion, recall, F1, accuracy: '417 print >> saveFile,'predict_y: ',predict_y418 predict_y = change2PrimaryC(predict_y)419 origin_y = change2PrimaryC(origin_y)420 print >> saveFile,'second results from LDADBN, presion, recall, F1, accuracy: '421 print evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)422 print >> saveFile,evaluation(predict_y, origin_y),getAccuracy(predict_y, origin_y)423 424 425 end_time = time.clock()426 print >> saveFile,'Finish all using %.2f mins' % ((end_time - start_time) / 60.)427 print 'Finish all using %.2f mins' % ((end_time - start_time) / 60.)428 print >>saveFile,'------------------------------------------------------------------------------'429# layers = []...
SVMModel.py
Source:SVMModel.py
...30 clf, predicted = svm_imbalanced.train_and_predict()31 svm_imbalanced.display_confusion_matrix(predicted)32 svm_imbalanced.print_accuracy(predicted)33 print(f"Classification report for classifier {clf}:\n"34 f"{metrics.classification_report(svm_imbalanced.get_test_label(), predicted)}\n")35 # test_image, actual_label, predicted_label = svm_imbalanced.get_misclassified(predicted)36 # svm_imbalanced.display_samples(test_image, actual_label, predicted_label, False)37 print('Imbalanced with Symmetrical Noise')38 sym_non_balanced = SVMModel(balanced=False, noise_type='sym', noise_ratio=40)39 sym_non_balanced.scale_pixels()40 sym_non_balanced.show_class_distribution(False)41 clf2, predicted2 = sym_non_balanced.train_and_predict()42 sym_non_balanced.display_confusion_matrix(predicted2)43 sym_non_balanced.print_accuracy(predicted2)44 print(f"Classification report for classifier {clf2}:\n"45 f"{metrics.classification_report(sym_non_balanced.get_test_label(), predicted2)}\n")46 print('Imbalanced with Asymmetrical Noise')47 asym_non_balanced = SVMModel(balanced=False, noise_type='asym', noise_ratio=40)48 asym_non_balanced.scale_pixels()49 asym_non_balanced.show_class_distribution(False)50 clf3, predicted3 = asym_non_balanced.train_and_predict()51 asym_non_balanced.display_confusion_matrix(predicted3)52 asym_non_balanced.print_accuracy(predicted3)53 print(f"Classification report for classifier {clf3}:\n"54 f"{metrics.classification_report(asym_non_balanced.get_test_label(), predicted3)}\n")55 print('Balanced with No Noise')56 svm_balanced = SVMModel(balanced=True, noise_type='No Noise', noise_ratio=0)57 svm_balanced.scale_pixels()58 svm_balanced.show_class_distribution(False)59 clf6, predicted6 = svm_balanced.train_and_predict()60 svm_balanced.display_confusion_matrix(predicted6)61 svm_balanced.print_accuracy(predicted6)62 print(f"Classification report for classifier {clf6}:\n"63 f"{metrics.classification_report(svm_balanced.get_test_label(), predicted6)}\n")64 print('Balanced with Symmetrical Noise')65 sym_balanced = SVMModel(balanced=True, noise_type='sym', noise_ratio=40)66 sym_balanced.scale_pixels()67 sym_balanced.show_class_distribution(False)68 clf4, predicted4 = sym_balanced.train_and_predict()69 sym_balanced.display_confusion_matrix(predicted4)70 sym_balanced.print_accuracy(predicted4)71 print(f"Classification report for classifier {clf4}:\n"72 f"{metrics.classification_report(sym_balanced.get_test_label(), predicted4)}\n")73 print('Balanced with Asymmetrical Noise')74 asym_balanced = SVMModel(balanced=True, noise_type='asym', noise_ratio=40)75 asym_balanced.scale_pixels()76 asym_balanced.show_class_distribution(False)77 clf5, predicted5 = asym_balanced.train_and_predict()78 asym_balanced.display_confusion_matrix(predicted5)79 asym_balanced.print_accuracy(predicted5)80 print(f"Classification report for classifier {clf5}:\n"...
train_classifier.py
Source:train_classifier.py
...33 print("The length of image are train: {} test: {}".format(len(train_image_paths),len(test_image_paths)))34 print("Ambiguity will be filtered")35 #load label file36 meta = pd.read_csv(meta)37 train_X, train_y = get_test_label(meta,train_image_paths)38 val_X, val_y = train_test_split(train_X,train_y,validation_proportion)39 test_X, test_y = get_test_label(meta,test_image_paths)40 print("*"*50)41 print("Train: {} Validation: {} Test: {}".format(len(train_X),len(val_X),len(test_X)))42 # Create Dataset43 train_dataset = ClassifierDataset(train_X,train_y,config['augmentation'])44 val_dataset = ClassifierDataset(val_X,val_y,config['augmentation'])...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!