demo/3
ludovic.castglia 5 months ago
parent edb706659f
commit 04ac5cca7a

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

@ -0,0 +1,31 @@
from nnnar import *
from knn import *
import random
import matplotlib.pyplot as plt
import numpy as np
image = plt.imread('./data/img.jpg')
image = np.array(image)
height, width, _ = image.shape
def replaceRandomPixel(image,nb):
for i in range(nb):
y = random.randint(0, height - 1)
x = random.randint(0, width - 1)
v = [random.randint(0,255), random.randint(0,255), random.randint(0,255)]
n = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
for i in n:
if (y+i[0] >= 0 and y+i[0] < height and x+i[1] >= 0 and x+i[1] < width):
image[y+i[0],x+i[1]] = v
return image
image = replaceRandomPixel(image, 1000)
plt.imshow(image)
plt.axis('off')
plt.show()

@ -32,7 +32,7 @@ def runOneTest(trainTestRatio):
value = train.iloc[:, -1].values
for i in range(len(coord)):
nnnar.addPoint(np.array(coord[i]), np.array([value[i]]))
knn.addPoint(np.array(coord[i]), np.array([value[i]]))
# Test du modèle
coord = test.iloc[:, :-1].values
@ -40,7 +40,7 @@ def runOneTest(trainTestRatio):
nbError = 0
for i in range(len(coord)):
if nnnar.getLabelOfPoint(np.array(coord[i]), 5) != value[i]:
if knn.getLabelOfPoint(np.array(coord[i]), 5) != value[i]:
nbError += 1
return 100 - nbError / len(coord) * 100

Loading…
Cancel
Save