Question

In: Computer Science

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

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

Solutions

Expert Solution

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)


Related Solutions

Name your source code file sh.c Write your own simple shell. Your shell should prompt the...
Name your source code file sh.c Write your own simple shell. Your shell should prompt the user for a command, run it, then prompt the user for their next command. If the user types "exit", then the shell should terminate. The shell should ignore Ctrl-C. Inside the attached parse.h header file, there is a parse function that you can use to split up the command line into separate strings. Recall that execvp accepts two arguments: the name of the command,...
A text editor window should pop up with the following source code (except with your actual name):
  A text editor window should pop up with the following source code (except with your actual name): csci1011.lab8;/**** @author Your Name*/public class Account {} Implement the Account class. Add a public enum called ACCOUNT_TYPE with two values CHECKING, SAVING Add the following private instance variables to the Account class: An instance variable called aType of type Enum ACCOUNT_TYPE. An instance variable called accountOwner of type String. An instance variable called interestRate of type double. An instance variable called balance...
Modify the original code and add an additional function of your choice. The function should be...
Modify the original code and add an additional function of your choice. The function should be unique and something you created for this assignment. Support your experimentation with screen captures of executing the new code. Prepare a test table with at least 3 distinct test cases listing input and expected output for your unique function. #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x...
In order to run for the Office of the President should their be additional job requirements?...
In order to run for the Office of the President should their be additional job requirements? Name at least three that you think would be important and why?In order to run for the Office of the President should their be additional job requirements? Name at least three that you think would be important and why?
Explain in your own words the requirements an indeterminate structure should satisfy and name the methods...
Explain in your own words the requirements an indeterminate structure should satisfy and name the methods used to analyse indeterminate structures.
check the following code: is the requirements correct ? if not solve it . All the...
check the following code: is the requirements correct ? if not solve it . All the styles must be in a document style sheet. YOU ARE NOT ALLOWED TO USE THE type ATTRIBUTE ON THE LIST, you must use CSS to apply the style. <!DOCTYPE html> <html> <head> <title> car list</title> <style> body {background-color: powderblue;} h1   {color: blue;} p    {color: red;} </style> </head> <body> <style type="text/css"> ol{list-style-type:upper-roman;} ol ol{list-style-type:upper-alpha;} ol ol ol{list-style-type:decimal;} li.compact{background-color:pink;} li.midsize{background-color:blue;} li.sports{background- color:red;} ol.compact{background-color:pink;} ol.midsize{background-color:blue;} ol.sports{background-color:red;} </style>...
Write a program (your choice!) that fulfills all the requirements below. The final product should include...
Write a program (your choice!) that fulfills all the requirements below. The final product should include the pseudocode and flowchart for the entire program. Variables of each data type String, Integer, Real, Boolean Must contain at least one type of calculation Minimum of 3 modules/functions At least 2 decision structures IF, IF-ELSE, IF-ELSE IF At least 1 type of loop WHILE or FOR At least 1 array/list
Write the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
All Code should be written in C: 1. A perfect number is defined as a number...
All Code should be written in C: 1. A perfect number is defined as a number whose proper divisors (factors not including the number itself) add up to the same number. For example, 28 is a perfect number because its perfect divisors are 1, 2, 4, 7, 14, which add up to 28. Write a C function called is_perfect that takes a since integer as input, and returns 1 if the number is perfect, or 0 otherwise. 2. Using the...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document your code and properly label the input prompts and the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT