0% found this document useful (0 votes)
8 views17 pages

27 KrishParasShah

The document outlines a series of assignments for a Machine Learning Lab conducted by Krish Paras Shah at VES Institute of Technology. Each assignment involves writing Python programs to implement various machine learning techniques, including statistical analysis, linear regression, logistic regression, k-means clustering, hierarchical clustering, artificial neural networks, and support vector machines. The assignments emphasize the use of SPYDER and include code snippets and theoretical explanations for each method.

Uploaded by

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

27 KrishParasShah

The document outlines a series of assignments for a Machine Learning Lab conducted by Krish Paras Shah at VES Institute of Technology. Each assignment involves writing Python programs to implement various machine learning techniques, including statistical analysis, linear regression, logistic regression, k-means clustering, hierarchical clustering, artificial neural networks, and support vector machines. The assignments emphasize the use of SPYDER and include code snippets and theoretical explanations for each method.

Uploaded by

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

Machine Learning Lab (Assignment-01)

Name of the student: Krish Paras Shah Roll No. 27

Division: D13 (A.Y. 2024-25) Date: 20-02-


2025

Task Given: Write a python program to read a csv file and determine mean, variance
and standard deviation of the given data set. Use SPYDER only.
VES Institute of Technology
Department of Automation and Robotics

Machine Learning Lab (Assignment-02)

Name of the student: Krish Paras Shah Roll No. 27

AIM: Write a python program to determine mean, variance and standard deviation.

CODE:
import pandas as pd import numpy as np file_path =
'data_set.csv' df = pd.read_csv(file_path)
column_name = 'age' mean =
df[column_name].mean() variance =
df[column_name].var() std_dev =
df[column_name].std() print(f"Mean of
'{column_name}': {mean}") print(f"Variance of
'{column_name}': {variance}") print(f"Standard
Deviation of '{column_name}': {std_dev}")

OUTPUT:
VES Institute of Technology

Department of Automation and Robotics

Machine Learning Lab (Assignment-03)

Name of the student: Krish Paras Shah Roll No. 27

Division: D13 (A.Y. 2024-25) Date: 20-02-


2025

Task Given: Write a python program to implement linear regression with one
variable for the given data set (without using python libraries). Use SPYDER only.

Program Code:

X = [1, 2, 3, 4, 5, 6]
Y = [2, 4, 5, 4, 5, 7]

Line is of the form:


Y= (b1)X + b0
Output:
VES Institute of Technology

Department of Automation and Robotics

Machine Learning Lab

(Assignment-04)

Name of the student: Krish Paras Shah Date: 20 March 2025

Task Given: Write a python program to perform multivariate linear regression. Use
SPYDER only.

Theory:

Multivariate Linear Regression or multiple regression is an extension of simple linear


regression where multiple independent variables are used to predict the dependent
variable. It models the relationship between multiple features and an outcome using a
linear equation.

The equation for multiple regression is given by:

Y = β0 + β1X1 + β2X2 + ⋯ + βnXn

where Y is the dependent variable

Xi are independent variables

β1, β2, …, βn are regression coefficients

β0 is Y-intercept

Given Data Set:

X1 = [1, 2, 6, 8, 15]

X2 = [ 12, 3,14, 15, 6]

Y = [23, 36, 57, 10, 11]


VES Institute of Technology

Department of Automation and Robotics

Machine Learning Lab (Assignment-05)

Name: Krish Paras Shah Date: 27/05/2025

Aim: Write a python program to perform logistic regression on the given data set (read from csv
file). Use SPYDER only.

Theory:

Logistic Regression is a statistical method used for binary classification problems. It is used to model
the relationship between a dependent binary variable and one or more independent variables. The
range of logistic regression is restricted to 0 to 1.

Unlike linear regression, it does not require a linear relationship between input and output. This is due
to application of nonlinear logarithmic transformation.

The logistic function equation is given by:

Code:

Output:
Graph:

VES Institute of Technology


Department of Automation and Robotics

Machine Learning Lab (Assignment-06)

Name: Krish Paras Shah Date: 27/05/2025

Aim: Write a python program to perform k-means clustering on a given image for compression.

Theory:
K-means image compression is a technique that reduces the size of an image by reducing the number
of unique colors in the image, while maintaining its visual appearance. The method relies on K-means
clustering, a popular unsupervised machine learning algorithm, to group similar colors and represent
them with a smaller set of "centroids" (average colors of the clusters). This process results in a
compressed image with fewer colors, effectively reducing the amount of data needed to represent it.

Code:

Input Image:
Output Image:

VES Institute of Technology


Department of Automation and Robotics

Machine Learning Lab (Assignment-07)

Name: Krish Paras Shah Date:

Aim: Write a python program to implement Hierarchical clustering.

Code:
import pandas as pd import

numpy as np import

matplotlib.pyplot as plt

from scipy.cluster.hierarchy import dendrogram, linkage, fcluster

# Load CSV

data = pd.read_csv("C:/Users/DELL/Desktop/VESIT/SEM_6/ML/customers.csv")

# Extract features

X = data[['AnnualIncome', 'SpendingScore']].values

# Step 1: Hierarchical clustering

linked = linkage(X, method='ward')

# Step 2: Dendrogram

plt.figure(figsize=(10, 5))

dendrogram(linked, orientation='top',

distance_sort='descending',

show_leaf_counts=True)

plt.title("Dendrogram for Customer Segmentation")

plt.xlabel("Customer Index") plt.ylabel("Distance")

plt.grid(True) plt.show()

# Step 3: Assign clusters (e.g., 3 clusters) clusters

= fcluster(linked, 3, criterion='maxclust')

print("Cluster Labels:\n", clusters) # Step 4: Plot

clustered data plt.figure(figsize=(8, 6))


plt.scatter(X[:, 0], X[:, 1], c=clusters, cmap='rainbow')

plt.title("Hierarchical Clustering (3 Clusters)")

plt.xlabel("Annual Income (Lakhs)")

plt.ylabel("Spending Score (1-100)") plt.grid(True)

plt.show()

Output:

VES Institute of Technology


Department of Automation and Robotics

Machine Learning Lab (Assignment-08)

Name: Krish Paras Shah Date:

Aim: Write a python program to implement ANN for handwritten digits Recognition.

Code:
import tensorflow as tf

from tensorflow.keras.datasets import mnist from

tensorflow.keras.models import Sequential from

tensorflow.keras.layers import Dense, Flatten from

tensorflow.keras.utils import to_categorical import

matplotlib.pyplot as plt # Step 1: Load MNIST

dataset

(x_train, y_train), (x_test, y_test) = mnist.load_data()

# Normalize the data (0–1)

x_train = x_train / 255.0

x_test = x_test / 255.0

# Convert labels to one-hot

encoding y_train_cat =

to_categorical(y_train) y_test_cat

= to_categorical(y_test) # Step 2:

Build the model model =

Sequential()

model.add(Flatten(input_shape=(28, 28))) # Flatten 28x28 image to 784

model.add(Dense(128, activation='relu')) # Hidden layer with 128 neurons

model.add(Dense(64, activation='relu')) # Another hidden layer

model.add(Dense(10, activation='softmax')) # Output layer for 10 classes

# Step 3: Compile the model model.compile(optimizer='adam',


loss='categorical_crossentropy',

metrics=['accuracy']) # Step 4: Train

the model

model.fit(x_train, y_train_cat, epochs=5, batch_size=32, validation_split=0.2)

# Step 5: Evaluate the model

loss, accuracy = model.evaluate(x_test, y_test_cat)

print(f"\nTest Accuracy: {accuracy*100:.2f}%") #

Step 6: Predict and visualize some results

predictions = model.predict(x_test) # Display 5

random predictions import numpy as np for i in

range(5):

index = np.random.randint(0, len(x_test)) plt.imshow(x_test[index],

cmap='gray')

plt.title(f"Predicted: {np.argmax(predictions[index])} | Actual: {y_test[index]}")

plt.axis('off')

plt.show()

Output:
VES Institute of Technology

Department of Automation and Robotics

Machine Learning Lab (Assignment-09)


Name: Krish Paras Shah Date:

Aim: Write a python program to implement SVM for spam email classifiers.

Code:
import pandas as pd from
sklearn.feature_extraction.text import
TfidfVectorizer from sklearn.model_selection import
train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix url =
"https://raw.githubusercontent.com/justmarkham/pycon-2016-tutorial/master/data/sms.tsv"
df = pd.read_table(url, header=None, names=["label", "message"])
df['label'] = df['label'].map({'ham': 0, 'spam':
1}) vectorizer =
TfidfVectorizer(stop_words='english') X =
vectorizer.fit_transform(df['message']) y =
df['label']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42) model = SVC(kernel='linear') model.fit(X_train, y_train)
y_pred = model.predict(X_test) print(" Spam Detection using SVM")
print("Accuracy:", accuracy_score(y_test, y_pred)) print("\nConfusion Matrix:\n",
confusion_matrix(y_test, y_pred)) print("\nClassification Report:\n",
classification_report(y_test, y_pred))

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy