Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从多层感知器分类器中获取神经元权重_Python_Apache Spark_Pyspark - Fatal编程技术网

Python 如何从多层感知器分类器中获取神经元权重

Python 如何从多层感知器分类器中获取神经元权重,python,apache-spark,pyspark,Python,Apache Spark,Pyspark,我在pySpark(使用Spark 1.6.0)中使用了一个MLP多类分类器,或多或少地遵循了来自的示例 因为我感兴趣的是训练模型一次,然后在不同的数据集上使用已经训练过的模型,所以我想检索神经元权重(就像为python sklearn使用pickle包解释的那样) 然而,在阅读了本文之后,我无法获得模型的权重和内部参数 如果有帮助,我的代码是: # Importing PySpark libraries from pyspark import SparkConf, SparkContext f

我在pySpark(使用Spark 1.6.0)中使用了一个MLP多类分类器,或多或少地遵循了来自的示例

因为我感兴趣的是训练模型一次,然后在不同的数据集上使用已经训练过的模型,所以我想检索神经元权重(就像为python sklearn使用pickle包解释的那样)

然而,在阅读了本文之后,我无法获得模型的权重和内部参数

如果有帮助,我的代码是:

# Importing PySpark libraries
from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext, HiveContext
from pyspark.ml.classification import MultilayerPerceptronClassifier
from pyspark.ml.evaluation import MulticlassClassificationEvaluator

#%% Codigo inicio

if __name__ == "__main__":

    conf  = SparkConf().setAppName("prueba_features")
    sc    = SparkContext(conf=conf)
    hc    = HiveContext(sc)
    sqlc  = SQLContext(sc)

    # Load training data
    data = sqlc.read.format("libsvm")\
        .load("/user/sample_multiclass_classification_data.txt")

    # print data
    print("\nData set: \n{}".format(data))

    # Split the data into train and test
    splits = data.randomSplit([0.6, 0.4], 1234)
    train = splits[0]
    test = splits[1]

    # print sets
    print("\nTraining set: \n{}".format(train))
    print("\nTest set: \n{}".format(test))

    # 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)
    layers = [4, 5, 4, 3]

    # create the trainer and set its parameters
    trainer = MultilayerPerceptronClassifier(maxIter=100, layers=layers, blockSize=128, seed=1234)

    # train the model
    model = trainer.fit(train)

    # compute precision on the test set
    result = model.transform(test)
    predictionAndLabels = result.select("prediction", "label")
    evaluator_prec = MulticlassClassificationEvaluator(metricName="precision")
    evaluator_rec = MulticlassClassificationEvaluator(metricName="recall")
    evaluator_f1 = MulticlassClassificationEvaluator(metricName="f1")

    # print fitting precision and results
    print("\nResults: \n{}".format(result))

    print("\nKPIs")
    print("Precision: " + str(evaluator_prec.evaluate(predictionAndLabels)))
    print("Recall: " + str(evaluator_rec.evaluate(predictionAndLabels)))
    print("F1-score: " + str(evaluator_f1.evaluate(predictionAndLabels)))

    # we end the SparkContext
    sc.stop()

如果可能,有人知道如何使用pySpark MLP吗?

您正在寻找的方法是:

权重

层的权重

版本2.0.0中的新功能


正如注释所说,您需要将Spark版本更新到至少2.0才能使用它。

谢谢!但升级到2.0.0不是一个选项,因为无法修改环境。。。例如,Spark 1.6.0中是否有一个选项,可以使用带有配置参数的文件完全初始化MLP分类器,就像其他分类器一样?