背景:我正在开展一个项目,该项目旨在使用 Azure ML 中的情绪分析将产品评论分为正面和负面。当我将评论分类到不同的部门时,我陷入了困境。
我基本上是从 csv 文件中读取单词并检查评论(v:句子列表)是否包含这些单词。如果在评论中找到其中一些词,那么我会记下句子编号并将其推送到相应的列表中(FinanceList、QualityList、LogisticsList)。最后,我将列表转换为字符串并将它们推送到数据框中。
我在 Azure ML 中的脚本中编写的打印语句没有记录输出。
数据框中的值始终为 0,但是当我在本地运行代码时,我得到了预期的输出。
第一个图像的描述:数据框的列显示 0 值。
第二张图片的描述:我已经突出显示了我在本地获得的预期输出,用于在 AzureML 中使用的相同审查。
我已经检查过的东西:
- 正确读取 csv 文件。
- 评论包含我正在搜索的单词。
我无法理解我哪里出错了。
'
import csv
import math
import pandas as pd
import numpy as np
def azureml_main( data, ud):
FinanceDept = []
LogisticsDept = []
QualityDept = []
#Reading from the csv files
with open('.\Script Bundle\\quality1.csv', 'rb') as fin:
reader = csv.reader(fin)
QualityDept = list(reader)
with open('.\Script Bundle\\finance1.csv', 'rb') as f:
reader = csv.reader(f)
FinanceDept = list(reader)
with open('.\Script Bundle\\logistics1.csv', 'rb') as f:
reader = csv.reader(f)
LogisticDept = list(reader)
FinanceList = []
LogisticsList = []
QualityList = []
#Initializing the Lists
FinanceList.append(0)
LogisticsList.append(0)
QualityList.append(0)
rev = data['Data']
v = rev[0].split('.')
print FinanceDept
S = 0
for sentence in v:
S = S + 1
z = sentence.split(' ')
for c in z:
c = c.lower()
if c in FinanceDept and S not in FinanceList:
FinanceList.append(S)
if c in LogisticsDept and S not in LogisticsList:
LogisticsList.append(S)
if c in QualityDept and S not in QualityList:
QualityList.append(S)
#Compute User Reputation Score
Upvotes = int(ud['upvotes'].tolist()[0])
Downvotes = int(ud['downvotes'].tolist()[0])
TotalVotes = max(1,Upvotes+Downvotes)
q = data['Score']
print FinanceList
repScore = float(Upvotes)/TotalVotes
repScore = repScore*float( q[0] )
str1 = ','.join(str(e) for e in FinanceList)
str2 = ','.join(str(e) for e in QualityList)
str3 = ','.join(str(e) for e in LogisticsList)
x = ud['id']
#df = pd.DataFrame( [str(repScore), str1 , str2 , str3 ], columns=[Write the columns])
d = {'id': x[0], 'Score': float(repScore),'Logistics':str3,'Finance':str1,'Quality':str2}
df = pd.DataFrame(data=d, index=np.arange(1))
return df,`