Skip to content

Instantly share code, notes, and snippets.

View Guidosalimbeni's full-sized avatar
🎯
Focusing

Guido Salimbeni Guidosalimbeni

🎯
Focusing
View GitHub Profile
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)
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])
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]
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
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=[]
@Guidosalimbeni
Guidosalimbeni / medium-web-scraping-selenium-and-price-prediction-with-prophet.ipynb
Created January 13, 2021 23:00
Medium Web Scraping Selenium and price prediction with Prophet.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Guidosalimbeni
Guidosalimbeni / add.php
Created April 15, 2022 11:38
PHP connection to a MySQL database
<?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'];
@Guidosalimbeni
Guidosalimbeni / submit.js
Created April 15, 2022 11:45
Submit to PHP connection to MySQL
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),