Untitled
Guest 566 13th May, 2024
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
iris = pd.read_csv('iris.data',header=None)
X = iris.iloc[:,:-1].values
Y = iris.iloc[:,-1].values
print(X.shape)
plt.boxplot(X)
plt.show()
def klasy_dla_somsiadow(ziom,somsiady,ilu,ile_klas=3):
ilu_somsiadow = few_somsiady(ziom,somsiady,ilu)
somsiad_klases = {"Iris-setosa":0,"Iris-versicolor":0,"Iris-verginica":0}
for somsiad_id in ilu_somsiadow:
somsiad_klases[Y[somsiad_id]] += 1
print(somsiad_klases)
return max(somsiad_klases)
def few_somsiady(ziom,somsiady,ilu):
kilku_somsiadow = []
for _ in range(ilu):
nowysomsiad, somsiaddistance = closest_somsiad(ziom,somsiady,kilku_somsiadow)
kilku_somsiadow.append(nowysomsiad)
print(kilku_somsiadow)
return kilku_somsiadow
def closest_somsiad(ziom,somsiady,current_somsiads = []):
index = 0
min_distance = policz_droge_do_najblizszego_skurwysyna_zlodzieja(ziom,somsiady[0:1][0])
for idx,somsiad in enumerate(somsiady):
temp_distance = policz_droge_do_najblizszego_skurwysyna_zlodzieja(ziom,somsiad)
if temp_distance < min_distance and idx not in current_somsiads:
index = idx
min_distance = temp_distance
return index,min_distance
def policz_droge_do_najblizszego_skurwysyna_zlodzieja(x1,x2):
return sum((x-y) **2 for x,y in zip(x1,x2))
temp = [4.8, 3.1, 4.44, 0.9]
x = np.arange(1,10)
plt.plot(x,few_somsiady(temp,X,len(x)))
plt.show()
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
- Always favorable prices for services such assensual massag in New Yourk
Java | 1 | 15 minutes ago
- Untitled
Markup | 6 | 7 hours ago
- bakus
Python | 6 | 7 hours ago
- brak balansu
Markup | 7 | 8 hours ago
- Fallout Shelter
SQL | 11 | 16 hours ago
- Untitled
Markup | 13 | 19 hours ago
- Керамзит 5 10
Elixir | 12 | 20 hours ago