• Spark ML之高级数据源


    一.图像数据源

    图像数据源用于从目录加载图像文件,它可以通过ImageIO Java库将压缩图像(jpeg,png等)加载为原始图像表示形式加载的DataFrame具有一StructType列:“ image”,其中包含存储为图像架构的图像数据。image的架构为:

    • origin :(StringType代表图像的文件路径)
    • height:(IntegerType图像的高度)
    • width:(IntegerType图像的宽度)
    • nChannels :(IntegerType图像通道数)
    • mode:(IntegerType兼容OpenCV的类型)
    • data:(BinaryType以OpenCV兼容顺序的图像字节:大多数情况下按行BGR)

    代码实现:

        val image_df = spark.read.format("image").option("dropInvalid", true)
          .load("D:\software\spark-2.4.4\data\mllib\images\origin\kittens")
    
        image_df.schema.printTreeString()
    
        image_df.select("image.origin", "image.width", "image.height")
          .show(true)

    执行结果:

     

     二.LIBSVM数据源

    LIBSVM数据源用于从目录加载“ libsvm”类型的文件。加载的DataFrame有两列:包含以double形式存储的标签编号和包含以Vectors存储的特征向量的特征。列的模式为:

    • label:(DoubleType代表实例标签)
    • features :(VectorUDT代表特征向量)

    代码实现:

        val libsvm_df = spark.read.format("libsvm").option("numFeatures", "780")
          .load("D:\software\spark-2.4.4\data\mllib\sample_libsvm_data.txt")
    
        libsvm_df.show(10)

    执行结果:

  • 相关阅读:
    terminal
    变量提升、函数提升
    ssh传输文件
    mocha测试框架
    npm-run 自动化
    webpack
    浅析babel
    构建工具gulp
    C++中TRACE宏及assert()函数的使用
    memcpy函数-C语言
  • 原文地址:https://www.cnblogs.com/yszd/p/13628355.html
Copyright © 2020-2023  润新知