Advertisement
DomMisterSoja

Trab.Python(Catalogação de flores)(otimizado do otimizado do

Sep 10th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. import random
  2. escolha = 0
  3. while(escolha!=4):
  4.   print('1-Usuario da informações linha por linha\n2-Usuario  da informações de cada vez\n3-Calibragem\n4-Sair')
  5.   i=int(input('\n'))
  6.   escolha==i
  7.   if(i==1):
  8.     z = []
  9.     x=input('Insira as informações da flor')
  10.     x=x.split(',')
  11.     k=int(input('Valores de k na checagem\n'))
  12.     for i in x:
  13.       a=float(i)
  14.       z.append(a)
  15.      
  16.  
  17.   if(i==2):
  18.     z = []
  19.     k=int(input('Valores de k na checagem\n'))
  20.     for i in range(4):
  21.       a = float(input('Insira os dados\n'))
  22.       z.append(a)
  23.   if(i==3):
  24.     check=[]
  25.     arquivo1 = open('iris_test.dat','r')
  26.     for i in arquivo1:
  27.       info = i.split(',')
  28.       c = 0
  29.       z = []
  30.       geralz=[]
  31.       for i in info:
  32.           if c <= 3:
  33.               i = float(i)
  34.               x.append(i)
  35.           if c == 4:
  36.               check.append(i)
  37.           geralz.append(x)
  38.           c += 1
  39.  
  40.   arquivo = open('iris.dat', 'r')
  41.   geral = []
  42.   ivirgi = []
  43.   ivers = []
  44.   iset = []
  45.  
  46.   for i in arquivo:
  47.       info = i.split(',')
  48.       c = 0
  49.       x = []
  50.       dist = []
  51.       for i in info:
  52.           if c <= 3:
  53.               i = float(i)
  54.               x.append(i)
  55.               if c == 3:
  56.                   for j in range(4):
  57.                       n=(z[j]-x[j])**2
  58.                       dist.append(n)
  59.                   n1=0
  60.                   n2=0
  61.                   for x in dist:
  62.                       n1+=x
  63.                   n2=n1**(1/2)
  64.                   geral.append(n2)
  65.           if c == 4:
  66.               if (i == 'Iris-virginica\n'):
  67.                   ivirgi.append(n2)
  68.               elif (i == 'Iris-setosa\n'):
  69.                   iset.append(n2)
  70.               elif (i == 'Iris-versicolor\n'):
  71.                   ivers.append(n2)
  72.           c += 1
  73.   geral = sorted(geral)
  74.   ivirgi = sorted(ivirgi)
  75.   ivers = sorted(ivers)
  76.   iset = sorted(iset)
  77.  
  78.   SIvirg = 0
  79.   SIvers = 0
  80.   SIset = 0    
  81.   while(k-1 >= len(geral)):
  82.     print('k extrapola o o número de amostras')
  83.     k=int(input('Valores de k na checagem\n'))
  84.   for i in range(k):
  85.       if geral[i] in ivirgi:
  86.           SIvirg += 1
  87.       elif geral[i] in ivers:
  88.           SIvers += 1
  89.       elif geral[i] in iset:
  90.           SIset += 1
  91.   if i==1 or i ==2 :
  92.     check2=[]
  93.     if SIvirg >= SIvers:
  94.         if SIvirg>=SIset:
  95.             check2.append('Os dados da flor inserida, mostram que ela é : Iris-virginica.')
  96.     if SIvers >= SIvirg:
  97.         if SIvers>= SIset:
  98.             check2.append('Os dados da flor inserida, mostram que ela é : Iris-versicolor.')
  99.     if SIset >= SIvirg:
  100.         if SIset>=SIvers:
  101.             check2.append('Os dados da flor inserida, mostram que ela é : Iris-Setosa.')
  102.     print(random.choice(check2))
  103.     arquivo.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement