示例#1
0
def main():
    # Create a Knn object
    knn_classifier = Knn("diabetes.csv")

    # Set k as 20
    knn_classifier.set_k(20)
    knn_classifier.get_confusion_matrix()
示例#2
0
class PublicApi():
        def __init__(self):
                self.app = flask.Flask(__name__)
                CORS(self.app)
                self.app.config["DEBUG"] = True
                self.knn = Knn(3)                

        def start(self):
                @self.app.route('/api/predict', methods=['POST'])
                def api_id():    
                        logging.info(request.args)
                        if 'radiant_score' in request.args and 'dire_score' in request.args and 'duration' in request.args:
                                radiant_score = int(request.args['radiant_score'])
                                dire_score = int(request.args['dire_score'])
                                duration = int(request.args['duration'])
                                self.knn.set_k(int(request.args['k']))
                                result = self.knn.predict([[radiant_score,dire_score,duration]])
                                logging.info(result[0])
                                text_result = ''
                                logging.error(self.knn.k)
                                if result[0] == 1:
                                        text_result = 'Radiant wins!'
                                else:
                                        text_result = 'Dire wins!'                                        
                                        
                                self.knn.plot2D(radiant_score-dire_score,duration,text_result)
                                return str('{"result": \"'+text_result+'\"}')
                        else:
                                return "Missed a field"
                self.app.run(host='0.0.0.0', port=8080)
示例#3
0
from flask import request, jsonify, render_template, make_response
import numpy as np
import cv2
import sys
import base64
import io
from knn import Knn
from PIL import Image
from flask_cors import CORS

app = flask.Flask(__name__)
CORS(app)
app.config["DEBUG"] = True

knn = Knn()
knn.set_k(100)


@app.route('/getMathAnswer', methods=['POST'])
def getMathAnswer():
    if 'base64' in request.json:
        try:
            data = request.json['base64']
            imgdata = base64.b64decode(data)
            filename = 'some_image.png'
            # print(request.json)
            with open(filename, 'wb') as f:
                f.write(imgdata)
            im = cv2.imread(filename)
            # customHeight = int(request.json['height'])
            # customHeight = int(customHeight*0.7)
示例#4
0
from flask import request, jsonify, render_template, make_response
import numpy as np
import cv2
import sys
import base64
import io
from knn import Knn
from PIL import Image
from flask_cors import CORS

app = flask.Flask(__name__)
CORS(app)
app.config["DEBUG"] = True

knn = Knn()
knn.set_k(70)


@app.route('/getMathAnswer', methods=['POST'])
def getMathAnswer():
    if 'base64' in request.json:
        try:
            data = request.json['base64']
            imgdata = base64.b64decode(data)
            filename = 'some_image.png'
            # print(request.json)
            with open(filename, 'wb') as f:
                f.write(imgdata)
            im = cv2.imread(filename)
            # customHeight = int(request.json['height'])
            # customHeight = int(customHeight*0.7)