|
Image Recognition
|
bet | 132/182 | Sana | 19.05.2024 | Hajmi | 5,69 Mb. | | #244351 |
Bog'liq Python sun\'iy intellekt texnologiyasi Dasrlik 20244. Ma’lumotni tayyorlash:
Mashina o‘qitish algoritmlarini ishlatish uchun, ma’lumotlarni tayyorlash zarur. Masalan, VectorAssembler orqali mavjud o‘zgaruvchilarni bir vectorga joylashtirish:
from pyspark.ml.feature import VectorAssembler
feature_cols = ["feature1", "feature2"]
assembler = VectorAssembler(inputCols=feature_cols, outputCol="features")
data = assembler.transform(data).select("features", "label")
5. Mashinali o‘qitish modelini tayyorlash va o‘qitish:
Masofaviy qo‘llanma uchun MLlib kutubxonasidan foydalanish mumkin. Modelni tayyorlash, o‘qitish va baholashni o‘rganamiz:
from pyspark.ml.regression import LinearRegression
from pyspark.ml.evaluation import RegressionEvaluator
# Modelni tayyorlash va o‘qitish
lr = LinearRegression()
model = lr.fit(data)# Modelni baholash
predictions = model.transform(data)
evaluator = RegressionEvaluator(labelCol="label", predictionCol="prediction", metricName="rmse")
rmse = evaluator.evaluate(predictions)
print(f"Root Mean Squared Error (RMSE): {rmse}")
6. Tavsiyalar tizimini integratsiya qilish:
Tavsiyalar tizimini integratsiya qilish uchun PySpark kutubxonasi orqali ishlatiladigan mashhur algoritmalar mavjud. Misol uchun, ALS (Alternating Least Squares) algoritmi, PySpark MLlib dagi tavsiyalar tizimida ishlatiladi.
from pyspark.ml.recommendation import ALS
# ALS modelini tayyorlash va o‘qitish
als = ALS(rank=10, maxIter=5, userCol="userId", itemCol="itemId", ratingCol="rating")
model = als.fit(training_data)
# Foydalanuvchi uchun mahsulotlarni tavsiya qilish
user_recommendations = model.recommendForAllUsers(5)
Bu misol, PySpark orqali mashina o‘qitish algoritmlarini Big Data loyihalari uchun integratsiya qilishni ko‘rsatadi. Sizning maqsadlaringizga qarab, foydalanilayotgan algoritmlar, ma’lumotlar strukturasini va mahsulotlarni tanlash usullarini o‘zgartirishingiz mumkin.
|
| |