07.17

评分函数(score function),它是原始图像数据到类别分值的映射。
损失函数(loss function),它是用来量化预测分类标签的得分与真实标签之间一致性的。
该方法可转化为一个最优化问题,在最优化过程中,将通过更新评分函数的参数来最小化损失函数值

python excel 转 json

#!/usr/bin/python
# -*- coding: utf-8 -*-
import pandas as pd
import json

# df = pd.read_excel('tmp.xls',sheetname=1,index_col='领域')

#读xls
df = pd.read_excel('target.xls',sheetname=0)
str = df.to_json(orient='records',force_ascii=False)
f = open('jsondata_xls.txt','a')
json.dump(str,f,ensure_ascii=False)

#读csv
#,encoding = "ISO-8859-1"
df = pd.read_csv('target.csv',encoding="gb18030")
str = df.to_json(orient='records',force_ascii=False)
f = open('jsondata_cvs.txt','a')
json.dump(str,f,ensure_ascii=False)

string 转 json

import pandas as pd

def processLine(target):
    str1 = (' '.join(target.split())).replace(' 访客问题', '#访客问题') \
        .replace(' 所属类目', '@所属类目').replace(' 机器人回答', '@机器人回答').replace(' 相关问题', '@相关问题') \
        .replace(' 匹配答案', '&匹配答案').replace(' 答案', '&答案')
    str2 = (''.join(str1.split()).replace('>>/', '>>')).replace(':',':')
    #chat list
    chat_list = str2.split('#')

    # print(chat_list)

    list_all = []
    for chat_item in chat_list:
        item1_list = chat_item.split('@')
        dict = {}
        for i in item1_list:
            if '&' not in i:
                i_list = i.split('>>')
                if len(i_list)<2:
                    print('', end='')
                else:
                    dict[i_list[0]] = i_list[1]
            else:
                i_list = i.split('>>')
                if len(i_list)<2:
                    print('', end='')
                else:
                    dict_temp = {}
                    tmp1 = i_list[1].split('&')

                    for tt in tmp1:
                        ttl = tt.split(':')
                        if len(ttl) < 2:
                            print('',end='')
                        else:
                            dict_temp[ttl[0]] = ttl[1]

                    dict[i_list[0]] = dict_temp
        list_all.append(dict)

    print(list_all)

df = pd.read_excel('target.xls',sheetname=0)

chats = df['对话详细信息']

_target = chats[0]


for chat in chats:
    processLine(chat)



你可能感兴趣的:(07.17)