Quiz 14 - FDA
pdf
keyboard_arrow_up
School
Stony Brook University *
*We aren’t endorsed by this school
Course
572
Subject
Industrial Engineering
Date
Dec 6, 2023
Type
Pages
8
Uploaded by GrandIce91895
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
1/8
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 1 columns):
#
Column
Non-Null Count
Dtype
---
------
--------------
-----
0
Number of Tests
1000 non-null
int64
dtypes: int64(1)
memory usage: 7.9 KB
In [1]:
# Importing necessary libraries
import
pandas
as
pd
import
numpy
as
np
import
matplotlib.pyplot
as
plt
# Generating the dataset
np
.
random
.
seed
(
42
)
r
=
3
# Number of failures
p
=
0.2
# Probability of failure
data
=
np
.
random
.
negative_binomial
(
r
,
p
,
1000
)
# Generating data using negative binomial distribution
df
=
pd
.
DataFrame
(
data
,
columns
=
[
'Number of Tests'
])
# Display the first few rows of the dataframe
df
.
head
()
Out[1]:
In [2]:
df
.
info
()
In [3]:
df
.
describe
()
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
2/8
Out[3]:
In [4]:
# Plotting the histogram
plt
.
figure
(
figsize
=
(
10
,
6
))
plt
.
hist
(
df
[
'Number of Tests'
],
bins
=
20
,
color
=
'skyblue'
,
edgecolor
=
'black'
)
plt
.
title
(
'Distribution of Number of Tests Before Failure'
,
fontsize
=
15
)
plt
.
xlabel
(
'Number of Tests'
,
fontsize
=
12
)
plt
.
ylabel
(
'Frequency'
,
fontsize
=
12
)
plt
.
grid
(
axis
=
'y'
,
alpha
=
0.75
)
plt
.
show
()
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
3/8
In [5]:
mean_data
=
np
.
mean
(
data
)
var_data
=
np
.
var
(
data
)
In [6]:
p_estimated
=
mean_data
/
var_data
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
4/8
Estimated value of p: 0.21278292066823185
Probability of a device failing after more than 5 tests: 0.7681287870549661
In [7]:
from
scipy.stats
import
nbinom
# Calculating the probability of failure after more than 5 tests
prob_more_than_5_tests
=
nbinom
.
sf
(
5
,
r
,
p_estimated
)
print
(
"Estimated value of p:"
,
p_estimated
)
print
(
"Probability of a device failing after more than 5 tests:"
,
prob_more_than_5_tests
)
In [8]:
# Importing necessary libraries
import
pandas
as
pd
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
scipy.stats
import
gamma
# Generating the dataset using Gamma Distribution
np
.
random
.
seed
(
42
)
shape_parameter
=
2
scale_parameter
=
800
# Mean = shape * scale = 1600
data
=
np
.
random
.
gamma
(
shape_parameter
,
scale_parameter
,
1000
)
df_2
=
pd
.
DataFrame
(
data
,
columns
=
[
'Lifetime in Hours'
])
# Display the first few rows of the dataframe
df_2
.
head
()
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
5/8
Out[8]:
In [9]:
df_2
Out[9]:
In [10]:
df_2
.
info
()
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
6/8
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 1 columns):
#
Column
Non-Null Count
Dtype
---
------
--------------
-----
0
Lifetime in Hours
1000 non-null
float64
dtypes: float64(1)
memory usage: 7.9 KB
In [11]:
df_2
.
describe
()
Out[11]:
In [13]:
# Plotting the histogram
plt
.
figure
(
figsize
=
(
10
,
6
))
plt
.
hist
(
df_2
[
'Lifetime in Hours'
],
bins
=
20
,
color
=
'lightgreen'
,
edgecolor
=
'black'
)
plt
.
title
(
'Distribution of Lifetimes of Light Bulbs'
,
fontsize
=
15
)
plt
.
xlabel
(
'Lifetime in Hours'
,
fontsize
=
12
)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
7/8
plt
.
ylabel
(
'Frequency'
,
fontsize
=
12
)
plt
.
grid
(
axis
=
'y'
,
alpha
=
0.75
)
plt
.
show
()
In [14]:
# Calculating the sample mean and variance
mean_data_2
=
np
.
mean
(
data
)
var_data_2
=
np
.
var
(
data
)
11/2/23, 4:01 PM
Quiz 14
localhost:8889/nbconvert/html/Downloads/Quiz 14.ipynb?download=false
8/8
Estimated shape parameter: 2.1583043230324153
Estimated scale parameter: 763.5365389883217
Probability of a light bulb lasting more than 2000 hours: 0.3018148050158612
# Estimating the shape and scale parameters
shape_estimated_2
=
mean_data_2
**
2
/
var_data_2
scale_estimated_2
=
var_data_2
/
mean_data_2
# Calculating the probability of a light bulb lasting more than 2000 hours
prob_more_than_2000_hours_2
=
1
-
gamma
.
cdf
(
2000
,
a
=
shape_estimated_2
,
scale
=
scale_estimated_2
)
print
(
"Estimated shape parameter:"
,
shape_estimated_2
)
print
(
"Estimated scale parameter:"
,
scale_estimated_2
)
print
(
"Probability of a light bulb lasting more than 2000 hours:"
,
prob_more_than_2000_hours_2
)