0% found this document useful (0 votes)
16 views5 pages

Ex No 4 A

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Ex No 4 A

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EX NO-4 A

PROBABILITY DENSITY FUNCTION USING NORMAL


DATE DISTRIBUTION

AIM:

To visualize the probability density function of the normal distribution for IQ scores,
specifically highlighting the area between defined lower and upper bounds, and to
calculate the cumulative probability of a specific IQ value.

ALGORITHM:

1. Define Parameters:

• Set the mean (mean) to 100 and standard deviation (std_dev) to 15, reflecting
typical IQ distribution characteristics.

2. Create IQ Range:

• Generate a range of IQ values from 0 to 200 using np.linspace, creating an


array of 1000 evenly spaced points.

3. Define Bounds for Shaded Area:

• Specify lower and upper bounds for the shaded area (e.g., 75 and 100).

4. Calculate the PDF:

• Use scipy.stats.norm.pdf to calculate the probability density function for the IQ


range based on the defined normal distribution parameters.

5. Plot the PDF:

• Use matplotlib.pyplot to plot the PDF against the IQ range.

6. Highlight Shaded Area:

• Fill the area under the curve between the lower and upper bounds using
plt.fill_between.

7. Add Reference Lines:

• Draw vertical lines to indicate the lower and upper bounds using plt.axvline.

8. Label the Plot:

• Add a title, x-label, y-label, and a legend to the plot for clarity.

9. Calculate Probability for a Specific IQ Value:


• Prompt the user to enter an IQ value and calculate the cumulative probability
using scipy.stats.norm.cdf.

10. Display the Probability:

• Print the calculated probability to the console.

PROGRAM:

import numpy as np

import matplotlib.pyplot as plt

import scipy.stats as stats

# Define the parameters for the normal distribution (IQ typically has a mean of 100
and std deviation of 15)

mean = 100

std_dev = 15

# Define the IQ range (0, 200) as given in the question

iq_range = np.linspace(0, 200, 1000)

# Define the lower and upper bounds for the shaded area

lower_bound = 75

upper_bound = 100

# Create the PDF for the normal distribution

pdf = stats.norm.pdf(iq_range, mean, std_dev)

# Plot the PDF

plt.plot(iq_range, pdf, label="Probability")

# Fill the area between the lower and upper bounds

plt.fill_between(iq_range, pdf, where=(iq_range >= lower_bound) & (iq_range <=


upper_bound),color='blue', alpha=0.3)

# Add lines to mark the lower and upper bounds

plt.axvline(lower_bound, color='green', linestyle='--', label="Lower limit")

plt.axvline(upper_bound, color='red', linestyle='--', label="Upper limit")

# Add titles and labels


OUTPUT:
plt.title('Normal Distribution of IQ')

plt.xlabel('IQ')

plt.ylabel('Probability Density')

# Add a legend

plt.legend()

# Show the plot

plt.show()

# Calculate the probability of an IQ level of 90

print("Enter the IQ_Value:",iq_value)

probability = stats.norm.cdf(iq_value, mean, std_dev)

print(f'The probability of an IQ of {iq_value} is {probability}')

RESULT:

The code visualizes the probability density function (PDF) of IQ scores


and also highlighting the area. It also calculates the cumulative probability of a
specified IQ value, allowing users to understand the likelihood of scoring below that
IQ in relation to the normal distribution.

You might also like