• 大小:
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-24
  • 语言: 其他
  • 标签: 高清  源码    

资源简介

spark 机器学习 第二版 含源码 高清版本

资源截图

代码片段和文件信息

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Tuple2;
import java.util.*;
import java.util.stream.Collectors;

/**
 * A simple Spark app in Java (Wordcount example)
 */
public class JavaApp {

    public static void main(String[] args) {
        JavaSparkContext sc = null;

        try {
//           ####### create spark context by starting the cluster locally using 2 CPU cores #######
            sc = new JavaSparkContext(“local[2]“ “First Spark App“);

            JavaRDD data = sc.textFile(“data/UserPurchaseHistory.csv“).map(s -> s.split(““));

//           ####### let‘s count the number of purchases #######
            long numPurchases = data.count();

            System.out.println(“NumberPurchases : “ + numPurchases);

            long uniqueUsers = data.map(strings -> strings[0]).distinct().count();

//           ####### let‘s count the number of users #######
            System.out.println(“Unique users : “ + uniqueUsers);

            Double totalRevenue = data.map(strings -> Double.parseDouble(strings[2])).reduce((Double v1 Double v2) -> new Double(v1.doubleValue() + v2.doubleValue()));

//           ####### let‘s count the total revenue #######
            System.out.println(“Total revenue : “ + totalRevenue);

            List> pairs = data.mapToPair(strings -> new Tuple2(strings[1] 1)).reduceByKey((Integer i1 Integer i2) -> i1 + i2).collect();

            Map sortedData = new HashMap<>();
            Iterator it = pairs.iterator();
            while (it.hasNext()) {
                Tuple2 o = (Tuple2) it.next();
                sortedData.put(o._1() o._2());
            }
            List sorted = sortedData.entrySet()
                    .stream()
                    .sorted(Comparator.comparing((Map.Entry entry) -> entry.getValue()).reversed())
                    .map(Map.Entry::getKey)
                    .collect(Collectors.toList());
            System.out.println(“Most popular products sorted : “ + sorted);


            String mostPopular = sorted.get(0);
            int purchases = sortedData.get(mostPopular);
            System.out.println(“Most popular product is : “ + mostPopular + “ with number of purchases : “ + purchases);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sc.stop();
        }


    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      29494  2016-11-14 11:18  Graphic 图\B05184_08_01.png

     文件      29503  2016-11-13 06:47  Graphic 图\B05184_08_02.png

     文件      29517  2016-11-14 11:18  Graphic 图\B05184_08_03.png

     文件      29519  2016-11-13 06:48  Graphic 图\B05184_08_04.png

     文件      29475  2016-11-14 11:18  Graphic 图\B05184_08_05.png

     文件      19647  2016-11-14 11:18  Graphic 图\B05184_08_06.png

    .......       378  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\.gitattributes

    .......       649  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\.gitignore

    .......       251  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\java-spark-app\data\UserPurchaseHistory.csv

    .......      1060  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\java-spark-app\pom.xml

    .......      2513  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\java-spark-app\src\main\java\JavaApp.java

    .......       117  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\python-spark-app\data\UserPurchaseHistory.csv

    .......      1405  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\python-spark-app\pythonapp.py

    .......       117  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\r-spark-app\data\UserPurchaseHistory.csv

    .......      1767  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\r-spark-app\r-script-01.R

    .......       537  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\README

    .......      5120  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\scala-shell-code_01.scala

    .......       144  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\scala-spark-app\build.sbt

    .......       117  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\scala-spark-app\data\UserPurchaseHistory.csv

    .......      1426  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter01\scala-spark-app\src\main\scala\ScalaApp.scala

    .......      1093  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\build.sbt

    .......       882  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\fields\ComplexNumber.scala

    .......       285  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\fields\GaloisField.scala

    .......       579  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\fields\GF2.scala

    .......       501  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\matrix\BreezeMatrix.scala

    .......       909  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\matrix\BreezeMatrixOperations.scala

    .......      1607  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\operations\common.scala

    .......       362  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\plot\BreezePlotGaussian.scala

    .......       413  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\plot\BreezePlotLine.scala

    .......       633  2017-04-28 19:15  Machine-Learning-with-Spark-Second-Edition-master 源码\Chapter02\breeze\src\main\scala\linalg\sgd\BreezeSGDVector.scala

............此处省略1092个文件信息

评论

共有 条评论