Bajardi: Ziyodullayeva Dilnoza




Download 244,88 Kb.
Sana09.07.2024
Hajmi244,88 Kb.
#267253
Bog'liq
1701530542 (1)


O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI


MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI







5-Amaliy topshiriq.




Guruh: 715_21

Bajardi:Ziyodullayeva Dilnoza


Tekshirdi: Ochilov Mannon
Toshkent 2023
21-variant
https://colab.research.google.com/drive/1g3fIxTN11_SIkv0QJoRdWKxNmC6fEjle#scrollTo=TKz5s2THgCEX

21

Yer maydonlarini sinflashtirish(ekin ekiladigan)

40

2

4

import numpy as np


dataset=np.array([
[4,5,1,2,0], # maqola soni, tezis soni, monografiya, qo'llanma soni, sinfi
[4,6,5,2,0],
[6,8,3,0,1],
[14,5,1,2,0],
[4,6,5,2,0],
[24,5,1,2,0],
[4,6,5,2,1],
[6,8,3,0,1],
[6,8,3,0,1],
[5.6,2.1,2.0,1,1]
])
num_examples = 40
num_classes = 2
num_features = 4
X = np.random.rand(num_examples, num_features) # Your feature data
y = np.random.randint(0, num_classes, size=num_examples) # Your target labels
import matplotlib.pyplot as plt
feature1 = 0
feature2 = 1
plt.scatter(X[y == 0, feature1], X[y == 0, feature2], label='Class 1', marker='o')
plt.scatter(X[y == 1, feature1], X[y == 1, feature2], label='Class 2', marker='x')
plt.xlabel(f'Feature {feature1}')
plt.ylabel(f'Feature {feature2}')
plt.legend()
plt.show()

# Modelni qurish uchun datasetni train va test qismlarga ajratish
X_train= dataset[:,:-1] #barcha xususiyatlar
Y_train=dataset[:,-1] #sinf
X_train
Y_train
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X_train, Y_train, test_size=0.15, random_state=42)
x_train.shape
x_test.shape
from sklearn.linear_model import LogisticRegression
logisticRegr = LogisticRegression()
logisticRegr.fit(x_train, y_train)
train_accuracy = logisticRegr.score(x_train,y_train)
test_accuracy = logisticRegr.score(x_test,y_test)
#train to'plam uchun
score = logisticRegr.score(x_train, y_train)
print(score)
test_pred = logisticRegr.predict(x_test)
train_pred = logisticRegr.predict(x_train)
#test to'plam uchun
score = logisticRegr.score(x_test, y_test)
print(score)
from sklearn.metrics import confusion_matrix
import seaborn as sns
y_pred = logisticRegr.predict(x_test)
cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(8, 6))
sns.heatmap(cm, annot=True, fmt='d', cmap='Reds')
plt.xlabel('Predicted')
plt.ylabel('True')
plt.show()

#train to'plam uchun
cm = confusion_matrix(y_train, train_pred)
print(cm)
#test to'plam uchun
cm = confusion_matrix(y_test, test_pred)
print(cm)
#datasetda yo'q misol bilan testlash
logisticRegr.predict([[4.7,6,3,0]])[0]
Download 244,88 Kb.




Download 244,88 Kb.