Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_process_prediction(self):
model_path = 'tests/fixtures/test_predict_by_model/iris'
options = fsclient.read_json_file(os.path.join(model_path, "options.json"))
target_categories = ["setosa", "versicolor", "virginica"]
ds = DataFrame.create_dataframe(os.path.join(model_path, "iris_test.csv"))
ds.drop([options['targetFeature']])
results = ["setosa", "versicolor", "virginica", "setosa", "versicolor", "virginica"]
results_proba = None
proba_classes = None
ModelHelper.process_prediction(ds,
results, results_proba, proba_classes,
None, options.get('minority_target_class'),
options['targetFeature'], target_categories)
ds_test = DataFrame.create_dataframe(os.path.join(model_path, "iris_test.csv"))
self.assertEqual(ds.dtypes, ds_test.dtypes)
self.assertEqual(ds.df.values.tolist(), ds_test.df.values.tolist())
self.assertEqual( len(res['data']), 6)
ds = DataFrame.create_dataframe(os.path.join(model_path, "iris_test.csv"))
fsclient.remove_file(results_file_path)
self.assertFalse(fsclient.is_file_exists(results_file_path))
fsclient.remove_file(predicted_file_path)
self.assertFalse(fsclient.is_file_exists(predicted_file_path))
ds.options['data_path'] = None
res = ModelHelper.save_prediction(ds, prediction_id,
support_review_model=False, json_result=False, count_in_result=False, prediction_date=prediction_date,
model_path=model_path, model_id=options.get('uid'))
self.assertEqual( type(res[0]), dict)
self.assertEqual( res[0][options['targetFeature']], 'setosa')
ds = DataFrame.create_dataframe(os.path.join(model_path, "iris_test.csv"))
fsclient.remove_file(results_file_path)
self.assertFalse(fsclient.is_file_exists(results_file_path))
fsclient.remove_file(predicted_file_path)
self.assertFalse(fsclient.is_file_exists(predicted_file_path))
ds.options['data_path'] = None
ds.loaded_columns = ds.columns
res = ModelHelper.save_prediction(ds, prediction_id,
support_review_model=False, json_result=False, count_in_result=False, prediction_date=prediction_date,
model_path=model_path, model_id=options.get('uid'))
self.assertEqual( res['columns'], ds.columns)
self.assertEqual( len(res['data']), 6)
self.assertEqual( type(res['data'][0]), list)
model_path = 'tests/fixtures/test_predict_by_model/iris'
options = fsclient.read_json_file(os.path.join(model_path, "options.json"))
target_categories = ["setosa", "versicolor", "virginica"]
ds = DataFrame.create_dataframe(os.path.join(model_path, "iris_test.csv"))
ds.drop([options['targetFeature']])
results = ["setosa", "versicolor", "virginica", "setosa", "versicolor", "virginica"]
results_proba = None
proba_classes = None
ModelHelper.process_prediction(ds,
results, results_proba, proba_classes,
None, options.get('minority_target_class'),
options['targetFeature'], target_categories)
ds_test = DataFrame.create_dataframe(os.path.join(model_path, "iris_test.csv"))
self.assertEqual(ds.dtypes, ds_test.dtypes)
self.assertEqual(ds.df.values.tolist(), ds_test.df.values.tolist())
def _predict_on_cloud(self, filename, model_id, threshold, data, columns, output):
ds = DataFrame.create_dataframe(filename, data, columns)
pipeline_api = AugerPipelineApi(self.ctx, None, model_id)
predictions = pipeline_api.predict(ds.get_records(), ds.columns, threshold)
ds_result = DataFrame.create_dataframe(None, records=predictions['data'], features=predictions['columns'])
ds_result.options['data_path'] = filename
return ModelHelper.save_prediction_result(ds_result,
prediction_id = None, support_review_model = False,
json_result=False, count_in_result=False, prediction_date=None,
model_path=None, model_id=model_id, output=output)
def _predict_on_cloud(self, filename, model_id, threshold, data, columns, output):
ds = DataFrame.create_dataframe(filename, data, columns)
pipeline_api = AugerPipelineApi(self.ctx, None, model_id)
predictions = pipeline_api.predict(ds.get_records(), ds.columns, threshold)
ds_result = DataFrame.create_dataframe(None, records=predictions['data'], features=predictions['columns'])
ds_result.options['data_path'] = filename
return ModelHelper.save_prediction_result(ds_result,
prediction_id = None, support_review_model = False,
json_result=False, count_in_result=False, prediction_date=None,
model_path=None, model_id=model_id, output=output)