I am working on the CS50AI "Shopping" project and received the following comments from the grader. I have checked the specification carefully but didn't spot any issue. The output seems to work as well.
Extracted my code below for reference. Any guidance / hint would be appreciated. This is my only pending project. Thank you!
Comments from grader:
The load_data function does not accept/process all of the data types it should be processing. Be sure everything is handled correctly! https://cs50.harvard.edu/ai/2023/projects/4/shopping/#specification
Code:
def load_data(filename):
evidence = []
label = []
month = {'Jan': 0,
'Feb': 1,
'Mar': 2,
'Apr': 3,
'May': 4,
'June': 5,
'Jul': 6,
'Aug': 7,
'Sep': 8,
'Oct': 9,
'Nov': 10,
'Dec': 11}
counter = 0
with open(sys.argv[1], 'r') as file:
csvreader = csv.reader(file)
for row in csvreader:
if counter == 0: #I have used this if-else to exclude the first header row
counter += 1
else:
evidence.append([
int(row[0]),
float(row[1]),
int(row[2]),
float(row[3]),
int(row[4]),
float(row[5]),
float(row[6]),
float(row[7]),
float(row[8]),
float(row[9]),
month[row[10]],
int(row[11]),
int(row[12]),
int(row[13]),
int(row[14]),
1 if row[15] == "Returning_Visitor" else 0,
1 if row[16] == "TRUE" else 0
])
label.append(
1 if row[17] == "TRUE" else 0
)
return (evidence, label)