ML termwork
ML termwork
Source Code:
Output:
Problem Statement 2: Create a list using the input from the user and perform the following task:
• Range, Average Deviation, Absolute Deviations, Squared Deviations, Standard Deviation
Objective: Create a Python program that accepts user input to build a list, calculates the range, average
deviation, absolute deviations, squared deviations, and standard deviation.
Algorithm:
Source Code:
Output:
Source Code:
Output:
Problem Statement 4: Write a program that demonstrates the use of various data types (integer, float,
string, boolean, list, tuple, set, dictionary) and prints their values and types.
Objective: Create a Python program that demonstrates the usage of basic data types: integer, float, string,
boolean, list, tuple, set, and dictionary. The program should print the value and type of each data type.
Algorithm:
Source Code:
Output:
Problem Statement 5: Write a program that demonstrates arithmetic, comparison, and logical operators
along with operator precedence in Python.
Objective: Create a Python program that demonstrates the use of arithmetic, comparison, and logical
operators, along with showcasing operator precedence.
Algorithm:
Source Code:
Output:
Problem Statement 6: Write a program that demonstrates how to convert between different data types
(e.g., integer to string, string to integer, etc.).
Objective: Create a Python program that illustrates conversions between integers, floats, strings, booleans,
and collections such as lists, tuples, and sets.
Algorithm:
Source Code:
Output:
Problem Statement 7: Write a program that takes input from the user for their name and age, then prints a
greeting message using that information.
Objective: Create a Python program that takes input for the user's name and age and prints a personalized
greeting message.
Algorithm:
Source Code:
Output:
Problem Statement 8: Write a program that demonstrates both single-line and multi-line comments in
Python.
Objective: Create a Python program that demonstrates the use of single-line and multi-line comments
effectively.
Algorithm:
Source Code:
Output:
Problem Statement 9: Write a program that imports the built-in math module and uses it to calculate the
square root of a number and print the value of pi
Objective: Create a Python program that imports the math module, calculates the square root of a user-
provided number, and prints the value of pi.
Algorithm:
Source Code:
Output:
Problem Statement 10: Write a program that demonstrates control statements using if-else, for loop, and
while loop. • If-Else Statement • For Loop • While Loop
Objective: Create a Python program that demonstrates:
1. Conditional control using an if-else statement.
2. Iteration using a for loop.
3. Iteration using a while loop.
Algorithm:
Source Code:
num = int(input("Enter a number: "))
print("Positive" if num > 0 else "Zero/Negative")
print("\nSquares of numbers:")
for item in range(1, 6): # Example range
print(item**2, end=", ")
print("\nCountdown:")
count = 3
while count > 0:
print(count, end=", ")
count -= 1
print("Go!")
Output:
Problem Statement 11: Write a program that defines a function to greet a user and then calls that function.
Objective: Write a Python program that defines a function to greet a user by their name and then calls that
function to display the greeting.
Algorithm:
Source Code:
def greet_user(name):
print(f"Hello, {name}! Welcome!")
greet_user(user_name)
Output:
Problem Statement 12: Write a program that demonstrates the use of some Python built-in functions like
abs(), max(), min(), len(), and round().
Objective: Write a Python program that demonstrates the usage of built-in functions: abs(), max(), min(),
len(), and round().
Algorithm:
Source Code:
number, float_number, numbers_list = -42, 3.14159, [10, 20, 30, 5, 15]
Output:
Problem Statement 13: Write a program that imports the random module and generates a random integer
between 1 and 100.
Objective: Write a Python program that imports the random module and generates a random integer
between 1 and 100.
Algorithm:
Source Code:
import random
Output:
Problem Statement 14: Write a program that demonstrates file handling by performing the following
operations: a) Create a file b) Writing data to a file c) Reading data from the file d) Appending new data to
the file e) Reading the file line by line
Objective: Write a Python program that performs the following file handling operations:
1. Create a file. 2.Write data to the file. 3. Read data from the file. 4. Append new data to the file. 5.
Read the file line by line.
Algorithm:
Source Code:
with open("example.txt", "w") as file:
file.write("This is the first line of the file.\n")
file.write("This is the second line of the file.\n")
Output:
Problem Statement 15: Write a Python program to perform K-Means clustering on a given dataset and
visualize the clustered data points along with their centroids.
Objective: Write a Python program to:
1. Perform K-Means clustering on a given dataset.
2. Visualize the clustered data points and their centroids using Matplotlib.
Algorithm:
Source Code:
Output:
Problem Statement 16: Implement DBScan algorithm using Python on a given dataset.
Objective: To implement the DBSCAN clustering algorithm on a dataset to identify clusters of varying
shape and size, and mark outliers/noise.
Algorithm:
Source Code:
Output:
Problem Statement 17: Implement PCA on a given dataset iris and reduce it to 2 principal components.
Objective: To perform dimensionality reduction on the Iris dataset using PCA and reduce the features from
4 to 2 while preserving as much variance as possible.
Algorithm:
Source Code:
Output:
Problem Statement 18: Write a program to extract the features from a given dataset using PCA and then
forward the extracted features to K-means clustering algorithm for cluster generation
Objective: Reduce high-dimensional data using PCA, then cluster the data using K-Means on the extracted
principal components.
Algorithm:
Source Code:
Output:
Problem Statement 19: Write a program to extract the features from a given dataset using PCA and then
forward the extracted features to DBSCAN clustering algorithm for cluster generation.
Objective: Extract meaningful features using PCA and apply DBSCAN clustering to detect dense regions
(clusters) in the reduced feature space.
Algorithm:
Source Code:
Output:
Problem Statement 20: Write a program to demonstrate the uses of NumPy and SciPy.
Objective: Showcase basic operations using NumPy (array manipulation, math) and SciPy (scientific
computing: integration, optimization).
Algorithm:
Source Code:
Output:
Problem Statement 21: Write a program to demonstrate the uses of Matplotlib and Scikit Learn.
Objective: Use Scikit-learn to train a machine learning model, and Matplotlib to visualize the results.
Algorithm:
Source Code:
Output:
Source Code:
Output:
Problem Statement 21: Write a program to implement Linear Regression in a given dataset and also
calculate the test accuracy.
Objective: Train a Linear Regression model on a dataset and evaluate it using test accuracy (R² score).
Algorithm:
Source Code:
Output: