CS - LAB
CS - LAB
LAB MANUVAL
STUDENT NAME :
REGISTER NUMBER :
PROGRAMME : UG
PRACTICAL EXERCISES:
Learning Model.
AIM :
ALGORITHM :
PROGRAM :
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Power: 100000
Square Root: 3.1622776601683795
Log10: 1
Sin(a): -0.5440211108893698
Cos(a): -0.8390715290764524
Tan(a): 0.6483608274590866
RESULT :
AIM :
ALGORITHM :
PROGRAM :
family = {
"parent": [
("John", "Mary"),
("John", "Peter"),
("Susan", "Mary"),
("Susan", "Peter"),
("Mary", "James"),
("Mary", "Sophia"),
]
}
def find_siblings(person):
siblings = set()
for p1, child1 in family["parent"]:
for p2, child2 in family["parent"]:
if p1 == p2 and child1 != child2 and child1 == person:
siblings.add(child2)
return siblings
def find_grandparents(person):
grandparents = set()
for grandparent, parent in family["parent"]:
for p, child in family["parent"]:
if parent == p and child == person:
grandparents.add(grandparent)
return grandparents
query1 = "Mary"
siblings_of_query1 = find_siblings(query1)
print(f"Siblings of {query1}: {siblings_of_query1}")
query2 = "James"
grandparents_of_query2 = find_grandparents(query2)
print(f"Grandparents of {query2}: {grandparents_of_query2}")
OUTPUT :
RESULT :
AIM :
ALGORITHM :
PROGRAM :
OUTPUT :
RESULT :
Learning Model
AIM :
ALGORITHM :
PROGRAM :
OUTPUT :
RESULT :
AIM :
ALGORITHM :
PROGRAM :
class Employee:
def __init__(self, name, position):
self.name = name
self.position = position
def __repr__(self):
return f"Employee(name={self.name},
position={self.position})"
class Department:
def __init__(self, name):
self.name = name
self.employees = []
self.sub_departments = []
def add_employee(self, employee):
self.employees.append(employee)
def add_sub_department(self, department):
self.sub_departments.append(department)
def __repr__(self):
return f"Department(name={self.name},
employees={len(self.employees)},
sub_departments={len(self.sub_departments)})"
class Company:
def __init__(self, name):
self.name = name
self.departments = []
def add_department(self, department):
self.departments.append(department)
def display_hierarchy(self):
print(f"Company: {self.name}")
self._display_departments(self.departments, indent=2)
def _display_departments(self, departments, indent):
for department in departments:
print(" " * indent + f"Department: {department.name}")
for employee in department.employees:
print(" " * (indent + 2) + f"Employee: {employee.name},
Position: {employee.position}")
if department.sub_departments:
self._display_departments(department.sub_departments,
indent + 2)
my_company = Company("Tech Innovators")
sales_department = Department("Sales")
hr_department = Department("Human Resources")
sales_department.add_employee(Employee("Alice", "Sales
Manager"))
sales_department.add_employee(Employee("Bob", "Sales
Associate"))
hr_department.add_employee(Employee("Charlie", "HR Manager"))
recruitment_department = Department("Recruitment")
hr_department.add_sub_department(recruitment_department)
recruitment_department.add_employee(Employee("David",
"Recruiter"))
my_company.add_department(sales_department)
my_company.add_department(hr_department)
my_company.display_hierarchy()
OUTPUT :
RESULT :
AIM :
ALGORITHM :
PROGRAM :
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.mixture import GaussianMixture
X, _ = make_blobs(n_samples=500, centers=3, random_state=42)
gmm = GaussianMixture(n_components=3, covariance_type='full',
random_state=42)
gmm.fit(X)
labels = gmm.predict(X)
plt.figure(figsize=(8, 6))
plt.scatter(X[:, 0], X[:, 1], c=labels, cmap='viridis', marker='o',
alpha=0.7)
ax = plt.gca()
for mean, covar in zip(gmm.means_, gmm.covariances_):
v, w = np.linalg.eigh(covar)
v = 2.0 * np.sqrt(2.0) * np.sqrt(v)
u = w[0] / np.linalg.norm(w[0])
angle = np.arctan(u[1] / u[0])
angle = 180.0 * angle / np.pi
angle = angle + 90
ell = plt.matplotlib.patches.Ellipse(mean, v[0], v[1], angle=180.0 +
angle, color='red', alpha=0.5)
ax.add_patch(ell)
plt.title('Gaussian Mixture Model Clustering', fontsize=16)
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()
OUTPUT :
RESULT :