简体   繁体   中英

How can I make decision for exactly one data set using ID3 decision tree

I'm implementing a program that ask user for their symptoms (whether they have fever, cough, breathing issue) to check if they need COVID test.

I implemented my id3 decision tree, used some dataset in csv file

Now I want the program be like it can prompt user input to enter their symptoms (whether they have fever, cough, breathing issue), and tell them some info

My code is attached down below, the question is when I ran it, the error msg showed up, I think it is because I only have one dataset in my txt file

pandas.errors.EmptyDataError: No columns to parse from file

May I ask how can I fix it or is their a better way to make decision for just one data?

Thank you!

fever = input("Do you have a fever? (Yes or No) ")
cough = input("Do you cough? (Yes or No) ")
breathing_issue = input("Do you have short breating or other breathing issues? (Yes or No) ")
infected = "Yes"
test_sample = fever + "," + cough + "," + breathing_issue + "," +infected
f = open("test.txt", "w")
f.write(test_sample)
# convert to .csv
test_df = pd.read_csv(r'/Users/xxxx/xxxx/xxxx/test.txt', header=None, delim_whitespace=True)
train_df.columns = ['fever', 'cough', 'breating-issue', 'infected']
pd.set_option("display.max_columns", 500) # Load all columns

The reason this occurs is because lines 7-9 read an empty data frame. Here is a minimal reproducible example demonstrating the error:

import pandas as pd

with open("test.txt", "w") as _fh:
  _fh.write("yes,no,yes,no")

df = pd.read_csv("test.txt")
print(df)

Output:

Empty DataFrame
Columns: [yes, no, yes.1, no.1]
Index: []

To get a nonempty DataFrame, either the columns need names or pd.read_csv needs to be called with optional argument header=None . Here is a version where column names are written:

import pandas as pd

with open("test.txt", "w") as _fh:
  _fh.write("fever,cough,breathing_issues,infected\n")
  _fh.write("yes,no,yes,no")

df = pd.read_csv("test.txt")
print(df)

Output:

  fever cough breathing_issues infected
0   yes    no              yes       no

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM