Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Additional Requirements 1.The name of your source code fileshould be ProbEst.py

ID: 3789283 • Letter: A

Question

Additional Requirements

1.The name of your source code fileshould be ProbEst.py All your code should be within a single file.

2.You cannot import any package except for pandas.You need to use the pandas DataFrame object for storing data

Requirements Y ou are to create a program in Python that performs the following: 1. Asks the user for the number of cars (i.e. data instances) . 2. F or each car , ask s the user to enter the following fields: make, model , type (coupe, sedan, SUV), rating (A, B, C, D, or F) . Save the feature values for each car in a DataFrame object. 3. Display s the resulting DataFrame 4. Compute s the probability of each rating and output s to the screen. 5. For each type , compute s the conditional probability of that type, given each of the ratings: 6. Display s the conditional probabilities to the screen.

Output

70-511, [semester] [year]

NAME: [put your name here]

PROGRAMMING ASSIGNMENT #4

Enter the number of car instances:6

Enter the make,model,type,rating:ford,mustang,coupe,A

Enter the make,model,type,rating:chevy,camaro,coupe,B

Enter the make,model,type,rating:ford,fiesta,sedan,C

Enter the make,model,type,rating:ford,focus,sedan,A

Enter the make,model,type,rating:ford,taurus,sedan,B

Enter the make,model,type,rating:toyota,camry,sedan,B

   make   model             type                 rating

0 ford             mustang         coupe                 A

1 chevy          camaro           coupe B

2 ford             fiesta              sedan                  C

3 ford             focus              sedan    A

4 ford             taurus            sedan                   B

5 toyota         camry sedan                  B

Prob(rating=A) = 0.333333

Prob(rating=B) = 0.500000

Prob(rating=C) = 0.166667

Prob(type=coupe|rating=A) = 0.500000

Prob(type=sedan|rating=A) = 0.500000

Prob(type=coupe|rating=B) = 0.333333

Prob(type=sedan|rating=B) = 0.666667

Prob(type=coupe|rating=C) = 0.000000

Prob(type=sedan|rating=C) = 1.000000

Explanation / Answer

class Car(object):
def __init__(self, make=None, model=None, typee=None, rating=None):
self.make = make
self.model = model
self.typee = typee
self.rating = rating
  
t=input("Enter the number of car instances: ")
ca=cb=cc=cd=ce=cf=0.0
carList = []
ca_sedan=ca_coupe=ca_suv=0.0
cb_sedan=cb_coupe=cb_suv=0.0
cc_sedan=cc_coupe=cc_suv=0.0
cd_sedan=cd_coupe=cd_suv=0.0
ce_sedan=ce_coupe=ce_suv=0.0
cf_sedan=cf_coupe=cf_suv=0.0
for _ in range(t):
   k=map(str,raw_input("Enter the make,model,type,rating: ").split(','))
   if(k[3]=='A'):
       ca+=1
       if k[2]=='sedan': ca_sedan+=1
       if k[2]=='coupe': ca_coupe+=1
       if k[2]=='SUV': ca_suv+=1
   if(k[3]=='B'):
       cb+=1
       if k[2]=='sedan': cb_sedan+=1
       if k[2]=='coupe': cb_coupe+=1
       if k[2]=='SUV': cb_suv+=1
   if(k[3]=='C'):
       cc+=1
       if k[2]=='sedan': cc_sedan+=1
       if k[2]=='coupe': cc_coupe+=1
       if k[2]=='SUV': cc_suv+=1
   if(k[3]=='D'):
       cd+=1
       if k[2]=='sedan': cd_sedan+=1
       if k[2]=='coupe': cd_coupe+=1
       if k[2]=='SUV': cd_suv+=1
   if(k[3]=='E'):
       ce+=1
       if k[2]=='sedan': ce_sedan+=1
       if k[2]=='coupe': ce_coupe+=1
       if k[2]=='SUV': ce_suv+=1
   if(k[3]=='F'):
       cf+=1
       if k[2]=='sedan': cf_sedan+=1
       if k[2]=='coupe': cf_coupe+=1
       if k[2]=='SUV': cf_suv+=1
   carList.append(Car(k[0],k[1],k[2],k[3]))
print "70-511, [semester] [year]"
print "NAME: [put your name here]"
print "PROGRAMMING ASSIGNMENT #4"
print
print "make       model       type        rating"
for i in range(t):
   print i," ",carList[i].make,"   ",carList[i].model,"   ",carList[i].typee,"   ",   carList[i].rating
print
print "Prob(rating=A) = '%.6f'" %(ca/t)
print "Prob(rating=B) = '%.6f'" %(cb/t)
print "Prob(rating=C) = '%.6f'" %(cc/t)
print "Prob(rating=D) = '%.6f'" %(cd/t)
print "Prob(rating=E) = '%.6f'" %(ce/t)
print "Prob(rating=F) = '%.6f'" %(cf/t)
print
if ca>0:
   print "Prob(type=coupe|rating=A) = '%.6f'" %(ca_coupe/ca)
   print "Prob(type=sedan|rating=A) = '%.6f'" %(ca_sedan/ca)
   print "Prob(type=SUV|rating=A) = '%.6f'" %(ca_suv/ca)
if cb>0:
   print "Prob(type=coupe|rating=B) = '%.6f'" %(cb_coupe/cb)
   print "Prob(type=sedan|rating=B) = '%.6f'" %(cb_sedan/cb)
   print "Prob(type=SUV|rating=B) = '%.6f'" %(cb_suv/cb)
if cc>0:
   print "Prob(type=coupe|rating=C) = '%.6f'" %(cc_coupe/cc)
   print "Prob(type=sedan|rating=C) = '%.6f'" %(cc_sedan/cc)
   print "Prob(type=SUV|rating=C) = '%.6f'" %(cc_suv/cc)
if cd>0:
   print "Prob(type=coupe|rating=D) = '%.6f'" %(cd_coupe/cd)
   print "Prob(type=sedan|rating=D) = '%.6f'" %(cd_sedan/cd)
   print "Prob(type=SUV|rating=D) = '%.6f'" %(cd_suv/cd)
if ce>0:
   print "Prob(type=coupe|rating=E) = '%.6f'" %(ce_coupe/ce)
   print "Prob(type=sedan|rating=E) = '%.6f'" %(ce_sedan/ce)
   print "Prob(type=SUV|rating=E) = '%.6f'" %(ce_suv/ce)
if cf>0:
   print "Prob(type=coupe|rating=F) = '%.6f'" %(cf_coupe/cf)
   print "Prob(type=sedan|rating=F) = '%.6f'" %(cf_sedan/cf)
   print "Prob(type=SUV|rating=F) = '%.6f'" %(cf_suv/cf)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote