在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

eclipse中如何运行spark机器学习代码

117次阅读
没有评论

共计 6134 个字符,预计需要花费 16 分钟才能阅读完成。

这篇文章主要介绍 eclipse 中如何运行 spark 机器学习代码,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

直接在 eclipse 运行,不需要 hadoop,不需要搭建 spark,只需要 pom.xml 中的依赖完整

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.mllib.classification.LogisticRegressionWithSGD
import org.apache.spark.mllib.feature.HashingTF
import org.apache.spark.mllib.regression.LabeledPoint
object MLlib { def main(args: Array[String]) { val conf = new SparkConf().setAppName(s Book example: Scala).setMaster(local[2] )
 val sc = new SparkContext(conf)
 // Load 2 types of emails from text files: spam and ham (non-spam).
 // Each line has text from one email.
 val spam = sc.textFile(file:/Users/xxx/Documents/hadoopTools/scala/eclipse/Eclipse.app/Contents/MacOS/workspace/spark_ml/src/main/resources/files/spam.txt)
 val ham = sc.textFile(file:/Users/xxx/Documents/hadoopTools/scala/eclipse/Eclipse.app/Contents/MacOS/workspace/spark_ml/src/main/resources/files/ham.txt)
 // val abc=sc.parallelize(seq, 2)
 // Create a HashingTF instance to map email text to vectors of 100 features.
 val tf = new HashingTF(numFeatures = 100)
 // Each email is split into words, and each word is mapped to one feature.
 val spamFeatures = spam.map(email =  tf.transform(email.split(  )))
 val hamFeatures = ham.map(email =  tf.transform(email.split(  )))
 // Create LabeledPoint datasets for positive (spam) and negative (ham) examples.
 val positiveExamples = spamFeatures.map(features =  LabeledPoint(1, features))
 val negativeExamples = hamFeatures.map(features =  LabeledPoint(0, features))
 val trainingData = positiveExamples ++ negativeExamples
 trainingData.cache() // Cache data since Logistic Regression is an iterative algorithm.
 // Create a Logistic Regression learner which uses the LBFGS optimizer.
 val lrLearner = new LogisticRegressionWithSGD()
 // Run the actual learning algorithm on the training data.
 val model = lrLearner.run(trainingData)
 // Test on a positive example (spam) and a negative one (ham).
 // First apply the same HashingTF feature transformation used on the training data.
 val posTestExample = tf.transform(O M G GET cheap stuff by sending money to ... .split(  ))
 val negTestExample = tf.transform(Hi Dad, I started studying Spark the other ... .split(  ))
 // Now use the learned model to predict spam/ham for new emails.
 println(s Prediction for positive test example: ${model.predict(posTestExample)} )
 println(s Prediction for negative test example: ${model.predict(negTestExample)} )
 sc.stop()
 }
}

 sc.textFile 里的参数是文件在本地的绝对路径。

 setMaster(local[2] ) 表示是本地运行,只使用两个核

 HashingTF 用来从文档中创建词条目的频率特征向量,这里设置维度为 100.

TF-IDF(Term frequency-inverse document frequency )  是文本挖掘中一种广泛使用的特征向量化方法。TF-IDF 反映了语料中单词对文档的重要程度。假设单词用 t 表示,文档用 d 表示,语料用 D 表示,那么文档频度 DF(t, D)是包含单词 t 的文档数。如果我们只是使用词频度量重要性,就会很容易过分强调重负次数多但携带信息少的单词,例如:”a”,“the”以及”of”。如果某个单词在整个语料库中高频出现,意味着它没有携带专门针对某特殊文档的信息。逆文档频度 (IDF) 是单词携带信息量的数值度量。

pom.xml

