/ Published in: Python

asdfasd

Expand |
Embed | Plain Text

# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ #Assignment 1 from __future__ import division import random from scipy import * from math import * #1.1) import numpy as np poisson_lambda = 4 s = np.random.poisson(poisson_lambda,50) #1.2) mean = 0 for i in s: mean = mean + i mean = mean/len(s) #<--------- APROX. MEAN mean2 = 0 s_square = s**2 for i in s_square: mean2 = mean2 + i mean2 = mean2/len(s_square) variance = mean2 - mean**2 #<------ APROX VARIANCE #1.3) print 'Calculated mean: '.__add__(str(mean)) print 'Calculated variance: '.__add__(str(variance)) print 'Theoretical mean: '.__add__(str(poisson_lambda)) print 'Theoretical variance: '.__add__(str(poisson_lambda)) #Theoretically, lambda is the value for both the mean and variance of a Poisson # distribution. The fact that the number of observations is not very high #suggests that the approximation calculated in 1.4 won't be very accurate. #If the number of observations was greater, the aproximation would be better #1.4) from collections import Counter cnt = Counter() for i in s: cnt[i] += 1 cnt #1.5) import matplotlib.pyplot as plt d = dict(cnt) #from Counter() to dictionary plt.bar(range(len(d)),d.values()) plt.title('Bar plot of frequencies of observed values') plt.xlabel('Observed values') plt.ylabel('Number of occurrences') plt.show() #1.6) import matplotlib.pyplot as plt2 poisson_pmf = [x for x in range(14)] #initialization #I am going to create manually a poisson distribution of 14 elements for i in range(14): poisson_pmf[i] = (((poisson_lambda)**i)*(e**(-poisson_lambda)))/factorial(i) plt2.bar(range(len(poisson_pmf)),poisson_pmf) plt2.title('Bar plot of the poisson distribution between range [0,13]') plt2.xlabel('Observed values') plt2.ylabel('Magnitude') plt2.show() #1.7) from scipy import stats a = stats.ttest_1samp(s,2.0) b = stats.ttest_1samp(s,3.7) c = stats.ttest_1samp(s,4.3) #Assignment 2 #2.1) import numpy as np2 X1 = np2.random.exponential(5.0,100) X2= np2.random.exponential(5.0,100) #2.2) Y = [x for x in range(100)] for i in range(100): if X1[i]*X2[i]<=30+random.normal(0,100): Y[i] = 'Blue' else: Y[i] = 'Orange' #2.3) import matplotlib.pyplot as plt3 plt3.scatter(X1,X2,c=Y) plt3.xlabel('X1 values') plt3.ylabel('X2 values') plt3.title('Scatter plot of X1 vs X2') plt3.show() #2.4) X1X2 = zip(X1,X2) #2.5) from sklearn import svm #a) clf = svm.SVC(kernel='linear') clf.fit(X1X2, Y) #b) clf2 = svm.SVC(kernel='rbf', gamma=0.7) clf2.fit(X1X2, Y) #2.6) #For the linear kernel: linear_prediction = clf.predict(X1X2) #For the rbf kernel: rbf_prediction = clf2.predict(X1X2) #2.7) #For the linear kernel import matplotlib.pyplot as plt4 plt4.scatter(X1,X2,c=linear_prediction) plt4.xlabel('X1 values') plt4.ylabel('X2 values') plt4.title('Linearly predicted scatter plot of X1 vs X2') plt4.show() #For the rbf kernel: import matplotlib.pyplot as plt5 plt5.scatter(X1,X2,c=rbf_prediction) plt5.xlabel('X1 values') plt5.ylabel('X2 values') plt5.title('RBF-predicted scatter plot of X1 vs X2') plt5.show()

## Comments

Subscribe to commentsYou need to login to post a comment.

Thanks for the code. Now I will type my essay fast with your help. I have been looking for this peace of code, without that I cannot finish my program.

Extremely intriguing book to peruse, I have just perused two books of this Buy an Essay Online. He is better than average at composing, so far his books are among my top choices.

Check the reviews of instantassignmenthelp before assignment help.

Hi itskate, can you help me with my essay

Best one to share! Org

Homework, or a homework task, is an arrangement of errands doled out to understudies by their instructors to be finished outside the class. Normal homework assignments may incorporate required perusing, a composition or writing venture, numerical activities to be finished, data to be explored before a test, or different aptitudes to be rehearsed. vehicle graphics dubai

Thanks for sharing the code. It work like anything.

Assignment Help

Feeling down throughout the week? Is the idea of writing a due project making you cringe? Itâ€™s nothing to feel ashamed of, we have all been there! Dump your project on my homework help programming homework help and forget about it. Maybe go to a barbeque party in the sun to lift yourself up. We all deserve a break sometimes. Comment on this post if you feel the same way.

My Assignment Services is a well-established and prominent name in providing high-quality assignment help online to students since almost a decade. You can trust our academic ghostwriters completely to get best quality write-ups including case studies, research proposals, dissertations and theses, and more. It is the best do my assignment provider.Students should always keep themselves ready to meet the university requirements in order to achieve good grades, moreover, they prefer attending lengthy classes instead of writing assignments. Students who are not comfortable with writing assignments can avail university assignment help by myob assignment help at My Assignment Services comparatively low prices.

You can rent Singapore expert writers to ensure top quality cheap essay writing service singapore. Singapore is known for a system of quality control before the assignment is delivered. We examine plagiarism on each assignment to ensure that they are 100% literary and error free.

The professional report writing help ireland writer at IrelandAssignmentHelp.com is well-versed with all the academic writing styles and format your assignment in any of the styles that students ask for such as MLA, APA, Harvard, Oxford, Chicago, Vancouver or any other.

Being a law student it is very difficult for me to invest a lot of time on other things, so when it comes to writing an assignment it becomes very challenging for me. Writing an assignment is a lot of work. We need to do a lot of research work and also write a lot of pages which is very time-consuming. So, I started searching for help and found the Business law assignment help australia. I was assisted by a professional with the assignment and the assignment that was delivered to me fetched me really good grades. I am highly satisfied with the assistance that was offered to me. Pay Someone To Do Your Assignment australia