Fan Mashinali o‘qitishga kirish amaliy ish №3 Mavzu



Download 78,96 Kb.
Sana18.07.2022
Hajmi78,96 Kb.
#824344
Bog'liq
3-amaliy machine learning


O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Kafedra Sun’iy intellekt


Fan Mashinali o‘qitishga kirish

AMALIY ISH №3

Mavzu: Mashinali o‘qitishda klassik sinflashtirish algoritmlari va ularni dasturlash

Ta’lim yo‘nalishi: Kompyuter injiniringi


Guruh: IML001-2
Bajardi: Abduhakimov Fayzullo
Tekshirdi: Ochilov Mannon
Toshkent – 2022
3-amaliy ish
Mavzu: Mashinali o‘qitishda klassik sinflashtirish algoritmlari va ularni dasturlash



Masala

O‘zgaruvchi tanlamadagi misollar soni

Sinflar soni

Xususiyatlari soni

2

O‘simta xavflilik darajasini bashorat qiling

60

2

2


Ishni bajarish tartibi:

  1. Variantdagi berilgan shartni qanoatlantiruvchi datasetni shakllantiramiz. O‘simtaning xususiyatlari: uning o‘lchami va rivojlanish davri. Pythonda ushbu datasetni yaratib olamiz:

import numpy as np
#o‘simta kattaligi, rivojlanish davri
data = np.array([
[1, 10],
[1.1, 13],
[1.67, 33],
[1.2, 15],
[1.24, 20],
[1.34, 57],
[1.98, 42],
[4.23, 70],
[2.29, 35],
[2.34, 47],
[1.32, 33],
[1.4, 155],
[1.48, 27],
[1.75, 38],
[5.7, 33],
[1.8, 77],
[1.29, 21],
[2.1, 49],
[2.3, 22],
[2.39, 37],
[2.42, 56],
[2.41, 43],
[3.37, 73],
[2.2, 40],
[2.04, 38],
[2.16, 77],
[1.91, 22],
[1.78, 35],
[2.55, 43],
[3.4, 78],
[3.13, 50],
[3.12, 61],
[3.39, 89],
[4.03, 79],
[4.02, 85],
[3.34, 97],
[4.13, 92],
[4.24, 64],
[4.55, 92],
[4.98, 101],
[4.73, 69],
[4.61, 94],
[2.67, 56],
[5.1, 98],
[4.44, 89],
[4.41, 80],
[4.67, 99],
[4.77, 11],
[5.21, 103],
[5.24, 99],
[5.98, 122],
[5.88, 120],
[5.35, 132],
[5.87, 138],
[6.01, 147],
[6.03, 135],
[6.08, 109],
[5.77, 127],
[5.11, 92],
[5.14, 73],


])


target = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])
target_name = np.array(['Yengil shakli', 'Og\'ir shakli'])

2. Yaratilgan datasetning 2 ta xususiyatini olgan holda matplotlib kutubxonasi orqali grafik hosil qilamiz:


X = data[:, :2]
Y = target
from matplotlib import pyplot as plt
plt.figure(figsize=(6,6))
plt.scatter(*X[Y==0].T,s=30, alpha=1,label=target_name[0],color='red')
plt.scatter(*X[Y==1].T,s=30, alpha=1,label=target_name[1],color='green')
plt.xlabel('O\'simta kattaligi')
plt.ylabel('O\'simta davri')
plt.legend()
plt.show()


1-rasm. O’simta kattaligining o’simta davriga bog’liqlik grafigi
3. Yaratilgan datasetni modelni o‘qitish uchun 85 % va testlash uchun 15% nisbatda bo‘laklarga ajratamiz.
# Import Library for splitting data
from sklearn.model_selection import train_test_split


# Creating Train and Test datasets
X_train, X_test, y_train, y_test = train_test_split(X,Y, random_state = 42, test_size = 0.15)

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)

4. a) KNN sinflashtirish modelini quramiz:


#KNN
from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors =2)
classifier.fit(X_train, y_train)

Endi ushbu model asosida test va train to’plami uchun aniqliklarni topamiz:




