Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement ALS-based Computing in spark mllib

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to achieve ALS-based computing in spark mllib, which is very detailed and has a certain reference value. Interested friends must read it!

Run the code as follows / * Collaborative filtering algorithm, based on (alternating least square) ALS calculation * people are divided into groups, birds of a feather flock together. * ALS is the most commonly used approximation algorithm in statistical analysis. * input data set Ratings is a fixed input format of ALS, * Ratings [Int, Int, Double], that is, [user name, item name] Score] * / package spark.collaborativeFilteringimport org.apache.spark.mllib.recommendation. {ALS, Rating} import org.apache.spark. {SparkConf SparkContext} object sparkALS {def main (args: Array [String]) {val conf = new SparkConf (). SetAppName ("ALS"). SetMaster ("local") val sc= new SparkContext (conf) val data = sc.textFile (". / src/main/spark/collaborativeFiltering/ul.txt") val ratings = data.map (_ .split (") match {case Array (user, item, rate) = > Rating (user.toInt, item.toInt) Rate.toDouble) / / convert the dataset to dedicated Rating}) val rank = 2 / / the number of hidden factors in the model val numInterations = 5 / / the number of iterations of the algorithm val model = ALS.train (ratings, rank, numInterations, 0.01) / / Model training val result = model.recommendProducts (2jue 1) / / recommend a commodity result.foreach (println) / / Rating for user 2 (2.713808775549495) Recommend a product numbered 15 for user 2, and the predicted score of 3.97 is close to the actual 4.}} ul.txt1 11 21 12 31 13 13 14 11 11 14 01 15 12 12 12 22 13 22 14 12 15 43 11 23 33 13 13 14 03 15 14 11 13 24 14 14 15 15 11 24 14 14 15 15 11 15 25 13 13 25 25 25 14 14 15 4

These are all the contents of the article "how to implement ALS-based Computing in spark mllib". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report