@@ -24,7 +24,8 @@ class Mljar(object):
2424 This is a wrapper over MLJAR API - it does all the stuff.
2525 '''
2626
27- def __init__ (self , project , experiment ,
27+ def __init__ (self , project ,
28+ experiment ,
2829 metric = '' ,
2930 algorithms = [],
3031 validation_kfolds = MLJAR_DEFAULT_FOLDS ,
@@ -316,3 +317,40 @@ def predict(self, X):
316317 logger .error ('Sorry, there was some problem with computing prediction for your dataset. \
317318 Please login to mljar.com to your account and check details.' )
318319 return None
320+
321+
322+ @staticmethod
323+ def compute_prediction (X , model_id , project_id ):
324+
325+
326+ # chack if dataset exists in mljar if not upload dataset for prediction
327+ dataset = DatasetClient (project_id ).add_dataset_if_not_exists (X , y = None )
328+
329+ # check if prediction is available
330+ total_checks = 100
331+ for i in xrange (total_checks ):
332+ prediction = PredictionClient (project_id ).\
333+ get_prediction (dataset .hid , model_id )
334+
335+ # prediction is not available, first check so submit job
336+ if i == 0 and prediction is None :
337+ # create prediction job
338+ submitted = PredictJobClient ().submit (project_id , dataset .hid ,
339+ model_id )
340+ if not submitted :
341+ logger .error ('Problem with prediction for your dataset' )
342+ return None
343+
344+ if prediction is not None :
345+ pred = PredictionDownloadClient ().download (prediction .hid )
346+ #sys.stdout.write('\r\n')
347+ return pred
348+
349+ #sys.stdout.write('\rFetch predictions: {0}%'.format(round(i/(total_checks*0.01))))
350+ #sys.stdout.flush()
351+ time .sleep (5 )
352+
353+ #sys.stdout.write('\r\n')
354+ logger .error ('Sorry, there was some problem with computing prediction for your dataset. \
355+ Please login to mljar.com to your account and check details.' )
356+ return None
0 commit comments