Esempio n. 1
0
 def setUp(self):
     # 加载测试文件
     cases = load_csv("../file/mysql_test_case.csv")
     # 使用孤立森立判断label
     isolate1 = Isolate('mysql_test_case', cases)
     # 孤立森林判断后的结果
     self.np_array = isolate1.merge_arrays()
     # 连接数据库
     self.db = connectdb()
     # 设置表名
     self.table_name = self.np_array[1, 0]
Esempio n. 2
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/12/28 16:38
# @Author  : zsj
# @File    : xgboost_test.py
# @Description:

import numpy as np
import xgboost as xgb

from isolate_model.base_function import load_csv, translate_to_xgboost_datas

cases = load_csv("../file/predict.csv")
# isolate1 = Isolate('2_7', cases)
# np_array = isolate1.merge_arrays()
np_array = translate_to_xgboost_datas(cases)

# 从文本文件加载文件,也是由xgboost生成的二进制缓冲区,加载能训练的文件,
np_array = np_array[1:]
print("nparray", np_array)
length = len(np_array)
print(length)
# 按行打乱顺序,然后从中选择训练集,测试集, 验证集
np.random.shuffle(np_array)
rate = [8, 1, 1]
total_rate = sum(rate)
rate_num1 = int(length * rate[0] / total_rate)
rate_num2 = int(length * (rate[0] + rate[1]) / total_rate)
print(rate_num1)
print(rate_num2 - rate_num1)
dtrain = xgb.DMatrix(np_array[0:rate_num1, 1:-1].astype(float),
Esempio n. 3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/1/11 17:52
# @Author  : zsj
# @File    : xgb_func_test.py
# @Description:
from db.mysql_operation import insert_train_datas, connectdb, query_table, create_table
from isolate_model.base_function import load_csv, translate_to_xgboost_datas, save_xgboost_class, load_xgboost_class
from isolate_model.isolate_class import Isolate
from xgboost_model.xgboost_class import XGBoost

cases = load_csv("../file/customs_cpu_test.csv")
isolate1 = Isolate('2_7', cases)
np_array = isolate1.merge_arrays()
table_name = np_array[1, 0]
db = connectdb()
if not query_table(db, table_name):
    create_table(db, np_array[0], table_name)

insert_train_datas(db, table_name, np_array[1:])

xgb1 = XGBoost(table_name)
print(xgb1.name)
save_xgboost_class(xgb1)
pre = load_xgboost_class("982c78b5-435a-40b3-9a31-9fb5fbf8b16")
print(pre.precision, pre.recall, pre.lasted_update)
Esempio n. 4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/12/17 11:55
# @Author  : zsj
# @File    : isolate_test.py
# @Description:

from isolate_model.base_function import load_csv, show_csv, draw_with_diff_color
from isolate_model.isolate_class import Isolate

cases = load_csv("../file/customs_test2.csv")

# ##初始化模型
isolate1 = Isolate('2_7', cases)
# isolate1.init_model()
arr = isolate1.merge_arrays()
draw_with_diff_color(arr)
show_csv(cases, 1, 2)
Esempio n. 5
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/1/5 17:45
# @Author  : zsj
# @File    : db_test.py
# @Description:
from db.mysql_operation import connectdb, create_table, query_table, query_datas, update_datas, delete_datas, \
    drop_table, insert_train_datas, closedb
from isolate_model.base_function import load_csv
from isolate_model.isolate_class import Isolate

cases = load_csv("../file/customs_msmq_test.csv")
isolate1 = Isolate('2_7', cases)
np_array = isolate1.merge_arrays()

db = connectdb()
table_name = np_array[1, 0]
# 判断是否存在该表
is_exists = query_table(db, table_name)
# 如果不存在则创建该表
if not is_exists:
    create_table(db, np_array[0], table_name)
# 插入数据
insert_train_datas(db, table_name, np_array[1:])
result = query_datas(db, table_name)
print(len(result))