基于云计算的电子政务服务质量评估方法示例

2.6 系统使用示例具体的示例代码见 src/example.py

2.6.1 完整示例

假设 data 文件夹下有一个 post.train 和 post.test 的训练样本和测试样本,每行有 3 个字段:label、title、content。样本未分词,示例需完成以下任务:

1. 对 title 分词并训练,模型保存在 ../data/post/ 目录下,文件命名为 title,使用 libsvm 的 rbf 核函数,保留 top 40% 的词,特征权重采用 tf*idf。

2. 对 title 和 content 一起分词并训练,模型保存在 ../data/post/ 目录下,文件命名为 title_content,使用 liblinear,保留 top 20% 的词,特征权重采用 tf。

3. 对 post.test 进行分词,用已训练模型预测,结果命名为 post.result,输出原 label 与预测结果。

4. 计算预测模型的 F 值、Recall、Precision,输出到屏幕。

5. 计算 [0,1] 区间内各阈值下的 F 值、Recall、Precision,将结果保存在 post.analysis 文件中。

tms.tms_train("../data/post.train", indexes=[1], main_save_path="../data/", stopword_filename="../data/stopwords.txt", svm_type="libsvm", svm_param="-t 2", config_name="title.config", dic_name="title.key", model_name="title.model", train_name="title.train", param_name="title.param", ratio=0.4, seg=1, local_fun="tf", global_fun="idf")

tms.tms_train("../data/post.train", indexes=[1,2], main_save_path="../data/", stopword_filename="../data/stopwords.txt", svm_type="liblinear", config_name="title_content.config", dic_name="title_content.key", model_name="title_content.model", train_name="title_content.train", param_name="title_content.param", ratio=0.2, seg=1, local_fun="tf", global_fun="one")

tms.tms_predict_multi("../data/post.test", config_files=["../data/model/title.config", "../data/model/title_content.config"], indexes_lists=[[1],[1,2]], result_save_path="../data/post.result", result_indexes=[0], seg=1)

tms.tms_analysis("../data/post.result", step=2, output_file="", indexes=[0,1,2], predicted_label_index=0, predicted_value_index=1, true_label_index=2)
pdf 文件大小:591.34KB