Question

In: Statistics and Probability

Imagine you have a 6-class classification problem, where the dataset contains 9 input features. You decide...

Imagine you have a 6-class classification problem, where the dataset contains 9 input features. You decide to build a classifier using a “mixture of mixtures”, i.e. using a Gaussian mixture model for each likelihood (p(x|θ)). 3 mixture components are used with diagonal covariance matrices for each mixture model. Calculate the total number of model parameters in the classifier (do not consider priors).

Solutions

Expert Solution

problem1_3.py

import   sys
import   csv

def main():
  
   if len(sys.argv) != 3:
       print("Usage: python3 problem1_3.py [input_file] [output_file]")
       return
  
   sign = lambda x: (1,-1)[x<=0]
  
   ifile = open(sys.argv[1],'rt')
   reader = csv.reader(ifile)
  
   ofile = open(sys.argv[2],'wt')
   writer = csv.writer(ofile)
  
   b = 0
   w1 = 0
   w2 = 0
  
   b_o = -1
   w1_o = -1
   w2_o = -1
  
   while b != b_o or w1 != w1_o or w2 != w2_o:
      
       b_o = b
       w1_o = w1
       w2_o = w2
  
       ifile.seek(0)
  
       for row in reader:
           x1 = int(row[0])
           x2 = int(row[1])
           y = int(row[2])
          
           f = sign(b + w1*x1 + w2*x2)
      
           if y*f <= 0:
                   b += y
                   w1 += y*x1
                   w2 += y*x2
      
       row = [w1, w2, b]
      
       writer.writerow(row)
  
   ifile.close()
   ofile.close()
  
  
if __name__ == '__main__':
   main()
  
   problem2_3.py
  

import   sys
import   csv
import    numpy as np

def main():
  
   if len(sys.argv) != 3:
       print("Usage: python3 problem2_3.py [input_file] [output_file]")
       return
  
   ifile = open(sys.argv[1],'rt')
   reader = csv.reader(ifile)
  
   n = 0
  
   x1 = []
   x2 = []
   y = []
  
   for row in reader:
       n += 1
       x1.append(float(row[0]))
       x2.append(float(row[1]))
       y.append(float(row[2]))
  
   ifile.close()
  
   x1 = (x1 - np.mean(x1)) / np.std(x1)
   x2 = (x2 - np.mean(x2)) / np.std(x2)
  
   ofile = open(sys.argv[2],'wt')
   writer = csv.writer(ofile)
  
   for a in [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10]:
      
       b = [0, 0, 0]
      
       for i in range(0,100):
          
           s = [0, 0, 0]
          
           for k in range (0,n):
              
               d = b[0] + b[1]*x1[k] + b[2]*x2[k] - y[k]
               s[0] += d
               s[1] += d * x1[k]
               s[2] += d * x2[k]
          
           b[0] -= a * s[0] / n
           b[1] -= a * s[1] / n
           b[2] -= a * s[2] / n
      
       row = [a, 100, b[0], b[1], b[2]]
      
       writer.writerow(row)
  
   a = 1
   b = [0, 0, 0]
  
   for i in range(0,20):
      
       s = [0, 0, 0]
      
       for k in range (0,n):
          
           d = b[0] + b[1]*x1[k] + b[2]*x2[k] - y[k]
           s[0] += d
           s[1] += d * x1[k]
           s[2] += d * x2[k]
      
       b[0] -= a * s[0] / n
       b[1] -= a * s[1] / n
       b[2] -= a * s[2] / n
  
   row = [a, 20, b[0], b[1], b[2]]
  
   writer.writerow(row)
  
   ofile.close()
  
  
if __name__ == '__main__':
   main()


Related Solutions

Imagine you have a patient who has a ASA Class 3 classification: Type 1 Diabetes and...
Imagine you have a patient who has a ASA Class 3 classification: Type 1 Diabetes and Mild Angina. Identify which pre-surgical clearance tests you will order and explain why. Using Table 21-4, determine whether your patient may proceed to surgery. Remember, this is a hypothetical situation. You determine whether this is emergent or not—in other words, you choose your ending, but you need to be able to defend your selection in 250 words or less.
Imagine a scenario where you decide to start a firm in a specific industry. Please detail...
Imagine a scenario where you decide to start a firm in a specific industry. Please detail how your firm will evolve from creation towards the long run. Do so in the context of the 4 time frames we learned about in this class. You can use hypothetical numbers to illustrate any points you wish. Also, it would help to be specific about the type of industry you are in and think about the evolution of your firm within that specific...
Imagine the following scenario where you need to decide which MUTUALLY-EXCLUSIVE project to pursue: You are...
Imagine the following scenario where you need to decide which MUTUALLY-EXCLUSIVE project to pursue: You are given $50,000 to invest in one of the following two projects (you CANNOT invest in both). 200-500 words Project A: A highly respectable local entrepreneur reaches out to you for a short-term loan of $10,000 guaranteeing a return of $16,000 in 15 days ($6,000 of profit). The situation is unusual as her customers lost their financing source and will need about 2 weeks to...
Imagine that you have decided to acquire your dream car.  You now have to decide whether to...
Imagine that you have decided to acquire your dream car.  You now have to decide whether to buy or lease that car. Write a report specifying the differences between leasing and buying your dream car and make a decision on whether to buy or lease. In writing your report you must do the following: Gather the terms under which you would lease the car, such as the necessary down payment amount and monthly payment amount. Calculate the total costs when leasing...
A box contains 9 two-inch screws, of which 6 have a Phillips head and 3 have...
A box contains 9 two-inch screws, of which 6 have a Phillips head and 3 have a regular head. Suppose that you select 3 screws randomly from the box with replacement. 1) Find the probability there will be more than one Phillips head screw ? According to a recent report, 60% of U.S. college graduates cannot find a full time job in their chosen profession. Assume 73% of the college graduates who cannot find a job are female and that...
(Econometrics) Imagine you have a large dataset containing 12 variables on 5000 individuals over 12 year...
(Econometrics) Imagine you have a large dataset containing 12 variables on 5000 individuals over 12 year period. Individuals are interviewed annually and their income, assets, age, race, marriage status, sex, education level, mother's education, father's education, food expenditure, religion, and annual vacation spending are recorded. A) If you are trying to build a model predicting vacation spending what model would you build? B) Explain where you would prefer fixed effect vs random effects model. C) Should you worry about endogeneity?...
Problem 1 Imagine that you walk into some class on the Thursday morning after Mardi Gras...
Problem 1 Imagine that you walk into some class on the Thursday morning after Mardi Gras break and are surprised to discover that a ten-question, multiple choice quiz is being conducted. You have not studied for this quiz, so you decide to answer the questions randomly. Determine the following: a) If each question has four possible responses (a, b, c, or d), then how many possible ways can you respond to the quiz? b) How probable is it that you...
I am trying to solve a c++ problem over c strings where I have to input...
I am trying to solve a c++ problem over c strings where I have to input an email address and check if it is valid. After completing my code I keep getting errors that my program will not run, specifically the lines with my for loops. Can you please look at my code and tell me what is wrong and how I can fix the code? I included below the assignment instructions and my current code. Assignment Instructions Write a...
Imagine that you are a risk manager in any company. Assume that you have 6 causes...
Imagine that you are a risk manager in any company. Assume that you have 6 causes of loss, which need strategies for each cause. Mention in details with examples the process of your managing those risks.
Suppose you have a STAT class from 8:30–9:30 and an ECON class from 9:30–10:30. Assuming you...
Suppose you have a STAT class from 8:30–9:30 and an ECON class from 9:30–10:30. Assuming you arrive to school at 8:30 with zero text messages on your cell phone and you receive 6 texts every 45 minutes on average, find the following probabilities. a)Based on the information above, find the probability that you receive at least 3 texts during your STAT class. N.B. I suggest you find these in R studio. b)find the probability that you receive exactly 3 texts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT