Uploaded by sattarovmuhammadqodir9278

Yesbolov Bekgazi

advertisement
Muhammad Al-Xorazmiy nomidagi
TATU Nurafshon filiali 710-21
guruh
talabasi Yesbolov Bekgazining Mashinali
o’qitish fanidan bajargan
Amaliy ishi.
Bajardi : Yesbolov B.
Tekshirdi : Qobilov S.
1)Bu vazifani bajarish uchun quyidagi kodni Python da ishlatishingiz mumkin.
import numpy as np
import pandas as pd
np.random.seed(42)
# O'zgaruvchilar soni va qatorlar soni
n_features = 10
n_samples = 20
# Random dataset yaratish
X = np.random.rand(n_samples, n_features)
y = np.random.randint(0, 2, n_samples)
# Datasetni DataFrame ga aylantirish
df = pd.DataFrame(X, columns=[f'Feature_{i}' for i in range(1, n_features+1)])
df['Target'] = y
1) Logistik regressiya modelini tuzish uchun:
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix
import matplotlib.pyplot as plt
import seaborn as sns
# O'zgaruvchilar va ma'lumotlar bo'linishi
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Logistik regressiya modelini tuzish
model = LogisticRegression()
model.fit(X_train, y_train)
# Test ma'lumotlari bo'yicha baho hisoblash
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
# Confusion matrix
conf_matrix = confusion_matrix(y_test, y_pred)
# Natijalarni vizual ko'rish
plt.figure(figsize=(8, 6))
sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', xticklabels=['Class 0', 'Class 1'],
yticklabels=['Class 0', 'Class 1'])
plt.title('Confusion Matrix')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()
# Natijalarni ekranga chiqarish
print(f'Accuracy: {accuracy:.2f}')
Bu kodlar bilan, dataset yaratiladi, logistik regressiya modeli tuzildi, natijalar vizual va jadval ko'rinishida
ko'rsatildi.
Download