风险累积算法
安装
pip install thinkenergy-2.1.0-py3-none-any.whl
#执行激活脚本
使用方法
1.导入引擎工厂类
from thinkenergy.thinkengine import ThinkEngineFactory
2.使用 app_key 和 app_secret 初始化引擎工厂
Tip:用户需要申请app_key 和 app_secret,否则算法无法使用
tef = ThinkEngineFactory(app_key, app_secret)
3.根据算法编码获取具体的算法引擎
Tip:每一个算法都有对应的算法编号码,针对不同的算法请传入正确的算法编号,本例中A100157代表风险累积算法
alg_code = 'A100157'
te1 = tef.get_engine(alg_code)
4.给算法引擎设置参数(可选)
Tip:算法参数可以通过两种方式实现:
通过算法配置文件
通过set_params方法实现
不配置参数会使用默认的参数
te1.set_params(params=params) # 设置参数
5.调用算法
Tip:run()函数接收的数据为DataFarme,用户可以将自己的数据构建成符合算法的DataFarme,本例采用的是读取.csv格式文件中的数据转为DataFarme.
data = pd.read_csv(r'/tmp/sample_data_A100157.csv')
te1.run(data)
算法的使用参数说明如下:
参数 | 类型 | 示例 | 说明 |
---|---|---|---|
app_key | str | 123456 | 用户申请的app_key |
app_secret | str | 'I2NEWMBQFW7IMSD7XFZNHFARCVJAK7IZDK23BGABSWNU5QLBBCWLRFTL6QDAHDM32ZDA5ITFR6JPPJT3JHCBHZC77ZXNYSE4NUPHAEA=' | 用户申请的app_secret |
alg_code | str | A100157 | 算法编码 |
data | DataFrame | pandas二维数组 | |
params | dict | 算法配置 |
算法输入数据样例
算法传入数据DataFarme字段
#风险累积
['vin', 'timestamp','single_volt_list','single_temp_list'](最少50条数据)
输入数据样例
sample_data_A100157.csv文件内容
vin | timestamp | single_volt_list | single_temp_list | |
---|---|---|---|---|
0 | LZ91AE3A1H2LSA371 | 1620479291 | 4.07,4.07,4.07,4.071,4.071,4.068,4.071,4.071,4.072,4.072,4.061,4.07,4.071,4.071,4.071,4.071,4.071,4.071,4.072,4.07,4.071,4.07,4.061,4.07,4.089,4.088,4.088,4.09,4.089,4.09,4.089,4.089,4.089,4.09,4.091,4.089,4.09,4.089,4.09,4.089,4.089,4.089,4.089,4.089,4.089,4.09,4.09,4.09,4.09,4.09,4.072,4.09,4.09,4.089,4.09,4.089,4.09,4.09,4.089,4.09,4.09,4.089,4.09,4.09,4.09,4.089,4.09,4.089,4.089,4.09,4.09,4.088,4.089,4.09,4.09,4.09,4.091,4.09,4.089,4.09,4.09,4.089,4.09,4.09,4.09,4.075,4.089,4.088,4.089,4.09,4.089,4.09 | 29,29,29,30,30,29,30,30,30,30,30,30,30,29,29,29 |
1 | LZ91AE3A1H2LSA371 | 1621262603 | 3.91,3.906,3.905,3.909,3.907,3.907,3.908,3.907,3.908,3.91,3.9,3.91,3.908,3.908,3.909,3.907,3.907,3.908,3.908,3.902,3.906,3.903,3.9,3.91,3.924,3.924,3.925,3.927,3.926,3.924,3.927,3.929,3.926,3.929,3.928,3.925,3.928,3.928,3.925,3.928,3.929,3.927,3.929,3.925,3.922,3.923,3.924,3.922,3.926,3.927,3.909,3.928,3.929,3.923,3.932,3.931,3.925,3.926,3.927,3.924,3.929,3.928,3.924,3.926,3.926,3.925,3.927,3.924,3.92,3.922,3.922,3.922,3.921,3.925,3.926,3.924,3.929,3.927,3.92,3.923,3.927,3.924,3.927,3.927,3.925,3.914,3.925,3.924,3.924,3.923,3.92,3.923 | 24,24,23,25,25,24,25,25,25,25,25,25,25,24,24,24 |
2 | LZ91AE3A1H2LSA371 | 1620605310 | 3.945,3.944,3.944,3.946,3.946,3.943,3.945,3.946,3.945,3.946,3.937,3.945,3.945,3.945,3.946,3.946,3.946,3.946,3.946,3.944,3.945,3.945,3.937,3.945,3.962,3.962,3.962,3.963,3.963,3.963,3.963,3.963,3.962,3.963,3.964,3.962,3.964,3.963,3.964,3.964,3.963,3.963,3.963,3.963,3.964,3.963,3.963,3.963,3.963,3.963,3.947,3.964,3.964,3.962,3.964,3.964,3.965,3.964,3.963,3.964,3.965,3.964,3.965,3.964,3.964,3.963,3.964,3.962,3.963,3.963,3.963,3.961,3.963,3.963,3.964,3.963,3.965,3.965,3.964,3.963,3.963,3.963,3.964,3.963,3.963,3.949,3.963,3.962,3.962,3.964,3.964,3.963 | 26,26,25,27,27,26,27,27,27,27,27,27,27,27,27,27 |
3 | LZ91AE3A1H2LSA371 | 1621230411 | 4.111,4.111,4.111,4.111,4.111,4.108,4.111,4.111,4.111,4.111,4.101,4.111,4.111,4.111,4.111,4.111,4.111,4.111,4.111,4.111,4.111,4.11,4.101,4.111,4.129,4.13,4.129,4.131,4.13,4.131,4.13,4.131,4.13,4.131,4.131,4.13,4.131,4.13,4.131,4.131,4.13,4.13,4.131,4.13,4.13,4.13,4.13,4.129,4.131,4.131,4.111,4.131,4.131,4.13,4.131,4.131,4.13,4.13,4.13,4.13,4.131,4.13,4.13,4.13,4.13,4.13,4.131,4.129,4.129,4.13,4.13,4.129,4.13,4.131,4.131,4.131,4.131,4.131,4.129,4.13,4.131,4.13,4.131,4.131,4.131,4.116,4.131,4.129,4.13,4.13,4.129,4.13 | 29,28,27,30,30,28,30,29,30,29,30,29,29,28,29,28 |
4 | LZ91AE3A1H2LSA371 | 1621257077 | 4.014,4.014,4.014,4.014,4.014,4.011,4.014,4.014,4.014,4.015,4.005,4.014,4.014,4.014,4.014,4.014,4.014,4.014,4.015,4.014,4.015,4.014,4.005,4.014,4.031,4.031,4.031,4.032,4.032,4.032,4.032,4.032,4.031,4.032,4.032,4.031,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.015,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.031,4.032,4.032,4.032,4.032,4.032,4.032,4.031,4.032,4.031,4.032,4.032,4.032,4.03,4.032,4.032,4.032,4.032,4.034,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.032,4.018,4.032,4.031,4.032,4.032,4.032,4.032 | 25,24,23,26,25,25,26,25,25,25,25,25,25,24,25,25 |
算法参数配置
#在配置文件中的配置
CO_PARAMS = {
'alg_config': {
}
}
详细实例demo
import pandas as pd
from thinkenergy.thinkengine import ThinkEngineFactory
app_key = '123456' # 用户申请的 app_key
app_secret = 'I2NEWMBQFW7IMSD7XFZNHFARCVJAK7IZD' \
'K23BGABSWNU5QLBBCWLRFTL6QDAHDM32Z' \
'DA5ITFR6JPPJT3JHCBHZC77ZXNYSE4NUP' \
'HAEA=' # 用户申请的 app_secret
tef = ThinkEngineFactory(app_key, app_secret) # 初始化引擎工厂
# 实例化
alg_code = 'A100157' # 算法编号.本例为风险累积预警算法编号
data = pd.read_csv(r'/tmp/charge_trip.csv', encoding = 'gbk') # 读取 CSV
params = {
'alg_config': {
}
} #可传入符合厂商的配置参数
te1 = tef.get_engine(alg_code) # 获取风险累积预警算法引擎
te1.set_params(params=params) # 设置参数.可选,非必须
print(te1.run(data)) # 调用风险累积预警算法
算法结果
{'vin': 'Vehicle1_1.csv', 'start_time': '2020-01-20 01:43:39', 'end_time': '2020-03-19 18:13:31', 'score_list': '
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6,
1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6,
1.6]', 'max_score': 1.6}