为什么“print(getResults(test_data,getNaiveAnswer))”即此代码的最后一行没有作为数据帧提供预期的输出?

2024-10-03 11:13:45 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么“print(getResults(test_data,getNaiveAnswer))”即此代码的最后一行没有作为数据帧提供预期的输出

import numpy as np
import pandas as pd
import re
df = pd.read_csv('C:/Users/91750/Desktop/Machine Learning/csv/qa_AI.csv')
df
# this function is used to get printable results
def getResults(questions, fn):
    def getResult(q):
        answer, score, prediction = fn(q)
        return [q, prediction, answer, score]

        return  pd.DataFrame(list(map(getResult, questions)), columns=["Q", "Prediction", "A", "Score"])
    
    test_data = ['What are the subjects in FY?',' timings of the college hours?','order status','what is the order history','protein availability']
    
df  
test_data = ['What are the subjects in FY?',' timings of the college hours?','order status','what is the order history','protein availability']
    
def getNaiveAnswer(q):
    
    # regex helps to pass some punctuation signs:
    row = data.loc[data['Questions'].str.contains(re.sub(r"[^\w'\s)]+", "", q),case=False)]
    if len(row) > 0:
        return row["Answers"].values[0], 1, row["Questions"].values[0]
               
    return "Sorry, I didn't get you.", 0, ""

getResults(test_data, getNaiveAnswer)
print (getResults(test_data,getNaiveAnswer))

输出

None

Tags: csvthetestimportdfdatareturnis