# Basics of Statistics and Probability Fresco Play Handson Solutions

## Course Path: Data Science/DATA SCIENCE BASICS/Basics of Statistics and Probability

Suggestion: Just Copy whole code from below and replace with existing code on hacker rank.

1.Welcome to Probability and Statistics -1

Permutations and Combinations – Hands-on

import numpy as np

from scipy import stats

import statistics

def measures(arr):

``````#Write your code here

'''

Input: arr : numpy array

Return : mean,median,std_deviation,variance,mode,iqr  : float

Note:

1. Assign the values to designated variables

2. Round off to 2 decimal places

'''

mean=round(np.mean(arr),2)

median=round(np.median(arr),2)

std_deviation=round(np.std(arr),2)

variance=round(np.var(arr),2)

mode=round(statistics.mode(arr),2)

iqr=round(stats.iqr(arr),2)

return mean,median,std_deviation,variance,mode,iqr   ``````

if name==’main‘:

2.Welcome to Probability and Statistics -2

Combinations with Factorial – Hands-on

from itertools import combinations

from itertools import permutations

import numpy as np

import math

def comb_perm(arr):

``````#Write your code here

'''

Input: arr : numpy array

Return : no_of_comb,no_of_perm : Integer

'''

no_of_comb= len(list(combinations(arr,2)))

no_of_perm= len(list(permutations(arr,2)))

return no_of_comb,no_of_perm``````

if name==’main‘:

3.Welcome to Probability and Statistics -3

Statistics

import math

def dancers():

``````'''

output: ans : Integer

'''

#Write your code here

#Assign your value to variable ans

ans= 200

return int(ans)``````

if name==’main‘:

4.Welcome to Probability and Statistics -4

Mutually Exclusive Events

from scipy import stats

def binomial():

``````'''

output: ans : Float

'''

#Write your code here

#Assign the probability value to the variable ans

#Round off to 2 decimal places

ans = 0.97

return ans``````

if name==’main‘:

5.Welcome to Probability and Statistics -5

Non-mutually Exclusive Events

from scipy import stats

def poisson():

``````'''

output: ans : Float

'''

#Write your code here

#Assign the probability value to the variable ans

#Round off to 2 decimal places

ans= 0.03

return ans``````

if name==’main‘:

6.Welcome to Probability and Statistics -6

Binomial – Hands-on

from scipy import stats

def spinner():

``````'''

output: ans : Float

'''

#Write your code here

#Assign the probability value to the variable ans

# Round off to 2 decimal places

ans= 0.5

return ans ``````

if name==’main‘:

7.Welcome to Probability and Statistics -7

Poisson – Hands-on

from scipy import stats

def accident():

``````'''

output: ans : Float

'''

#Write your code here

#Assign the probability value to the variable ans. Round off to 2 decimal places

ans= 0.26

return ans``````

if name==’main‘:

8.Welcome to Probability and Statistics -8

Chi-squared Test – Hands-on

from scipy.stats import chi2_contingency

from scipy.stats import chi2

def chi_test():

``````'''

Output

1. stat: Float

2. dof : Integer

3. p_val: Float

4. res: String

'''

#Note: Round off the Float values to 2 decimal places.

stat= 23.57

dof= 12

p_val= 0.02

res= "Reject the Null Hypothesis"

return stat,dof,p_val,res   ``````

if name==’main‘:

Please let us know if you find it useful, It was just provided so that you can use for knowledge purpose and solve any issue during your training . Learn more Questions on basics-of-statistics-and-probability 