import org.apache.spark.ml.classification.MultilayerPerceptronClassifier
import org.apache.spark.ml.evaluation.MulticlassClassificationEvaluator
import org.apache.spark.mllib.util.MLUtils
import org.apache.spark.sql.Row
// Load training data
val data = MLUtils.loadLibSVMFile(sc,"data/mllib/sample_multiclass_classification_data.txt").toDF()
// Split the data into train and test
val splits = data.randomSplit(Array(0.6, 0.4), seed = 1234L)
val train = splits(0)
val test = splits(1)
// specify layers for the neural network:
// input layer of size 4 (features), two intermediate of size 5 and 4 and output of size 3 (classes)
val layers = Array[Int](4, 5, 4, 3)
// create the trainer and set its parameters
val trainer = new MultilayerPerceptronClassifier()
.setLayers(layers)
.setBlockSize(128)
.setSeed(1234L)
.setMaxIter(100)
// train the model
val model = trainer.fit(train)
// compute precision on the test set
val result = model.transform(test)
val predictionAndLabels = result.select("prediction", "label")
val evaluator = new MulticlassClassificationEvaluator().setMetricName("precision")
println("Precision:" + evaluator.evaluate(predictionAndLabels))
我有这个示例代码。输入文件" data / mllib / sample_multiclass_classification_data.txt"采用以下格式:
1 1:-0.222222 2:0.5 3:-0.762712 4:-0.833333
1 1:-0.555556 2:0.25 3:-0.864407 4:-0.916667
1 1:-0.722222 2:-0.166667 3:-0.864407 4:-0.833333
1 1:-0.722222 2:0.166667 3:-0.694915 4:-0.916667
我的输入文件(CSV):
Help me with my Account Balance, Balance
Want to know my Balance, Balance
What is the available Balance in my Account, Balance
Balance in Account, Balance
Available bank Balance, Balance
Help me with my Account Balance, Balance
Want to know my Balance, Balance
What is the available Balance in my Account, Balance
Balance in Account, Balance
我的输出如下:
key Balance - 0.0036513722,7.4863195E-4,0.0026168288,0.0018019283,3.6993028E-5,0.0015877665,-0.0023806596,-0.0044850614,0.0030128842,-0.0027919186,0.0029404194,0.001331976,-0.00244722,-0.0022837287,0.0033935083,-1.0614514E-4,0.004019062,0.0018543076,6.72285E-4,0.0019381851,0.0018775725,-0.0029566616,0.0039101024,0.0016479599,0.0023191334,0.0032120477,5.984378E-4,-4.9780607E-5,-4.5533956E-4,0.0019212944,-0.0014106851,0.0037013923,0.0043562353,8.073688E-4,0.004751688,0.0021792704,-5.208015E-4,-0.0033827745,-5.3768157E-4,0.0044863885,-0.0031513213,0.0023239064,0.0035973901,-0.0047605466,-0.0040854285,-0.0045714066,-0.001879341,0.0042538918,-0.004887264,0.0026716448,0.004494503,-3.7978767E-4,-0.0023598725,0.0047358125,-7.927376E-4,-0.0028520639,0.0019070529,1.3333082E-4,0.0016852015,0.0028981792,0.0042936187,-0.0010523892,0.0043657385,0.0028728675,0.0024622548,-0.0021084119,0.0022188448,-7.240367E-4,-0.004585674,-0.0032908982,-0.002840305,0.0017878491,0.0047972207,0.0012684285,-4.1861474E-4,0.0021237314,-0.0030996585,3.7243307E-4,0.004151346,0.0025370778,-0.0022359376,1.0996461E-5,0.0026262754,5.540156E-4,-0.0041488777,-0.0024115837,0.0017715782,-0.0032798958,4.7829092E-4,6.21534E-4,0.003895337,0.004436586,0.0029779458,-0.0015637607,6.298947E-4,0.0029944445,-2.794385E-4,-0.004432401,0.0034545213,0.002706862
我想执行以下操作:输入 - > word2vec - >输出 - >神经网络, 但是示例代码的输出格式与我的输出不匹配。有人可以帮帮我吗?