project xmlns= http://maven.apache.org/POM/4.0.0  xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance 
 xsi:schemaLocation= http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd 
 modelVersion 4.0.0 /modelVersion 
 groupId com.yanan.spark_maven /groupId 
 artifactId spark1.3.1 /artifactId 
 version 0.0.1-SNAPSHOT /version 
 packaging jar /packaging 
 name spark_maven /name 
 url http://maven.apache.org /url 
 properties 
 project.build.sourceEncoding UTF-8 /project.build.sourceEncoding 
 jackson.version 1.9.13 /jackson.version 
 /properties 
 dependencies 
 dependency 
 groupId junit /groupId 
 artifactId junit /artifactId 
 version 3.8.1 /version 
 scope test /scope 
 /dependency 
 dependency 
 groupId org.scala-lang /groupId 
 artifactId scala-library /artifactId 
 version 2.10.4 /version 
 /dependency 
 dependency 
 groupId org.apache.spark /groupId 
 artifactId spark-core_2.10 /artifactId 
 version 1.3.1 /version 
 /dependency 
 !-- dependency   groupId org.apache.spark /groupId   artifactId spark-sql_2.10 /artifactId  
 version 1.3.1 /version   /dependency   dependency   groupId org.apache.spark /groupId  
 artifactId spark-hive_2.10 /artifactId   version 1.3.1 /version   /dependency  
 dependency   groupId org.apache.spark /groupId   artifactId spark-bagel_2.10 /artifactId  
 version 1.3.1 /version   /dependency 
   dependency 
 groupId org.apache.spark /groupId 
 artifactId spark-graphx_2.10 /artifactId 
 version 1.3.1 /version 
 /dependency  -- 
 dependency 
 groupId org.apache.spark /groupId 
 artifactId spark-mllib_2.10 /artifactId 
 version 1.3.1 /version 
 /dependency 
 !-- specify the version for json_truple  dependency   groupId org.codehaus.jackson /groupId  
 artifactId jackson-core-asl /artifactId   version ${jackson.version} /version  
 /dependency   dependency   groupId org.codehaus.jackson /groupId   artifactId jackson-mapper-asl /artifactId  
 version ${jackson.version} /version   /dependency  -- 
 /dependencies 

name Scala-tools Maven2 Repository /name url http://scala-tools.org/repo-releases /url /pluginRepository /pluginRepositories repositories repository id cloudera-repo-releases /id url https://repository.cloudera.com/artifactory/repo/ /url /repository /repositories /project

ham.txt

Dear Spark Learner, Thanks so much for attending the Spark Summit 2014! Check out videos of talks from the summit at ...
Hi Mom, Apologies for being late about emailing and forgetting to send you the package. I hope you and bro have been ...
Wow, hey Fred, just heard about the Spark petabyte sort. I think we need to take time to try it out immediately ...
Hi Spark user list, This is my first question to this list, so thanks in advance for your help! I tried running ...
Thanks Tom for your email. I need to refer you to Alice for this one. I haven t yet figured out that part either ...
Good job yesterday! I was attending your talk, and really enjoyed it. I want to try out GraphX ...
Summit demo got whoops from audience! Had to let you know. --Joe

spam.txt

Dear sir, I am a Prince in a far kingdom you have not heard of. I want to send you money via wire transfer so please ...
Get Vi_agra real cheap! Send money right away to ...
Oh my gosh you can be really strong too with these drugs found in the rainforest. Get them cheap right now ...
YOUR COMPUTER HAS BEEN INFECTED! YOU MUST RESET YOUR PASSWORD. Reply to this email with your password and SSN ...
THIS IS NOT A SCAM! Send money and get access to awesome stuff really cheap and never have to ...
Vi_agra  本来是去掉下划线的

以上是“eclipse 中如何运行 spark 机器学习代码”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-17发表,共计6134字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 无遮挡又黄又爽又色的视频免费 | 久久综合久久综合九色 | 人妻中文字幕无码专区 | 福利片福利一区二区三区 | 久久精品视频99精品视频150 | 免费视频精品一区二区三区 | 在线观看视频欧美 | 精品成人资源在线观看 | 亚洲一区av无码少妇电影 | 中文亚洲欧美 | 在线看一级片 | 在线视频黄色 | 乌克兰少妇xxxx做受野外 | 丰满人妻熟妇乱又伦精品 | 少妇真实被内射视频三四区 | 日本亚洲视频 | 亚洲中文字幕无码天然素人在线 | 乱人伦人妻精品一区二区 | 国产精品免费视频播放 | 久久无码av三级 | 午夜性色福利在线视频福利 | 福利在线免费 | 亚洲国产一区二区三区精品 | 日日日日人人人夜夜夜2017 | 国产又爽又黄又舒服又刺激视频 | 高清性欧美 | 18禁无遮挡啪啪无码网站 | 国产成人偷拍 | 清纯唯美一二区jk | 超激情碰碰碰啪在线视频 | 午夜影院黄色 | 色福利视频 | 久久老子午夜精品无码怎么打 | 免费人成再在线观看网站 | 全部在线播放免费毛片 | 又爽又黄禁片视频1000免费 | 久久精品国产99国产精品 | 两个人日本在线观看视频 | 女人下边被添全过视频的网址 | 男人靠女人免费视频网站 | 国产成人av一区二区三区在线 |