<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                向量標簽是一個本地向量,就是在密集向量,或者稀疏向量的基礎上,添加一個標簽。 <br/> <mark>標簽向量用于監督學習中</mark>,使用 double 存儲一個標簽,所以標簽數據可以用于回歸,或者分類。對于二分類,一個標簽應該要么是 0 要么是 1。對于多分類,標簽應該是從零開始的索引:`0,1,2,3,4`。 <br/> **1. 通過Scala數據類型創建向量標簽** ```scala import org.apache.spark.mllib.regression.LabeledPoint import org.apache.spark.mllib.linalg.Vectors object LabelVector { def main(args: Array[String]): Unit = { // 創建一個密集向量,向量標簽為1.0 // case class LabeledPoint(val label : scala.Double, val features : org.apache.spark.mllib.linalg.Vector) val pos: LabeledPoint = LabeledPoint(1.0, Vectors.dense(1.0, 0.0, 3.0)) println(pos) // (1.0,[1.0,0.0,3.0]) // 創建一個稀疏向量,向量標簽為0.0 val neg = LabeledPoint(0.0, Vectors.sparse(3, Array(0, 2), Array(1.0, 3.0))) println(neg) // (0.0,(3,[0,2],[1.0,3.0])) println(neg.label) // 0.0 println(neg.features) // (3,[0,2],[1.0,3.0]) } } ``` <br/> **2. 通過libsvm格式數據創建向量標簽** 在實際生產中訓練數據是稀疏數據很常見。Mllib 支持以 libsvm 格式存儲的稀疏矩陣,這是一個 `.txt` 格式文件,其中<mark>每一行代表一個打標簽的稀疏特征向量</mark>,格式如下: ```txt label index1:value1 index2:value2 ... ``` 其中,索引是從 1 開始的,遞增的順序。加載之后,特征索引就轉化為了從0 開始的。 <br/> (1)數據`sample_libsvm_data.txt` ```scala 0 128:51 129:159 130:253 131:159 ... 1 159:124 160:253 161:255 162:63 ... ... ``` (2)讀取`.txt`文件創建向量標簽 ```scala import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.mllib.regression.LabeledPoint import org.apache.spark.mllib.util.MLUtils import org.apache.spark.rdd.RDD object LabelVectorLibSvm { def main(args: Array[String]): Unit = { val conf: SparkConf = new SparkConf().setMaster("local[*]") .setAppName(this.getClass.getName) val sc = SparkContext.getOrCreate(conf) // def loadLibSVMFile(sc : org.apache.spark.SparkContext, path : scala.Predef.String // , numFeatures : scala.Int, minPartitions : scala.Int) val examples: RDD[LabeledPoint] = MLUtils.loadLibSVMFile(sc, "F:/mlib/sample_libsvm_data.txt") examples.foreach(println) // (0.0,(692,[127,128,129,130,...], [51.0,159.0,253.0,159.0,...])) // (1.0,(692,[158,159,160,161,...], [124.0,253.0,255.0,63.0,...])) } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看