y_pred_test = classifier.predict(X_test)
y_pred_train = classifier.predict(X_train)


from sklearn.metrics import classification_report, confusion_matrix, accuracy_score
result = confusion_matrix(y_test, y_pred_test)
print("Confusion Matrix:")
print(result)


result1 = classification_report(y_test, y_pred_test)
print("Classification Report:",)
print (result1)


result2 = accuracy_score(y_test,y_pred_test)
print("Accuracy of test:",result2)


result3 = accuracy_score(y_train,y_pred_train)
print("Accuracy of train:",result3)



Ko’rinib turibdiki, ushbu modelda test aniqligi 88% va train to’plami uchun esa 94% ni tashkil etmoqda.

b) SVM modelini quramiz:


from sklearn.svm import SVC
clf = SVC(kernel='linear')
clf.fit(X_train,y_train)

Endi ushbu model asosida test va train to’plami uchun aniqliklarni topamiz:


y_pred_testSVM = classifier.predict(X_test)
y_pred_trainSVM = classifier.predict(X_train)

resultSVM = confusion_matrix(y_test, y_pred_testSVM)
print("Confusion Matrix:")
print(resultSVM)


result1SVM = classification_report(y_test, y_pred_testSVM)
print("Classification Report:",)
print (result1SVM)


result2SVM = accuracy_score(y_test,y_pred_testSVM)
print("Accuracy of test:",result2SVM)


result3SVM = accuracy_score(y_train,y_pred_trainSVM)
print("Accuracy of train:",result3SVM)


Ushbu modelda ham xuddi KNN singari bir xil natijani oldik.
c) DT modelini quramiz:
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X_train,y_train)

Endi ushbu model asosida test va train to’plami uchun aniqliklarni topamiz:


y_pred_testDT = classifier.predict(X_test)
x_pred_trainDT = classifier.predict(X_train)
resultDT = confusion_matrix(y_test, y_pred_test)
print("Confusion Matrix:")
print(resultDT)


result1DT = classification_report(y_test, y_pred_test)
print("Classification Report:",)
print (result1DT)


result2DT = accuracy_score(y_test,y_pred_test)
print("Accuracy of test:",result2DT)
result3DT = accuracy_score(y_train,y_pred_train)
print("Accuracy of train:",result3DT)

d) RF modelini quramiz:


#RF
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(random_state=1)
clf.fit(X_train,y_train)

Endi ushbu model asosida test va train to’plami uchun aniqliklarni topamiz:


y_pred_test = classifier.predict(X_test)
y_pred_train = classifier.predict(X_train)

result = confusion_matrix(y_test, y_pred_test)
print("Confusion Matrix:")
print(result)


result1 = classification_report(y_test, y_pred_test)
print("Classification Report:",)
print (result1)


result2 = accuracy_score(y_test,y_pred_test)
print("Accuracy of test:",result2)


result3 = accuracy_score(y_train,y_pred_train)
print("Accuracy of train:",result3)


Har bir modelda test va train to’plamlari uchun aniqlik(accuracy) aniqlandi. Test to’plam uchun tartibsizlik matritsalari aniqlandi.

5. Ko’rib chiqilgan har bir model qiyosiy tahlilini amalga oshiramiz.
Test to’plam uchun:
plt.figure(figsize=(6,3))
plt.title('Sinflashtirish algoritmlarning solishtirma grafigi')
plt.bar(['KNN','SVM','Decision Tree','Random Forest'],[88,88,88,88],color='b')
plt.ylabel("Aniqlik")
plt.show()

2-rasm. Test to’plam uchun qurilgan sinflashtirish modellarining qiyosiy tahlili.
Train to’plam uchun:
plt.figure(figsize=(6,3))
plt.title('Sinflashtirish algoritmlarning solishtirma grafigi')
plt.bar(['KNN','SVM','Decision Tree','Random Forest'],[94,94,94,94],color='b')
plt.ylabel("Aniqlik")
plt.show()

3-rasm. Train to’plam uchun qurilgan sinflashtirish modellarining qiyosiy tahlili.
Download 78,96 Kb.

Do'stlaringiz bilan baham:




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish