Ayush File 1
Ayush File 1
Conduction of Program 10
Record Maintenance 5
Internal Viva 5
Total 25
PROGRAM - 1
Aim :To develop a machine learning model using Linear Regression for predicting house prices.
Objective: Perform EDA to analyze dataset patterns, preprocess data by handling missing values
and normalizing features, train a Linear Regression model, and evaluate accuracy.
Outcomes: Gain insights into housing price factors, develop a predictive regression model,
assess its accuracy using statistical metrics, and visualize predictions for better interpretation.
Dataset Used:The California Housing Dataset (from sklearn.datasets).
Program:-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import fetch_california_housing
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
# Correlation heatmap
plt.subplot(1, 2, 1)
sns.heatmap(df.corr(numeric_only=True), annot=True, cmap='coolwarm', fmt=".2f")
plt.title("Feature Correlation Heatmap")
# Distribution of Charges (Target)
plt.subplot(1, 2, 2)
sns.histplot(df['charges'], bins=30, kde=True, color='blue')
plt.title("Distribution of Medical Charges")
plt.tight_layout()
plt.show()
Program:
# Importing library
import pandas as pd
from sklearn.datasets import fetch_california_housing
from sklearn.linear_model import Ridge
from sklearn.model_selection import train_test_split
Program :
# Importing libraries
import pandas as pd
from sklearn.datasets import fetch_california_housing
from sklearn.linear_model import Lasso
from sklearn.model_selection import train_test_split
# Lasso Regression
lasso = Lasso()
# Training the Model
lasso.fit(X_train, y_train)
Program:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
# Making predictions
y_pred = model.predict(X_test)
# Model evaluation
Program:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
wine = datasets.load_wine()
X, y = wine.data, wine.target
feature_names = wine.feature_names
df = pd.DataFrame(X, columns=feature_names)
df['target'] = y
# Make predictions
y_pred = classifier.predict(X_test)
Program:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, f1_score, confusion_matrix, classification_report
# Make predictions
y_pred = knn_classifier.predict(X_test)
# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
print(f"KNN Accuracy: {accuracy:.2f}")
Aim: Build and evaluate an SVM classifier for on the Wine dataset.
Objective: Load and split the data, train an SVM with an RBF kernel, and evaluate
performance using accuracy, F1-score, confusion matrix, and classification report.
Outcome: Trained an SVM, achieved performance metrics, visualized and generated a
detailed classification report.the confusion matrix,
Dataset: Wine dataset from scikit-learn .
Program:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, f1_score, confusion_matrix, classification_report
# Make predictions
y_pred = svm_classifier.predict(X_test)
# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
print(f"SVM Accuracy: {accuracy:.2f}")
Aim: To implement and evaluate a Random Forest Classifier on the Iris dataset.
Objective: Train a Random Forest model using the Iris dataset, evaluate its performance using
accuracy and classification report, and interpret the results.
Outcome: Successfully trained a Random Forest model, achieved high classification accuracy,
and analyzed detailed class-wise performance metrics.
Dataset: Iris dataset from scikit-learn with 150 samples, 4 features (sepal/petal length & width),
and 3 classes of Iris flowers.
Program:
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.datasets import load_iris
Aim: To implement a feedforward neural network using the sigmoid activation function and
backpropagation algorithm to learn the XOR logical function.
Objective: Build and train a feedforward neural network with one hidden layer to learn the XOR
logic gate using sigmoid activation and gradient descent.
Outcome: Successfully trained a neural network to output correct XOR results through forward
and backpropagation.
Dataset: XOR truth table with 2 input features and 1 output (4 samples total).
Program :
import numpy as np
# Derivative of sigmoid
def sigmoid_derivative(x):
return x * (1 - x)
# Training process
epochs = 10000
learning_rate = 0.5
for _ in range(epochs):
# Forward propagation
hidden_layer_input = np.dot(X, weights_input_hidden)
hidden_layer_output = sigmoid(hidden_layer_input)
final_input = np.dot(hidden_layer_output, weights_hidden_output)
final_output = sigmoid(final_input)
# Backpropagation
error = y - final_output
d_output = error * sigmoid_derivative(final_output)
hidden_layer_error = d_output.dot(weights_hidden_output.T)
d_hidden_layer = hidden_layer_error * sigmoid_derivative(hidden_layer_output)
# Updating weights
weights_hidden_output += hidden_layer_output.T.dot(d_output) * learning_rate
weights_input_hidden += X.T.dot(d_hidden_layer) * learning_rate
print("Final Output after training:\n", final_output)
PROGRAM – 11
Aim: To implement a neural network using the Adam optimizer for binary classification tasks.
Objective: Build and compile a simple feedforward neural network with hidden layers using
the ReLU and Sigmoid activation functions. Use the Adam optimizer and binary cross-entropy
as the loss function.
Outcome: Successfully created and compiled a neural network model using TensorFlow Keras
and viewed its architecture using .summary().
Dataset: Dummy input shape assumed with 10 features for binary classification (actual data
loading not included).
Program:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Aim: To implement K-Means clustering algorithm for grouping data points into clusters based
on similarity.
Objective: Apply the K-Means algorithm to partition sample data into two clusters and print
the cluster labels and centers.
Outcome: Successfully applied K-Means clustering, obtained cluster assignments for data
points, and identified the cluster centers.
Dataset: Sample 2D data points used for clustering.
Program:
from sklearn.cluster import KMeans
import numpy as np
# Sample data
X = np.array([[1, 2], [2, 3], [3, 4], [10, 11], [11, 12], [12, 13]])