0% found this document useful (0 votes)
5 views10 pages

Student Lab Report Machine Learning With Python

This student lab report from Galgotias University details various machine learning experiments conducted using Python. The report includes objectives, programs, and results for experiments on NumPy operations, Pandas DataFrame operations, data visualization with Matplotlib, and several machine learning algorithms including linear regression, KNN classification, decision trees, and K-means clustering. The document serves as a comprehensive overview of practical applications of machine learning techniques in Python.

Uploaded by

Rahul Chaudhary
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)
5 views10 pages

Student Lab Report Machine Learning With Python

This student lab report from Galgotias University details various machine learning experiments conducted using Python. The report includes objectives, programs, and results for experiments on NumPy operations, Pandas DataFrame operations, data visualization with Matplotlib, and several machine learning algorithms including linear regression, KNN classification, decision trees, and K-means clustering. The document serves as a comprehensive overview of practical applications of machine learning techniques in Python.

Uploaded by

Rahul Chaudhary
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

Student Lab Report

Galgotias University
Plot No.2, Sector-17A, Yamuna Expresway, Greater
Noida, Gautam Buddh Nagar, U.P., India

Course Name: Master of Computer Applications (MCA)


University: Galgotias University
Year: 2026
Semester: 2nd
Assignment: Machine learning with Python

Submitted By: Submitted To:

Name: Rahul Pal


_____________________
GALGOTIAS UNIVERSITY
Admission No: GUOLPG250861
Name Semester Admission No.
RAHUL PAL 2nd GUOLPG250861

Index
Sr. No. Name of Experiment Page
No.
NumPy Array Operations
1. 3

Pandas DataFrame Operations


2. 4
Matplotlib Data Visualization
3. 5
Correlation Matrix
4. 6
Linear Regression
5. 7
KNN Classification
6. 8
Decision Tree Classifier
7. 9
K-Means Clustering
8. 10
Experiment No. 1

Objective/Aim: NumPy Operations

Program:

import numpy as np

# Create 1D and 2D arrays

array_1d = [Link]([1, 2, 3, 4])

array_2d = [Link]([[1, 2], [3, 4]])

# Find shape, size, and datatype

print("1D Array - Shape:", array_1d.shape, "| Size:", array_1d.size, "| Datatype:",


array_1d.dtype)

print("2D Array - Shape:", array_2d.shape, "| Size:", array_2d.size, "| Datatype:",


array_2d.dtype)

# Addition and Multiplication (Element-wise)

array_a = [Link]([[1, 2], [3, 4]])

array_b = [Link]([[5, 6], [7, 8]])

print("\nAddition:\n", array_a + array_b)

print("Element-wise Multiplication:\n", array_a * array_b)

print("Matrix Multiplication (Dot Product):\n", [Link](array_a, array_b))


Experiment No. 2
Objective/Aim: Pandas DataFrame Operations

Program:

import pandas as pd

import numpy as np

# Create a DataFrame with some missing values

