Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
spark:spark-introduction [2014/11/11 09:06] straka |
spark:spark-introduction [2014/11/11 09:13] straka |
||
---|---|---|---|
Line 25: | Line 25: | ||
The central object of Spark framework is RDD -- resilient distributed dataset. It contains ordered sequence of items, which may be distributed in several threads or on several computers. Spark offers multiple operations which can be performed on RDD, like '' | The central object of Spark framework is RDD -- resilient distributed dataset. It contains ordered sequence of items, which may be distributed in several threads or on several computers. Spark offers multiple operations which can be performed on RDD, like '' | ||
- | We start by simple word count example. We load the RDD from text file, every line of the input file becoming an element of RDD. We then split every line into words, count every word occurrence and sort the words by the occurrences. | + | We start by simple word count example. We load the RDD from text file, every line of the input file becoming an element of RDD. We then split every line into words, count every word occurrence and sort the words by the occurrences. |
<file python> | <file python> | ||
wiki = sc.textFile("/ | wiki = sc.textFile("/ | ||
Line 63: | Line 63: | ||
===== K-Means Example ===== | ===== K-Means Example ===== | ||
- | An example implementing [[http:// | + | An example implementing [[http:// |
<file python> | <file python> | ||
import numpy as np | import numpy as np | ||
Line 71: | Line 71: | ||
lines = sc.textFile("/ | lines = sc.textFile("/ | ||
- | data = lines.map(lambda line: map(float, line.split())).cache() | + | data = lines.map(lambda line: np.array(map(float, line.split()))).cache() |
K = 50 | K = 50 | ||
Line 97: | Line 97: | ||
print "Final centers: " + str(centers) | print "Final centers: " + str(centers) | ||
</ | </ | ||
- | The implementation starts by loading the data and caching them in memory using '' | + | The implementation starts by loading the data points |
Note that explicit broadcasting used for '' | Note that explicit broadcasting used for '' |