Mashinali o‘qitish

O‘ZBEKISTON RESPUBLIKASI
OLIY TA’LIM FAN VA INNOVATSIYALAR VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Kompyuter injiniringi fakulteti
Sun’iy intellekt kafedrasi
Mashinali o‘qitish fanidan
3-TOPSHIRIQ
Mavzu: Mashinali o‘qitishda klassik sinflashtirish algoritmlari va ularni dasturlash
Bajardi: 211-21- guruh talabasi
Dilshod Qo’ldoshev
Tekshirdi: Muminov Elyor
Baho:_____
TOSHKENT 2024
3-AMALIY TOPSHIRIQ
Mashinali o‘qitishda klassik sinflashtirish algoritmlari va ularni dasturlash
Datasetni shakllantirish. Bunda o‘zgaruvchilar soni kamida 10 tani va qatorlar soni 20 tani tashkil etishi lozim.
Quyidagi sinflashtiruvchi modellar orqali shakillantirilgan datasetni sinflashtirish algoritmini va dasturini ishlab chiqish.
KNN (k-Nearest Neighbors)
SVM (Support Vector Machine)
Natijalarni vizual va jadval ko‘rinishda taqdim etish.
import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("oxunjon.csv")
data.head()
data.info()
RangeIndex: 9902 entries, 0 to 9901 Data columns (total 20 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 9902 non-null int64 1 url 9902 non-null object 2 region 9902 non-null object 3 region_url 9902 non-null object 4 price 9902 non-null int64 5 year 9868 non-null float64 6 manufacturer 9902 non-null object 7 model 9902 non-null object 8 fuel 9902 non-null object 9 odometer 9902 non-null int64 10 title_status 9738 non-null object 11 transmission 9902 non-null object 12 image_url 9902 non-null object 13 description 9902 non-null object 14 state 9902 non-null object 15 lat 9902 non-null float64 16 long 9902 non-null float64 17 posting_date 9902 non-null object 18 price_category 9902 non-null object 19 date 9902 non-null object dtypes: float64(3), int64(3), object(14) memory usage: 1.5+ MB
data.describe()
# Sinov qismi bo'yicha fakt va aniqlik
test_accuracy = [0.85, 0.88, 0.82, 0.87] # Misol uchun aniqliklar
training_accuracy = [0.95, 0.92, 0.96, 0.93] # Misol uchun egalliklar
cities = ['City 1', 'City 2', 'City 3', 'City 4'] # Shahar nomlari
# Grafikni yaratish
plt.figure(figsize=(10, 6))
plt.plot(cities, test_accuracy, marker='o', label='Test Accuracy')
plt.plot(cities, training_accuracy, marker='x', label='Training Accuracy')
# X va Y o'qlarini nomlash
plt.xlabel('Cities')
plt.ylabel('Accuracy')
# Grafik sarlavhasi
plt.title('Accuracy by Cities')
# Qo'shimcha elementlar
plt.legend()
# Grafikni chiqarish
plt.grid(True)
plt.xticks(rotation=45) # X o'qi qaytarish
plt.tight_layout() # Xo'lakni to'g'ri chiqarish
plt.show()
LOGISTIK REGRESSION
X, y = make_classification(n_samples=20, n_features=10, n_classes=2, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
knn_model = KNeighborsClassifier()
knn_model.fit(X_train_scaled, y_train)
knn_predictions = knn_model.predict(X_test_scaled)
knn_accuracy = accuracy_score(y_test, knn_predictions)
print("KNN modelining aniqligi:", knn_accuracy)
Knn modelining aniqligi 0,5
svm_model = SVC(kernel='linear', random_state=42)
svm_model.fit(X_train_scaled, y_train)
svm_predictions = svm_model.predict(X_test_scaled)
svm_accuracy = accuracy_score(y_test, svm_predictions)
print("SVM modelining aniqligi:", svm_accuracy)
SVM modelining aniqligi 0,75
|