|
Supervised Learning (O‘qitish bilan bajariladigan o‘qitish)
|
bet | 99/182 | Sana | 19.05.2024 | Hajmi | 5,69 Mb. | | #244351 |
Bog'liq Python sun\'iy intellekt texnologiyasi Dasrlik 2024Supervised Learning (O‘qitish bilan bajariladigan o‘qitish):
Bu usulda, ma’lumotlarning bir qismini o‘qitish uchun ishlatiladi va boshqa qismini sinovdan o‘tkazish uchun. Ushbu usul, “ko‘rib chiqish” (label) ma’lumotlari bo‘yicha sinflarni bilmagan model o‘rganishga mo‘ljallangan.
Ko‘rib chiqish modeli yaratish:
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score# Ma’lumotlarni tayyorlash
X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.2, random_state=42)# Ko‘rib chiqish modelini yaratish va o‘qitish
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X_train, y_train)# Test ma’lumotlarini sinfga o‘tkazish va natijalarni hisoblash
predictions = model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy}")
Unsupervised Learning (O‘qitishsiz o‘qitish):
Bu usulda, ma’lumotlarning sinflari yoki turlari avvaldan bilmagan model orqali o‘rganiladi. Ushbu usul, o‘rganilayotgan modelni o‘z-o‘zidan aniqlash, gruppalar qilish, yoki boshqa maqsadlarga qiziqish uchun foydalaniladi.
K-means tanib olish modeli:
from sklearn.cluster import KMeans # Ma’lumotlarni tayyorlash
X = prepare_data(features)# K-means modelini yaratish va o‘qitish
model = KMeans(n_clusters=3)
model.fit(X)# Har bir obyektni guruhga joylash
labels = model.labels_
Reinforcement Learning (Qayta qo‘llash o‘qitishi):
Bu usulda, model bajarayotgan har bir harakat uchun mukofot yoki jazga olish uchun bir muqobil yondashuvni o‘rganadi. Misol uchun, bir oyinchining o‘yin oynash jarayonida o‘rganish.
Qayta qo‘llash o‘qitish uchun OpenAI Gym:
import gym # O‘yin muhitini yaratish
env = gym.make('CartPole-v1') # Modelni yaratish va o‘rganish
model = create_rl_model()
for episode in range(num_episodes):
state = env.reset()
total_reward = 0
while not done:
action = model.select_action(state)
next_state, reward, done, _ = env.step(action)
total_reward += reward # Modelni qayta qo‘llash uchun ma’lumotni o‘rganish
model.learn(state, action, reward, next_state, done)
state = next_state
print(f"Episode: {episode}, Total Reward: {total_reward}")
Bu misollar avtomatik tanib olish va tasniflashning bir nechta mashhur usullarini o‘z ichiga oladi. Muammoni hal qilish uchun, ma’lumotlar, maqsad va kerakli natijalar bo‘yicha qo‘llaniladigan usulni tanlash kerak.
Avtomatik tanib olish va tasniflash (machine learning) muammolari uchun bir nechta mashinali o‘qitish usullari mavjud. Bu usullar turli turdagi ma’lumotlar bilan ishlash uchun moslashtirilgan. Quyidagi usullar avtomatik tanib olish va tasniflashning asosiy qismidir:
|
| |