data = {

'Student': ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank'],

'Age': [20, 21, [Link], 22, 20, 23],

'Score': [85.5, 90.0, 78.5, [Link], 88.0, 92.5]

df = [Link](data)

# Display first 5 rows

print("First 5 rows of the DataFrame:")

print([Link](5))

# Find missing values in the dataset

print("\nMissing values in each column:")

print([Link]().sum())
Experiment No. 3
Objective/Aim: Matplotlib Visualizations

Program:

import [Link] as plt

students = ['Alice', 'Bob', 'Charlie', 'David', 'Eve']

marks = [85, 92, 78, 90, 88]

[Link](figsize=(15, 4))

# Line graph

[Link](1, 3, 1)

[Link](students, marks, marker='o', color='b', linestyle='-')

[Link]('Line Graph')

[Link]('Marks')

# Bar graph

[Link](1, 3, 2)

[Link](students, marks, color='orange')

[Link]('Bar Graph')

# Pie chart

[Link](1, 3, 3)

[Link](marks, labels=students, autopct='%1.1f%%', startangle=140)

[Link]('Pie Chart')

plt.tight_layout()

[Link]()
Experiment No. 4
Objective/Aim: Correlation Matrix

Program:

import pandas as pd

import seaborn as sns

import [Link] as plt

from [Link] import load_iris

# Load a built-in dataset

iris = load_iris()

df = [Link]([Link], columns=iris.feature_names)

# Calculate correla on between features

correla on_matrix = [Link]()

print("Correla on Matrix:")

print(correla on_matrix)

# Display the correla on matrix using a heatmap

plt.figure(figsize=(6, 4))

[Link](correla on_matrix, annot=True, cmap='coolwarm', fmt=".2f")

plt. tle('Feature Correla on Matrix')

[Link]()
Experiment No. 5
Objective/Aim: Linear Regression

Program:
import numpy as np

import [Link] as plt

from sklearn.linear_model import LinearRegression

from [Link] import mean_squared_error, r2_score

from sklearn.model_selec on import train_test_split

# Sample Data: Hours studied vs. Test score

X = [Link]([[1], [2], [3], [4], [5], [6], [7], [8]])

y = [Link]([30, 45, 50, 65, 70, 85, 90, 100])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

# Implement and train

model = LinearRegression()

model.fit(X_train, y_train)

# Predict output values

y_pred = [Link](X_test)

# Calculate metrics

mse = mean_squared_error(y_test, y_pred)

r2 = r2_score(y_test, y_pred)

print(f"Mean Squared Error: {mse:.2f}")

print(f"R-squared: {r2:.2f}")

print(f"Predic ons: {y_pred}")


Experiment No. 6
Objective/Aim: KNN Classification

Program:
from [Link] import load_iris

from sklearn.model_selec on import train_test_split

from [Link] import KNeighborsClassifier

from [Link] import accuracy_score, classifica on_report

# Load data

iris = load_iris()

X = [Link]

y = [Link]

# Train and test split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Implement and train KNN

knn = KNeighborsClassifier(n_neighbors=3)

knn.fit(X_train, y_train)

# Display predic on results and accuracy

y_pred = [Link](X_test)

accuracy = accuracy_score(y_test, y_pred)

print("Predic ons:", y_pred)

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

print("Classifica on Report:\n", classifica on_report(y_test, y_pred,


target_names=iris.target_names))
Experiment No. 7
Objective/Aim: Decision Tree Classifier
Program:

from [Link] import load_breast_cancer

from sklearn.model_selec on import train_test_split

from [Link] import DecisionTreeClassifier, plot_tree

import [Link] as plt

# Load sample dataset (Breast Cancer classifica on)

data = load_breast_cancer()

X_train, X_test, y_train, y_test = train_test_split([Link], [Link], max_depth=3,


random_state=42)

# Train the model

tree_model = DecisionTreeClassifier(max_depth=3, random_state=42)

tree_model.fit(X_train, y_train)

# Visualize the decision tree

plt.figure(figsize=(12, 8))

plot_tree(tree_model, feature_names=data.feature_names,
class_names=data.target_names, filled=True, rounded=True)

plt. tle("Decision Tree Visualiza on")

[Link]()
Experiment No. 8
Objective/Aim: K-Means Clustering
Program:

from [Link] import KMeans

from [Link] import make_blobs

import [Link] as plt

# Generate sample data

X, y_true = make_blobs(n_samples=300, centers=4, cluster_std=0.60, random_state=0)

# Implement K-Means clustering

kmeans = KMeans(n_clusters=4, random_state=0, n_init='auto')

# Divide data into clusters

kmeans.fit(X)

y_kmeans = [Link](X)

# Visualize clusters using graphs

[Link] er(X[:, 0], X[:, 1], c=y_kmeans, s=50, cmap='viridis')

# Plot the centroids

centers = kmeans.cluster_centers_

[Link] er(centers[:, 0], centers[:, 1], c='red', s=200, alpha=0.75, marker='X',


label='Centroids')

plt. tle('K-Means Clustering')

[Link]()

[Link]()

You might also like