說明:
spark.mlp
針對 SparkDataFrame 擬合多層感知器神經網絡模型。用戶可以調用summary
打印擬合模型的摘要,調用predict
對新數據進行預測,調用write.ml
/read.ml
保存/加載擬合模型。僅支持分類數據。有關詳細信息,請參閱Multilayer Perceptron
用法:
spark.mlp(data, formula, ...)
## S4 method for signature 'SparkDataFrame,formula'
spark.mlp(
data,
formula,
layers,
blockSize = 128,
solver = "l-bfgs",
maxIter = 100,
tol = 1e-06,
stepSize = 0.03,
seed = NULL,
initialWeights = NULL,
handleInvalid = c("error", "keep", "skip")
)
## S4 method for signature 'MultilayerPerceptronClassificationModel'
summary(object)
## S4 method for signature 'MultilayerPerceptronClassificationModel'
predict(object, newData)
## S4 method for signature 'MultilayerPerceptronClassificationModel,character'
write.ml(object, path, overwrite = FALSE)
參數:
data
用於模型擬合的SparkDataFrame
觀察值和標簽。formula
要擬合的模型的符號說明。目前僅支持少數公式運算符,包括'~'、'.'、':'、'+'和'-'。...
傳遞給該方法的附加參數。layers
包含每層節點數的整數向量。blockSize
塊大小參數。solver
求解器參數,支持的選項:"gd"(小批量梯度下降)或"l-bfgs"。maxIter
最大迭代次數。tol
迭代的收斂容差。stepSize
步長參數。seed
權重初始化的種子參數。initialWeights
權重初始化的 initialWeights 參數,它應該是一個數字向量。handleInvalid
如何處理字符串類型的特征和標簽列中的無效數據(看不見的標簽或 NULL 值)。支持的選項:"skip"(過濾掉包含無效數據的行)、"error"(拋出錯誤)、"keep"(將無效數據放入特殊的附加存儲桶中,索引為 numLabels)。默認為"error"。object
spark.mlp
擬合的多層感知器分類模型newData
用於測試的 SparkDataFrame。path
保存模型的目錄。overwrite
如果輸出路徑已經存在,是否覆蓋。默認為 FALSE,這意味著如果輸出路徑存在則拋出異常。
返回:
spark.mlp
返回擬合的多層感知器分類模型。
summary
返回擬合模型的匯總信息,是一個列表。該列表包括numOfInputs
(輸入數量)、numOfOutputs
(輸出數量)、layers
(包括輸入和輸出層的層大小數組)和weights
(層的權重)。對於 weights
,它是一個長度等於給定架構的預期長度的數字向量(即,對於 8-10-2 網絡,112 個連接權重)。
predict
返回一個 SparkDataFrame,其中包含在名為 "prediction" 的列中標記的預測值。
注意:
spark.mlp 自 2.1.0
摘要(MultilayerPerceptronClassificationModel) 自 2.1.0
從 2.1.0 開始預測(MultilayerPerceptronClassificationModel)
write.ml(MultilayerPerceptronClassificationModel, character) 自 2.1.0
例子:
df <- read.df("data/mllib/sample_multiclass_classification_data.txt", source = "libsvm")
# fit a Multilayer Perceptron Classification Model
model <- spark.mlp(df, label ~ features, blockSize = 128, layers = c(4, 3), solver = "l-bfgs",
maxIter = 100, tol = 0.5, stepSize = 1, seed = 1,
initialWeights = c(0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 9, 9, 9, 9, 9))
# get the summary of the model
summary(model)
# make predictions
predictions <- predict(model, df)
# save and load the model
path <- "path/to/model"
write.ml(model, path)
savedModel <- read.ml(path)
summary(savedModel)
相關用法
- R SparkR spark.decisionTree用法及代碼示例
- R SparkR spark.powerIterationClustering用法及代碼示例
- R SparkR spark.svmLinear用法及代碼示例
- R SparkR spark.gaussianMixture用法及代碼示例
- R SparkR spark.naiveBayes用法及代碼示例
- R SparkR spark.getSparkFiles用法及代碼示例
- R SparkR spark.survreg用法及代碼示例
- R SparkR spark.lm用法及代碼示例
- R SparkR spark.fmClassifier用法及代碼示例
- R SparkR spark.gbt用法及代碼示例
- R SparkR spark.getSparkFilesRootDirectory用法及代碼示例
- R SparkR spark.logit用法及代碼示例
- R SparkR spark.addFile用法及代碼示例
- R SparkR spark.isoreg用法及代碼示例
- R SparkR spark.als用法及代碼示例
- R SparkR spark.glm用法及代碼示例
- R SparkR spark.lapply用法及代碼示例
- R SparkR spark.fmRegressor用法及代碼示例
- R SparkR spark.kmeans用法及代碼示例
- R SparkR spark.lda用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 Multilayer Perceptron Classification Model。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。