Beispiel #1
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        lik = get_likelihood(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        scale = float(request.POST["scale"])
    except:
        raise ValueError("Scale is not correct")
    try:
        domain = json.loads(request.POST['axis_domain'])
        x, y, z, width, param, best_scale = gaussian_process.classify_gp(features, labels, kernel, domain, lik, learn, scale)
    except Exception as e:
        return HttpResponse(json.dumps({"status": repr(e)}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'best_width': float(width),
                                     'best_param': float(param),
                                     'best_scale': float(best_scale),
                                     'domain': [np.min(z), np.max(z)],
                                     'z': z.tolist() }))
Beispiel #2
0
def classify(request):
    value=[]
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))    

    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    if kernel.get_name() == 'PolyKernel' and learn == "GridSearch":
        value.append(int(request.POST["polygrid1"]))
        value.append(int(request.POST["polygrid2"]))
        if value[1] <= value[0]:
            return HttpResponse(json.dumps({"status": "Bad values"}))

    try:
        C = float(request.POST["C"])
        domain = json.loads(request.POST['axis_domain'])
        x, y, z = svm.classify_svm(sg.LibSVM, features, labels, kernel, domain, learn, value, C=C)
    except Exception as e:
        import traceback
        return HttpResponse(json.dumps({"status": repr(traceback.format_exc(0))}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'domain': [np.min(z), np.max(z)],
                                     'z': z.tolist() }))
Beispiel #3
0
def classify(request):
    value = []
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    if int(features.get_num_vectors()) > 100 and learn == "GridSearch":
        return HttpResponse(
            json.dumps({
                "status":
                ("Model Selection "
                 "allowed only for less than 100 samples due to computational costs"
                 )
            }))

    if kernel.get_name() == 'PolyKernel' and learn == "GridSearch":
        value.append(int(request.POST["polygrid1"]))
        value.append(int(request.POST["polygrid2"]))
        if value[1] <= value[0]:
            return HttpResponse(json.dumps({"status":
                                            "Bad values for degree"}))

    try:
        C = float(request.POST["C"])
        domain = json.loads(request.POST['axis_domain'])
        x, y, z = svm.classify_svm(sg.LibSVM,
                                   features,
                                   labels,
                                   kernel,
                                   domain,
                                   learn,
                                   value,
                                   C=C)
    except Exception as e:
        import traceback
        return HttpResponse(
            json.dumps({"status": repr(traceback.format_exc(0))}))

    return HttpResponse(
        json.dumps({
            'status': 'ok',
            'domain': [np.min(z), np.max(z)],
            'z': z.tolist()
        }))
Beispiel #4
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    try:
        rate = float(request.POST["rate"])
        bias = float(request.POST['bias'])
        z_value, z_label = classify_perceptron(sg.Perceptron, features, labels, rate, bias)
    except Exception as e:
        return HttpResponse(json.dumps({"status": e}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'domain': [np.min(z_value), np.max(z_value)],
                                     'z': z_value.tolist() }))
Beispiel #5
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        lik = get_likelihood(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    if int(features.get_num_vectors()) > 100 and learn == "ML2":
        return HttpResponse(
            json.dumps({
                "status":
                ("Model Selection "
                 "allowed only for less than 100 samples due to computational costs"
                 )
            }))

    try:
        scale = float(request.POST["scale"])
    except:
        raise ValueError("Scale is not correct")
    try:
        domain = json.loads(request.POST['axis_domain'])
        x, y, z, width, param, best_scale = gaussian_process.classify_gp(
            features, labels, kernel, domain, lik, learn, scale)
    except Exception as e:
        return HttpResponse(json.dumps({"status": repr(e)}))

    return HttpResponse(
        json.dumps({
            'status': 'ok',
            'best_width': float(width),
            'best_param': float(param),
            'best_scale': float(best_scale),
            'domain': [np.min(z), np.max(z)],
            'z': z.tolist()
        }))
Beispiel #6
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    try:
        C = float(request.POST["C"])
        x, y, z = svm.classify_svm(sg.LibSVM, features, labels, kernel, domain, C=C)
    except Exception as e:
        import traceback
        return HttpResponse(json.dumps({"status": repr(traceback.format_exc())}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'domain': [np.min(z), np.max(z)],
                                     'z': z.tolist() }))
Beispiel #7
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        lik = get_likelihood(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    
    if int(features.get_num_vectors()) > 100 and learn == "ML2":
        return HttpResponse(json.dumps({"status": ("Model Selection " 
            "allowed only for less than 100 samples due to computational costs")}))

    try:
        scale = float(request.POST["scale"])
    except:
        raise ValueError("Scale is not correct")
    try:
        domain = json.loads(request.POST['axis_domain'])
        x, y, z, width, param, best_scale = gaussian_process.classify_gp(features, labels, kernel, domain, lik, learn, scale)
    except Exception as e:
        return HttpResponse(json.dumps({"status": repr(e)}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'best_width': float(width),
                                     'best_param': float(param),
                                     'best_scale': float(best_scale),
                                     'domain': [np.min(z), np.max(z)],
                                     'z': z.tolist() }))