Kiberxavfsizlik” fakulteti 713-21- guruh cry


Download 55.97 Kb.
Sana15.11.2023
Hajmi55.97 Kb.
#1774062
Bog'liq
SHamsiddin 3





MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

KIBERXAVFSIZLIK” FAKULTETI


713-21- guruh CRY002 - 1 - patok talabasi
XUSHVAQTOV SHAMSIDDINning
Mashinali oqitish kirish” fanidan tayyorlagan

3-AMALIY ISHI

Topshirdi: Xushvaqtov Sh.


Tekshirdi: Ochilov M.


TOSHKENT - 2023

3-amaliy ish.
17-variant


  1. Davlatlarni sinflashtirish 60 3 4

import pandas as pd


import numpy as np

df = pd.read_csv('/content/Shamsiddin.csv')


df.head()

X = df.iloc[:, 1:-2].values
Y = df.iloc[:, -1].values

X
array([[4, '17075', 8.0],


[2, '9976', 3.0],
[4, '9599', 30.0],
[5, '9519.4', 136.0],
[8, '8515.7', 22.0],
[6, '7692', 2.0],
[3, '2780', 14.0],
[4, '2724.9', 5.0],
[4, '2381.7', 16.0],
[3, '2345.4', 13.0],
[1, '2149.7', 15.0],
[2, '1972.5', 53.0],
[4, '1904.5', 13.0],
[5, '1886', 126.0],
[8, '1759.5', 3.0],
[6, '1,648,000', 41.0],
[3, '1,566,6', 24.0],
[4, '1,285,220', 21.0],
[4, '1,284,000', 7.0],
[8, '1,267,000', 9.0],
[6, '1,246,700', 8.0],
[3, '1,240,000', 9.0],
[4, '1,219,912', 36.0],
[4, '1,138,910', 37.0],
[3, '1,127,127', 64.0],
[1, '1,98,580', 8.0],
[2, '1,30,700', 2.0],
[4, '1,1,450', 77.0],
[5, '945.087', 38.0],
[8, '923.768', 139.0],
[6, '912.05', 29.0],
[3, '881.913', 202.0],
[4, '825.418', 2.0],
[4, '801.59', 24.0],
[8, '780.58', 89.0],
[6, '756.95', 21.0],
[3, '752.614', 14.0],
[4, '647.5', 46.0],
[4, '644.329', 46.0],
[3, '644.329', 13.0],
[4, '622.984', 6.0],
[4, '603.7', 78.0],
[8, '600.37', 2.0],
[6, '587.04', 30.0],
[3, '582.65', 58.0],
[4, '527.97', 39.0],
[4, '514', 127.0],
[3, '504.782', 85.0],
[6, '488.1', 10.0],
[3, '475.44', 34.0],
[4, '462.84', 11.0],
[4, '449.964', 20.0],
[3, '448.9', 79.0],
[1, '446.55', 73.0],
[2, '437.072', 59.0],
[4, '406.75', 15.0],
[5, '390.58', 32.0],
[8, '377.835', 337.0],
[6, '357.021', 230.0]], dtype=object)

Y

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, 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, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
[9]
0 сек.

import matplotlib.pyplot as plt

x = X[:,0]
y = X[:,2]

setosa_x = x[:50]


setosa_y = y[:50]

versicolor_x = x[50:100]


versicolor_y = y[50:100]

virginica_x = x[100:]


virginica_y = y[100:]

plt.figure(figsize=(8,6))


plt.xlabel('SepalLengthCm')
plt.ylabel('PetalLengthCm')

plt.scatter(setosa_x,setosa_y,marker='s',color='green',label='Setosa')


plt.scatter(versicolor_x,versicolor_y,marker='o',color='red',label='Versicolor')
plt.scatter(virginica_x,virginica_y,marker='*',color='orange',label='Virginica')
plt.legend()
plt.show()


# 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)

# KNN
from sklearn.neighbors import KNeighborsClassifier

classifier = KNeighborsClassifier(n_neighbors =3)
classifier.fit(X_train, y_train)

y_pred_test = classifier.predict(X_test)

from sklearn.metrics import classification_report, confusion_matrix, accuracy_score

print(classification_report([0,1,0,1,2,0,1,2,0,0], [0,1,1,1,0,0,1,2,0,1]))

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:",result2)

#SVM


from sklearn.svm import SVC

clf = SVC(kernel='linear')

clf.fit(X_train,y_train)

y_pred_test = classifier.predict(X_test)

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:",result2)

# DT
from sklearn.tree import DecisionTreeClassifier


clf = DecisionTreeClassifier()
clf.fit(X_train,y_train)

y_pred_test = classifier.predict(X_test)

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:",result2)

#RF
from sklearn.ensemble import RandomForestClassifier


clf = RandomForestClassifier(random_state=1)
clf.fit(X_train,y_train)

y_pred_test = classifier.predict(X_test)

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:",result2)
plt.figure(figsize=(6,3))
plt.title('Sinflashtirish algoritmlarning solishtirma grafigi')
plt.bar(['KNN','SVM','Decision Tree','Random Forest'],[95,64,100,2],color='r')
plt.ylabel("Aniqlik")
plt.grid()
plt.show()


a=np.array([1,2])
b=np.array([3,2])
a.dot(b)
Download 55.97 Kb.

Do'stlaringiz bilan baham:




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