Ilova funksionalligini takomillashtirish uchun mashinali o‘qitishdan foydalanishning amaliy misollari




Download 5,69 Mb.
bet31/182
Sana19.05.2024
Hajmi5,69 Mb.
#244351
1   ...   27   28   29   30   31   32   33   34   ...   182
Bog'liq
Python sun\'iy intellekt texnologiyasi Dasrlik 2024

2.3. Ilova funksionalligini takomillashtirish uchun mashinali o‘qitishdan foydalanishning amaliy misollari


Python-da kod namunalari bilan dasturlarning ishlashini yaxshilash uchun mashinali o‘qitishdan foydalanishning ba’zi misollari:
Tabiiy tilni qayta ishlash (NLP) yordamida avtomatik matnni aniqlash:
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
# Ta’lim ma’lumotlariga misol
training_data = [("Bu yaxshi mahsulot", " ijobiy "),
("Ushbu mahsulot yoqmadi", " salbiy "),
("Men bu xizmatdan xursandman", " ijobiy ")]
# Tonallikni tahlil qilish uchun Mashinali o‘qitish modelini yaratish
model = make_pipeline(TfidfVectorizer(), MultinomialNB())
model.fit([data[0] for data in training_data], [data[1] for data in training_data])
# Matn ohangini tahlil qilish uchun modeldan foydalanish
text_to_analyze = " Ushbu mahsulot mening kutganimdan oshib ketdi!"
sentiment = model.predict([text_to_analyze])[0]
print(f" Matnning tonalligi: {sentiment}")
TensorFlow kutubxonasi yordamida tasvirlardagi ob’ektlarni tanib olish:
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.inception_v3 import InceptionV3
from tensorflow.keras.applications.inception_v3 import preprocess_input, decode_predictions
# Oldindan tayyorlangan Inception v3 modelini yuklab olish
model = InceptionV3(weights='imagenet’)
# Rasmni yuklash va qayta ishlash
img_path = 'path/to/your/image.jpg’
img = image.load_img(img_path, target_size=(299, 299))
x = image.img_to_array(img)
x = preprocess_input(x)
x = tf.expand_dims(x, axis=0)
# Rasmdagi ob’ektlarni bashorat qilish
predictions = model.predict(x)
decoded_predictions = decode_predictions(predictions, top=3)[0]
# Natijalarni chiqarish
for i, (imagenet_id, label, score) in enumerate(decoded_predictions):
print(f"{i + 1}: {label} ({score:.2f})")

Download 5,69 Mb.
1   ...   27   28   29   30   31   32   33   34   ...   182




Download 5,69 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Ilova funksionalligini takomillashtirish uchun mashinali o‘qitishdan foydalanishning amaliy misollari

Download 5,69 Mb.