pplonski / my_ml_service

My Machine Learning Web Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attribute error MLRegistry object has not attribute 'endpoints'

ashrafuljoypb opened this issue · comments

I am trying to run the code of tests.py so that I can confirm that no issues in the class.
so how can I solve it?
Traceback (most recent call last):
File "/Users/dpashraful/PycharmProjects/Dpml_ex1/dpmlex1/ml/tests.py", line 34, in test_registry
self.assertEqual(len(registry.endpoints), 0)
^^^^^^^^^^^^^^^^^^
AttributeError: 'MLRegistry' object has no attribute 'endpoints'

Here are the tests.py code files code:
import inspect
from django.test import TestCase
from .income_classifier.random_forest import RandomForestClassifier
from .registry import MLRegistry

class MLTests(TestCase):
def test_rf_algorithm(self):
input_data = {
"age": 37,
"workclass": "Private",
"fnlwgt": 34146,
"education": "HS-grad",
"education-num": 9,
"marital-status": "Married-civ-spouse",
"occupation": "Craft-repair",
"relationship": "Husband",
"race": "White",
"sex": "Male",
"capital-gain": 0,
"capital-loss": 0,
"hours-per-week": 68,
"native-country": "United-States"
}
my_alg = RandomForestClassifier()
response = my_alg.compute_prediction(input_data)
self.assertEqual('OK', response['status'])
self.assertTrue('label' in response)
self.assertEqual('<=50K', response['label'])

# add below method to MLTests class:
def test_registry(self):
    registry = MLRegistry()
    self.assertEqual(len(registry.endpoints), 0)
    endpoint_name = "income_classifier"
    algorithm_object = RandomForestClassifier()
    algorithm_name = "random forest"
    algorithm_status = "production"
    algorithm_version = "0.0.1"
    algorithm_owner = "Piotr"
    algorithm_description = "Random Forest with simple pre- and post-processing"
    algorithm_code = inspect.getsource(RandomForestClassifier)
    # add to registry
    registry.add_algorithm(endpoint_name, algorithm_object, algorithm_name,
                           algorithm_status, algorithm_version, algorithm_owner,
                           algorithm_description, algorithm_code)
    # there should be one endpoint available
    self.assertEqual(len(registry.endpoints), 1)