背景:我正在做一个项目,该项目的目标是使用azureml中的情绪分析将产品评论分为正面和负面两类。当我将评论分类到不同的部门时,我遇到了麻烦。在
我基本上是从csv文件中读取单词,并检查评论(v:句子列表)是否包含这些单词。如果这些单词中有一些是在评论中找到的,那么我会记下句子编号,并将其放入相应的列表(FinanceList、QualityList、LogisticsList)。最后,我将列表转换为字符串,并将它们推送到数据帧中。在
我在azureml中编写的print语句的输出没有被记录
数据帧中的值总是为0,但是当我在本地运行代码时,我得到了预期的输出。在
第一个映像的说明:数据帧中显示0值的列。在
第二幅图的描述:我已经突出显示了在本地获得的预期输出,这是在AzureML中使用的同一个评审。在
我已经检查过了:
我不明白我哪里做错了。在
'
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,`
@Anuj Shankar公司, 在我的同事测试之后,我们可以从
CSV
文件中读取数据并得到预期的结果。请参考以下经验:1)输入数据-它有
apple.zip
文件,其中有两个与您类似的csv
文件,每个csv文件都包含与公司相关的单词包。在2) Python脚本:
如果我想买一个字符串,我想买一个3。它有2个与微软有关的单词,0个与苹果有关,在下面的快照中可以看到。
你能检查一下文件路径是否正确,根据https://azure.microsoft.com/en-us/documentation/articles/machine-learning-execute-python-scripts/,Python代码不能访问它运行的机器上的大多数目录,例外是当前目录及其子目录。“脚本包”是子目录吗?您也可以尝试使用输入,而不是从脚本读取csv文件。executepython脚本模块接受3个输入,前2个是数据帧,第3个是为Python库文件保留的。例如,您可以对实际数据使用input 1,对csv中最初的单词使用input 2。它需要有一个机制,将3个csv文件捆绑到一个单独的数据帧中输入2。在
相关问题 更多 >
编程相关推荐