This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let question = "test question'; | |
| let answer = 'test answer'; | |
| let form = new FormData(); | |
| form.append("question", question); | |
| form.append("answer", answer); | |
| fetch("http://www.guidosalimbeni.it/-- xxx xxx xxx --- .php", { | |
| // URL | |
| // body: JSON.stringify(form), // data you send. | |
| body: new URLSearchParams(form), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $servername = "xxx.xxx.xxx.xxx"; | |
| $username = "username"; | |
| $password = "******"; | |
| $database = "name"; | |
| $table = "data"; | |
| // your data here depending on things coded in the front end | |
| $question = $_POST['question']; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def main(): | |
| # prepare data | |
| trainingSet=df.values.tolist()[:18] | |
| testSet=df.values.tolist()[19:] | |
| print ('Train set: ' + repr(len(trainingSet))) | |
| print ('Test set: ' + repr(len(testSet))) | |
| # generate predictions | |
| predictions=[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getAccuracy(testSet, predictions): | |
| correct = 0 | |
| for x in range(len(testSet)): | |
| if testSet[x][-1] == predictions[x]: | |
| correct += 1 | |
| return (correct/float(len(testSet))) * 100.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getResponse(neighbors): | |
| classVotes = {} | |
| for x in range(len(neighbors)): | |
| response = neighbors[x][-1] | |
| if response in classVotes: | |
| classVotes[response] += 1 | |
| else: | |
| classVotes[response] = 1 | |
| sortedVotes = sorted(classVotes.items(), key=operator.itemgetter(1), reverse=True) | |
| return sortedVotes[0][0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getNeighbors(trainingSet, testInstance, k): | |
| distances = [] | |
| length = len(testInstance)-1 | |
| for x in range(len(trainingSet)): | |
| dist = euclideanDistance(testInstance, trainingSet[x], length) | |
| distances.append((trainingSet[x], dist)) | |
| distances.sort(key=operator.itemgetter(1)) | |
| neighbors = [] | |
| for x in range(k): | |
| neighbors.append(distances[x][0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def euclideanDistance(instance1, instance2, length): | |
| distance = 0 | |
| for x in range(length): | |
| distance += pow((float(instance1[x]) - float(instance2[x])), 2) | |
| return math.sqrt(distance) |