欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

eclipse中如何運(yùn)行spark機(jī)器學(xué)習(xí)代碼

這篇文章主要介紹eclipse中如何運(yùn)行spark機(jī)器學(xué)習(xí)代碼,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)主營(yíng)欽南網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,欽南h5重慶小程序開發(fā)搭建,欽南網(wǎng)站營(yíng)銷推廣歡迎欽南等地區(qū)企業(yè)咨詢

直接在eclipse運(yùn)行,不需要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里的參數(shù)是文件在本地的絕對(duì)路徑。

 setMaster("local[2]") 表示是本地運(yùn)行,只使用兩個(gè)核

 HashingTF 用來(lái)從文檔中創(chuàng)建詞條目的頻率特征向量,這里設(shè)置維度為100.

TF-IDF(Term frequency-inverse document frequency ) 是文本挖掘中一種廣泛使用的特征向量化方法。TF-IDF反映了語(yǔ)料中單詞對(duì)文檔的重要程度。假設(shè)單詞用t表示,文檔用d表示,語(yǔ)料用D表示,那么文檔頻度DF(t, D)是包含單詞t的文檔數(shù)。如果我們只是使用詞頻度量重要性,就會(huì)很容易過(guò)分強(qiáng)調(diào)重負(fù)次數(shù)多但攜帶信息少的單詞,例如:”a”, “the”以及”of”。如果某個(gè)單詞在整個(gè)語(yǔ)料庫(kù)中高頻出現(xiàn),意味著它沒(méi)有攜帶專門針對(duì)某特殊文檔的信息。逆文檔頻度(IDF)是單詞攜帶信息量的數(shù)值度量。

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>


	<build>
		<plugins>
			<plugin>
				<groupId>org.scala-tools</groupId>
				<artifactId>maven-scala-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>compile</goal>
							<goal>testCompile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	<pluginRepositories>
		<pluginRepository>
			<id>scala-tools.org</id>
			<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 本來(lái)是去掉下劃線的

eclipse中如何運(yùn)行spark機(jī)器學(xué)習(xí)代碼

以上是“eclipse中如何運(yùn)行spark機(jī)器學(xué)習(xí)代碼”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

名稱欄目:eclipse中如何運(yùn)行spark機(jī)器學(xué)習(xí)代碼
本文鏈接:http://aaarwkj.com/article30/jeigso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司做網(wǎng)站、商城網(wǎng)站定制網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
亚洲天堂国产中文在线| 午夜福利日本一区二区| 国产男女免费视频观看| 国产婷婷精品一区二区| 亚洲成在人线免费观看| 狠狠久久五月综合色和啪| 91午夜精品在线观看| 麻豆人妻性色av专区| 熟女人妻av五十路六十路| 日韩av天堂免费网站| 日本高清av一区二区| 99精品国产综合久久麻豆| 女人高潮被爽到呻吟在线| 不卡视频在线免费观看| 亚洲第一区二区国产精品| 国产成人精品视频午夜蜜蜂| 天堂av在线网址观看| 91九色在线精品一区| 久久伊人69日韩精品| 国产免费av剧情演绎| 日本一区二区三区视频版| 精品一区二区人妻乱交| 国产女片xb内射在线| 熟女自拍偷拍视频播放| 日本丰满熟女毛茸茸的黑逼| 蜜桃在线视频在线观看| 九九热精品视频美谷朱里| 丰满熟妇久久人妻同堂av| 久久综合中文字幕一区| 久久综合热这里只有精品| 国产av午夜精品福利| 亚洲av成人精品日韩一区麻豆 | 国产av剧情日韩精品| 国产黄a三级三级三级老师绑| 91精品亚洲内射孕妇| 亚洲日本韩国一区二区| 国产在线不卡免费精品| 精品三级一区二区三区| 91久久福利国产成人精品| 日本人妻精品一区二区| 色哟哟网站一区二区精品久久 |