評分函數(shù)(score function),它是原始圖像數(shù)據(jù)到類別分值的映射稼钩。
損失函數(shù)(loss function)顾稀,它是用來量化預測分類標簽的得分與真實標簽之間一致性的。
該方法可轉(zhuǎn)化為一個最優(yōu)化問題坝撑,在最優(yōu)化過程中静秆,將通過更新評分函數(shù)的參數(shù)來最小化損失函數(shù)值。
python excel 轉(zhuǎn) 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 轉(zhuǎn) json
import pandas as pd
def processLine(target):
str1 = (' '.join(target.split())).replace(' 訪客問題', '#訪客問題') \
.replace(' 所屬類目', '@所屬類目').replace(' 機器人回答', '@機器人回答').replace(' 相關(guān)問題', '@相關(guān)問題') \
.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)