Mavzu: Qo’lda yozilgan raqamni aniqlash uchun dataset shakllantirish Bajardi : Ismoilov Temurbek Qabul qildi : Temirov Azizbek tuit 2022-2023 Ishning maqsadi


Download 278.23 Kb.
bet2/2
Sana18.01.2023
Hajmi278.23 Kb.
#1098422
1   2
Bog'liq
3-lab MIT Temurbek

def Euclidean_distance(row1, row2):
distance = 0
for i in range(len(row1)-1):
distance += (row1[i] — row2[i])**2
return sqrt(distance)

Eucledian masofasini topib olamiz

def Get_Neighbors(train, test_row, num):

distance = list() # []


data = []
for i in train:
dist = Euclidean_distance(test_row, i)
distance.append(dist)
data.append(i)
distance = np.array(distance)
data = np.array(data)
index_dist = distance.argsort()
data = data[index_dist]
neighbors = data[:num]

return neighbors



Masofani tartiblagandan so'ng, k eng yaqin qo'shnilarni olish

def predict_classification(train, test_row, num):
Neighbors = Get_Neighbors(train, test_row, num)
Classes = []
for i in Neighbors:
Classes.append(i[-1])
prediction = max(Classes, key= Classes.count)
return prediction

Yangi ma'lumotlar nuqtasi sinfini bashorat qilish

def accuracy(y_true, y_pred):
n_correct = 0
for i in range(len(y_true)):
if y_true[i] == y_pred[i]:
n_correct += 1
acc = n_correct/len(y_true)
return acc

Aniqlikni hisoblash

Aniqlik o'lchangan qiymatning haqiqiy qiymatga qanchalik yaqinligini ko'rsatadi.



from sklearn.datasets import fetch_openml, load_digits
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib

Kutubxonalarni import qiling

standard format
mnist.keys()
mnist.target = mnist.target.astype(np.int8)
x = np.array(mnist.data)
y = np.array(mnist.target)
x.shape, y.shape
si = np.random.permutation(x.shape[0])
x = x[si]
y = y[si]



Ma'lumotlarni oldindan qayta ishlash

some_digit = x[12]
some_digit_image = some_digit.reshape(28, 28)
plt.imshow(some_digit_image, cmap=matplotlib.cm.binary)
plt.axis(“off”)
plt.show()

Ma'lumotlarning vizualizatsiyasi

trainx = x[:2000]
trainy = y[:2000]
train = np.insert(trainx, 784, trainy, axis = 1)prediction = predict_classification(train, train[1244], 4)
prediction
#Output 8.0



Modelni bashorat qilish


Dastur natijalari.


  1. Birinchi qadamimiz yani raqamlarni saqlash jarayonlari




  1. Raqamlarni alohida chiqish tartibini ko’rsatish



  1. Bitta belgini tanlash va tahlil qilish



  1. Raqam chiqishini tahrirlash

KNN algoritmi
6 ta berilgan sonlar Ichida eng yaqinini tanlash va taqqoslash




  1. Raqamlarni saqlash jarayonlari




  1. Va yakuniy datasetimizdan foydalanib kiritilgan raqamni olish




XULOSA
Ushbu amaliy mashg‘ulot python dasturlash tilida datasetlarni yaratish va ulardan foydalanishni o’rganish maqsadida foydalanildi . Bu topshiriq davomida bir nechta kurubxonalardan foydalanilgan hamda quyidagicha xulosalar va natijalar keltirilgan:
1. Adabiyotlar tahlil qilingan
2. Kiritilgan ,ma’lumotlar asosida dataset shakllantirilgan
3. Datasetdan malumot olish va tekshirish tartibi qo’llanilgan
Foydalanilgan adabiyotlar ro‘yxati
1. https://www.w3schools.com/python/module_statistics.asp
2. https://www.analyticsvidhya.com/blog/2022/04/a-comprehensive-guide-on-pygal-the-next-generation-data-visualization-library-in-python/
Download 278.23 Kb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling