Practical 1: Explore Different Types of Data
Program
import pandas as pd
data = pd.DataFrame({
"Student": ["A", "B", "C", "D"],
"Department": ["BCA", "BCA", "MCA", "BCA"], # Nominal
"Grade": ["A", "B", "A", "C"], # Ordinal
"Temperature_C": [20, 25, 30, 35], # Interval
"Age": [18, 19, 21, 22] # Ratio
})
print(data)
print("\nData types / scales:")
print("Department -> Nominal")
print("Grade -> Ordinal")
print("Temperature_C -> Interval")
print("Age -> Ratio")Practical 2: Data Cleaning — Missing Data, Imputation, Deletion and Normalization
Program
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
df = pd.DataFrame({
"Age": [18, 19, None, 21, 22],
"Marks": [65, 72, 80, None, 90]
})
print("Missing values:")
print(df.isnull().sum())
# Mean imputation
df_imputed = df.copy()
df_imputed["Age"] = df_imputed["Age"].fillna(df_imputed["Age"].mean())
df_imputed["Marks"] = df_imputed["Marks"].fillna(df_imputed["Marks"].mean())
# Min-Max normalization
scaler = MinMaxScaler()
df_imputed[["Age", "Marks"]] = scaler.fit_transform(df_imputed[["Age", "Marks"]])
print("\nCleaned and normalized data:")
print(df_imputed)Practical 3: Data Analysis and Exploration
Program
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
"StudyHours": [2, 3, 4, 5, 6, 7, 8],
"Marks": [45, 50, 58, 65, 70, 78, 85]
})
print(df.head())
print("\nSummary statistics:")
print(df.describe())
print("\nCorrelation:")
print(df.corr(numeric_only=True))
plt.scatter(df["StudyHours"], df["Marks"])
plt.xlabel("Study Hours")
plt.ylabel("Marks")
plt.title("Study Hours vs Marks")
plt.show()Practical 4: Linear Regression — Simple and Multiple
Program
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
df = pd.DataFrame({
"Hours": [2,3,4,5,6,7,8,9],
"Attendance": [70,72,75,78,80,84,88,90],
"Marks": [45,50,56,62,68,74,81,88]
})
X = df[["Hours", "Attendance"]] # Multiple regression
y = df["Marks"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42
)
model = LinearRegression()
model.fit(X_train, y_train)
pred = model.predict(X_test)
print("Coefficients:", model.coef_)
print("Intercept:", model.intercept_)
print("MSE:", mean_squared_error(y_test, pred))
print("R2:", r2_score(y_test, pred))