$ vendor/bin/phpunit analytics/tests/prediction_test.php --testdox Moodle 3.8dev (Build: 20190920), c2c1cbd40a50cccc92eb9379bed139c506cfb1cb Php: 7.3.7, pgsql: 9.6.14, OS: Darwin 18.7.0 x86_64 PHPUnit 7.5.15 by Sebastian Bergmann and contributors. core_analytics_prediction_testcase ✔ Static prediction ✔ Ml training and prediction with data set "no_splitting-\mlbackend_php\processor" ✔ Ml training and prediction with data set "quarters-\mlbackend_php\processor" → Ml training and prediction with data set "no_splitting-\mlbackend_python\processor" → Ml training and prediction with data set "quarters-\mlbackend_python\processor" ✘ Ml training and prediction with data set "no_splitting-\mlbackend_python\processor-server" │ │ moodle_exception: Server error HTTP status code 500: │ │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
evaluation
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.evaluate_dataset(datasetpath,
│ float(minscore),
│ float(maxdeviation),
│ int(niterations),
│ trainedmodeldir)
│ │
return json.dumps(result)
│ │
│
@app.route('/evaluationlog', methods=['GET'])
evaluate_dataset
│
# Classes balance check.
│ y_array = np.array(self.y.T[0])
│ unique_elements, counts = np.unique(y_array, return_counts=True)
│ │
if not np.array_equal(np.sort(self.classes), np.sort(unique_elements)):
│ result = dict()
│ result['runid'] = int(self.get_runid())
│ result['status'] = GENERAL_ERROR
│ result['info'] = ['The labels from the provided dataset do not ' +
│ 'match the targetclasses from the header']
AttributeError: 'Classifier' object has no attribute 'classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
evaluation
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.evaluate_dataset(datasetpath,
│ float(minscore),
│ float(maxdeviation),
│ int(niterations),
│ trainedmodeldir)
│ │
return json.dumps(result)
│ │
│
@app.route('/evaluationlog', methods=['GET'])
evaluate_dataset
│
# Classes balance check.
│ y_array = np.array(self.y.T[0])
│ unique_elements, counts = np.unique(y_array, return_counts=True)
│ │
if not np.array_equal(np.sort(self.classes), np.sort(unique_elements)):
│ result = dict()
│ result['runid'] = int(self.get_runid())
│ result['status'] = GENERAL_ERROR
│ result['info'] = ['The labels from the provided dataset do not ' +
│ 'match the targetclasses from the header']
AttributeError: 'Classifier' object has no attribute 'classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
evaluation
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.evaluate_dataset(datasetpath,
│ float(minscore),
│ float(maxdeviation),
│ int(niterations),
│ trainedmodeldir)
│ │
return json.dumps(result)
│ │
│
@app.route('/evaluationlog', methods=['GET'])
evaluate_dataset
│
# Classes balance check.
│ y_array = np.array(self.y.T[0])
│ unique_elements, counts = np.unique(y_array, return_counts=True)
│ │
if not np.array_equal(np.sort(self.classes), np.sort(unique_elements)):
│ result = dict()
│ result['runid'] = int(self.get_runid())
│ result['status'] = GENERAL_ERROR
│ result['info'] = ['The labels from the provided dataset do not ' +
│ 'match the targetclasses from the header']
AttributeError: 'Classifier' object has no attribute 'classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
evaluation
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.evaluate_dataset(datasetpath,
│ float(minscore),
│ float(maxdeviation),
│ int(niterations),
│ trainedmodeldir)
│ │
return json.dumps(result)
│ │
│
@app.route('/evaluationlog', methods=['GET'])
evaluate_dataset
│
# Classes balance check.
│ y_array = np.array(self.y.T[0])
│ unique_elements, counts = np.unique(y_array, return_counts=True)
│ │
if not np.array_equal(np.sort(self.classes), np.sort(unique_elements)):
│ result = dict()
│ result['runid'] = int(self.get_runid())
│ result['status'] = GENERAL_ERROR
│ result['info'] = ['The labels from the provided dataset do not ' +
│ 'match the targetclasses from the header']
AttributeError: 'Classifier' object has no attribute 'classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│AttributeError: 'Classifier' object has no attribute 'n_classes'
│__call__
│
def __call__(self, environ, start_response):
│ """The WSGI server calls the Flask application object as the
│ WSGI application. This calls :meth:`wsgi_app` which can be
│ wrapped to applying middleware."""
│ return self.wsgi_app(environ, start_response)
│ │
def __repr__(self):
│ return '<%s %r>' % (
│ self.__class__.__name__,
│ self.name,
wsgi_app
try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
│ raise
│ return response(environ, start_response)
│ finally:
handle_exception
# if we want to repropagate the exception, we can attempt to
│ # raise it with the whole traceback in case we can do that
│ # (the function was actually called from the except part)
│ # otherwise, we just raise the error again
│ if exc_value is e:
│ reraise(exc_type, exc_value, tb)
│ else:
│ raise e
│ │
self.log_exception((exc_type, exc_value, tb))
│ if handler is None:
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
wsgi_app
ctx = self.request_context(environ)
│ error = None
│ try:
│ try:
│ ctx.push()
│ response = self.full_dispatch_request()
│ except Exception as e:
│ error = e
│ response = self.handle_exception(e)
│ except:
│ error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
│ """Given the return value from a view function this finalizes
│ the request by converting it into a response and invoking the
handle_user_exception
return self.handle_http_exception(e)
│ │
handler = self._find_error_handler(e)
│ │
if handler is None:
│ reraise(exc_type, exc_value, tb)
│ return handler(e)
│ │
def handle_exception(self, e):
│ """Default exception handling that kicks in when an exception
│ occurs that is not caught. In debug mode the exception will
reraise
import collections.abc as collections_abc
│ │
def reraise(tp, value, tb=None):
│ if value.__traceback__ is not tb:
│ raise value.with_traceback(tb)
│ raise value
│ │
implements_to_string = _identity
│ │
else:│
text_type = unicode
full_dispatch_request
self.try_trigger_before_first_request_functions()
│ try:
│ request_started.send(self)
│ rv = self.preprocess_request()
│ if rv is None:
│ rv = self.dispatch_request()
│ except Exception as e:
│ rv = self.handle_user_exception(e)
│ return self.finalize_request(rv)
│ │
def finalize_request(self, rv, from_error_handler=False):
dispatch_request
# request came with the OPTIONS method, reply automatically
│ if getattr(rule, 'provide_automatic_options', False) \
│ and req.method == 'OPTIONS':
│ return self.make_default_options_response()
│ # otherwise dispatch to the handler for that endpoint
│ return self.view_functions[rule.endpoint](**req.view_args)
│ │
def full_dispatch_request(self):
│ """Dispatches the request and on top of that performs request
│ pre and postprocessing as well as HTTP exception catching and
│ error handling.
access_wrapper
if (userdata[0] == request.authorization.username and
│ userdata[1] == request.authorization.password):
│ │
# If all good we return the return from 'f' passing the
│ # original list of params to it.
│ return f(*args, **kwargs)
│ │
# Response for the client.
│ return 'Incorrect user and/or password provided by Moodle.', 401
│ │
return access_wrapper
wrapper
@wraps(f)
│ def wrapper(*args, **kwargs):
│ '''Execute the decorated function passing the call args.'''
│ │
update_wrapper(self, f)
│ return f(*args, **kwargs)
│ return wrapper
training
modeldir = storage.get_model_dir('dirhash')
│ │
datasetpath = get_file_path(storage.get_localbasedir(), 'dataset')
│ │
classifier = estimator.Classifier(uniquemodelid, modeldir)
│ result = classifier.train_dataset(datasetpath)
│ │
return json.dumps(result)
│ │
│
@app.route('/prediction', methods=['POST'])
train_dataset
│
def train_dataset(self, filepath):
│ """Train the model with the provided dataset"""
│ [self.X, self.y] = self.get_labelled_samples(filepath)
│ │
if len(np.unique(self.y)) < self.n_classes:
│ # We need samples belonging to all different classes.
│ result = dict()
│ result['status'] = NOT_ENOUGH_DATA
│ result['info'] = []
│ result['errors'] = 'Training data needs to include ' + \
AttributeError: 'Classifier' object has no attribute 'n_classes'│
│ The console is locked and needs to be unlocked by entering the PIN. │ You can find the PIN printed out on the standard output of your │ shell that runs the server. │
│