FDA_BATCH2PROGRAM
FDA_BATCH2PROGRAM
import numpy as np
OUTPUT
[Program finished]
EXNO2
import numpy as np
# d) Find the maximum and minimum value from a shape (3,3) array
arr3 = np.array([[4, 9, 1], [7, 3, 6], [8, 2, 5]])
print("d) Maximum value:", np.max(arr3))
print(" Minimum value:", np.min(arr3))
OUTPUT
a) Appended Array: [1 2 3 4 5]
b) Real parts: [1. 3. 5.]
Imaginary parts: [2. 4. 6.]
c) Second column elements: [2 5 8]
d) Maximum value: 9
Minimum value: 1
[Program finished]
EXNO3
import numpy as np
from scipy import stats
# Marks of 20 students
marks = [75, 80, 85, 90, 70, 88, 76, 92, 81, 78,
84, 79, 77, 83, 86, 82, 74, 89, 91, 87]
OUTPUT
Z-Test Result:
Z-Score = 2.1019038988497973
T-Test Result:
T-Score = 1.6948633480403503
P-Value = 0.10642890850820598
[Program finished]
EXNO4
from scipy.stats import f_oneway
# Perform ANOVA
f_statistic, p_value = f_oneway(class_A, class_B, class_C)
# Output results
print("ANOVA Test Results:")
print(f"F-statistic: {f_statistic:.3f}")
print(f"P-value: {p_value:.5f}")
# Interpretation
if p_value < 0.05:
print("Result: Significant difference between at least two groups.")
else:
print("Result: No significant difference between groups.")
OUTPUT
ANOVA Test Results:
F-statistic: 5.254
P-value: 0.01155
Result: Significant difference between at least two groups.
[Program finished]
EXNO5
import pandas as pd
import numpy as np
# 1. Create DataFrame from NumPy array
array_data = np.array([[1, 2, 3], [4, 5, 6]])
df_array = pd.DataFrame(array_data, columns=['A', 'B', 'C'])
print("DataFrame from NumPy array:")
print(df_array)
OUTPUT
DataFrame from NumPy array:
A B C
0 1 2 3
1 4 5 6
[Program finished]
EXNO6
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Create a 2x2 subplot grid
fig, axs = plt.subplots(2, 2, figsize=(10, 8))
# Line Plot
axs[0, 0].plot(x, y)
axs[0, 0].set_title("Line Plot")
# Bar Chart
axs[0, 1].bar(x, y)
axs[0, 1].set_title("Bar Chart")
# Scatter Plot
axs[1, 0].scatter(x, y)
axs[1, 0].set_title("Scatter Plot")
# Adjust layout
plt.tight_layout()
plt.show()
OUTPUT
EXNO7
import numpy as np
import pandas as pd
def calculate_variance(data):
# Convert input to NumPy array for consistency
data_array = np.array(data, dtype=float)
return np.var(data_array, ddof=1) # ddof=1 for sample variance
OUTPUT
Variance from list: 27.428571428571427
Variance from NumPy array: 2.8520000000000003
Variance from Pandas Series: 8.266666666666667
[Program finished]
EXNO8
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
# Your data
data = [5, 7, 8, 9, 10, 11, 12, 13, 15, 18]
mean = np.mean(data)
std = np.std(data)
plt.plot(x, y)
plt.title('Normal Curve from Your Data')
plt.show()
OUTPUT
EXNO9
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(50)
y = [x*5+3, -5*x, np.random.randn(50)]
c = ['green', 'red', 'blue']
l = ['Positive', 'Negative', 'Zero']
plt.xlabel("X-axis"); plt.ylabel("Y-axis")
plt.title("Correlation and Scatter Plots")
plt.legend()
plt.grid()
plt.show()
OUTPUT
EXNO10
import numpy as np
# Given data
X = [15, 18, 21, 24, 27]
Y = [25, 25, 27, 31, 32]
OUTPUT
Correlation Coefficient: 0.9534625892455922
[Program finished]
EXNO11
import numpy as np
import matplotlib.pyplot as plt
# Data
X = np.array([1, 2, 3.4, 5.6, 7, 8, 9, 10])
Y = np.array([3, 2, 5, 7, 8, 8, 9, 10])
# Predicted Y values
Y_pred = m * X + b
# Plot
plt.scatter(X, Y, color='blue', label='Data')
plt.plot(X, Y_pred, color='red', label='Regression Line')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Simple Linear Regression')
plt.legend()
plt.grid(True)
plt.show()
OUTPUT
EXNO12
# Predict
prediction = model.predict([[6]])
print("Predicted value for 6:", prediction[0])
# Model details
print("Slope:", model.coef_[0])
print("Intercept:", model.intercept_)
OUTPUT
[Program finished]
EXNO13
import pandas as pd
import numpy as np
# Corrected dictionary
exam_data = {
'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily',
'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no',
'yes', 'yes', 'no', 'no', 'yes']
}
# Create DataFrame
df = pd.DataFrame(exam_data, index=labels)
OUTPUT
name score attempts qualify
a Anastasia 12.5 1 yes
b Dima 9.0 3 no
c Katherine 16.5 2 yes
d James NaN 3 no
e Emily 9.0 2 no
f Michael 20.0 3 yes
g Matthew 14.5 1 yes
h Laura NaN 1 no
i Kevin 8.0 2 no
j Jonas 19.0 1 yes
[Program finished]
EXNO14
import numpy as np
# Original dictionary
data = {
'column0': {'a':1, 'b':0.0, 'c':0.0, 'd': 2.0},
'column1': {'a':3.0, 'b':1, 'c':0.0, 'd': -1.0},
'column2': {'a':4, 'b':1, 'c':5.0, 'd': -1.0},
'column3': {'a':3.0, 'b': -1.0, 'c': -1.0, 'd': -1.0}
}
print("Original dictionary:")
print(data)
print("Type:", type(data))
# Build list of lists: rows correspond to keys, columns correspond to the dictionary keys
array_data = [[data[col][k] for col in data] for k in keys]
print("\nndarray:")
print(nd_array)
print("Type:", type(nd_array))
OUTPUT
Original dictionary:
{'column0': {'a': 1, 'b': 0.0, 'c': 0.0, 'd': 2.0}, 'column1': {'a': 3.0, 'b': 1, 'c': 0.0, 'd': -1.0},
'column2': {'a': 4, 'b': 1, 'c': 5.0, 'd': -1.0}, 'column3': {'a': 3.0, 'b': -1.0, 'c': -1.0, 'd': -1.0}}
Type: <class 'dict'>
ndarray:
[[ 1. 3. 4. 3.]
[ 0. 1. 1. -1.]
[ 0. 0. 5. -1.]
[ 2. -1. -1. -1.]]
Type: <class 'numpy.ndarray'>
[Program finished]
EXNO15
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report
X = [[2,3],[1,5],[2,8],[5,2],[6,1],[7,3],[8,5],[7,7],[8,8],[9,7]]
y = [0,0,0,1,1,1,1,1,1,1]
OUTPUT
Accuracy: 100.00%
Classification Report:
precision recall f1-score support
accuracy 1.00 2
macro avg 1.00 1.00 1.00 2
weighted avg 1.00 1.00 1.00 2
[Program finished]
EXNO16
import pandas as pd
# Sample DataFrame
data = {
'col1': [0, 1, 2, 3, 4],
'col2': [1, 2, 3, 4, 7],
'col3': [4, 5, 6, 9, 1]
}
df = pd.DataFrame(data)
print("Original DataFrame")
print(df)
# Select all columns except 'col3'
df_except_col3 = df.loc[:, df.columns != 'col3']
OUTPUT
Original DataFrame
col1 col2 col3
0 0 1 4
1 1 2 5
2 2 3 6
3 3 4 9
4 4 7 1
[Program finished]
EXNO17
import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
import matplotlib.pyplot as plt
OUTPUT
EXNO18
import pandas as pd
import matplotlib.pyplot as plt
# Sample data
data = [12, 15, 14, 15, 19, 21, 18, 17, 16, 15, 14, 19, 22, 24, 25, 21, 23, 20]
# Create a DataFrame
df = pd.DataFrame(data, columns=['Values'])
OUTPUT
EXNO19
import numpy as np
# Define three NumPy arrays with the same shape
array1 = np.array([[1, 2], [3, 4]])
array2 = np.array([[5, 6], [7, 8]])
array3 = np.array([[9, 10], [11, 12]])
OUTPUT
Merged Array:
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[ 9 10]
[11 12]]]
[Program finished]
EXNO20
import pandas as pd
import numpy as np
data = {
'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily',
'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9.0, 16.5, np.nan, 9.0, 20.0, 14.5, np.nan, 8.0, 19.0],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']
}
df = pd.DataFrame(data, index=list('abcdefghij'))
print("Number of attempts in the examination is greater than 2:")
print(df[df.attempts > 2])
OUTPUT
Number of attempts in the examination is greater than 2:
name score attempts qualify
b Dima 9.0 3 no
d James NaN 3 no
f Michael 20.0 3 yes
[Program finished]