# 隐私计算FATE-多分类神经网络算法测试

2022/07/07 08:54

## 一、说明

• 二分类算法：是指待预测的 label 标签的取值只有两种；直白来讲就是每个实例的可能类别只有两种(0 或者 1)，例如性别只有 或者 ；此时的分类算法其实是在构建一个分类线将数据划分为两个类别。
• 多分类算法：是指待预测的 label 标签的取值可能有多种情况，例如个人爱好可能有 篮球足球电影 等等多种类型。常见算法：Softmax、SVM、KNN、决策树。

## 二、准备训练数据

### 2.1. guest端

10条数据，包含1个分类字段 y 和 10 个标签字段 x0 - x9

y 值有 0、1、2、3 四个分类

### 2.2. host端

10条数据，字段与 guest 端一样，但是内容不一样

## 三、执行训练任务

### 3.1. 准备dsl文件

{
"components": {
"output": {
"data": [
"data"
]
}
},
"data_transform_0": {
"module": "DataTransform",
"input": {
"data": {
"data": [
]
}
},
"output": {
"data": [
"data"
],
"model": [
"model"
]
}
},
"homo_nn_0": {
"module": "HomoNN",
"input": {
"data": {
"train_data": [
"data_transform_0.data"
]
}
},
"output": {
"data": [
"data"
],
"model": [
"model"
]
}
}
}
}


### 3.2. 准备conf文件

{
"dsl_version": 2,
"initiator": {
"role": "guest",
"party_id": 9999
},
"role": {
"arbiter": [
10000
],
"host": [
10000
],
"guest": [
9999
]
},
"component_parameters": {
"common": {
"data_transform_0": {
"with_label": true
},
"homo_nn_0": {
"encode_label": true,
"max_iter": 15,
"batch_size": -1,
"early_stop": {
"early_stop": "diff",
"eps": 0.0001
},
"optimizer": {
"learning_rate": 0.05,
"decay": 0.0,
"beta_1": 0.9,
"beta_2": 0.999,
"epsilon": 1e-07,
},
"loss": "categorical_crossentropy",
"metrics": [
"accuracy"
],
"nn_define": {
"class_name": "Sequential",
"config": {
"name": "sequential",
"layers": [
{
"class_name": "Dense",
"config": {
"name": "dense",
"trainable": true,
"batch_input_shape": [
null,
18
],
"dtype": "float32",
"units": 5,
"activation": "relu",
"use_bias": true,
"kernel_initializer": {
"class_name": "GlorotUniform",
"config": {
"seed": null,
"dtype": "float32"
}
},
"bias_initializer": {
"class_name": "Zeros",
"config": {
"dtype": "float32"
}
},
"kernel_regularizer": null,
"bias_regularizer": null,
"activity_regularizer": null,
"kernel_constraint": null,
"bias_constraint": null
}
},
{
"class_name": "Dense",
"config": {
"name": "dense_1",
"trainable": true,
"dtype": "float32",
"units": 4,
"activation": "sigmoid",
"use_bias": true,
"kernel_initializer": {
"class_name": "GlorotUniform",
"config": {
"seed": null,
"dtype": "float32"
}
},
"bias_initializer": {
"class_name": "Zeros",
"config": {
"dtype": "float32"
}
},
"kernel_regularizer": null,
"bias_regularizer": null,
"activity_regularizer": null,
"kernel_constraint": null,
"bias_constraint": null
}
}
]
},
"keras_version": "2.2.4-tf",
"backend": "tensorflow"
},
"config_type": "keras"
}
},
"role": {
"host": {
"0": {
"table": {
"name": "muti_breast_homo_host",
"namespace": "experiment"
}
}
}
},
"guest": {
"0": {
"table": {
"name": "muti_breast_homo_guest",
"namespace": "experiment"
}
}
}
}
}
}
}


### 3.3. 提交任务

flow job submit -d homo_nn_dsl.json -c homo_nn_multi_label_conf.json


## 五、准备预测配置

{
"dsl_version": 2,
"initiator": {
"role": "guest",
"party_id": 9999
},
"role": {
"arbiter": [
10000
],
"host": [
10000
],
"guest": [
9999
]
},
"job_parameters": {
"common": {
"model_id": "arbiter-10000#guest-9999#host-10000#model",
"model_version": "202207061504081543620",
"job_type": "predict"
}
},
"component_parameters": {
"role": {
"guest": {
"0": {
"table": {
"name": "predict_muti_breast_homo_guest",
"namespace": "experiment"
}
}
}
},
"host": {
"0": {
"table": {
"name": "predict_muti_breast_homo_host",
"namespace": "experiment"
}
}
}
}
}
}
}


1. model_idmodel_version 需修改为模型部署后的版本号。

2. reader_0 组件的表名和命名空间需与上传数据时配置的一致。

## 六、执行预测任务

flow job submit -c homo_nn_multi_label_predict.json


0 评论
0 收藏
0