0% found this document useful (0 votes)
1 views3 pages

Data Science Lab Python

Uploaded by

Sajib Chowdhury
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)
1 views3 pages

Data Science Lab Python

Uploaded by

Sajib Chowdhury
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/ 3

Data Science Lab using Python – PCC DS391

This document contains all 10 experiments as per the syllabus for Semester III B.Tech in
Data Science.

Experiment 1: Interactive commands in Python


🔹 Objective:
Write simple Python programs for reading/writing files and basic operations.

🔹 Code:
# Example: File I/O
with open('sample.txt', 'w') as f:
f.write("Hello, Data Science Lab!")

Experiment 2: Familiarization with IDE in Python


🔹 Objective:
Get familiar with Jupyter Notebook / VS Code for writing and running Python programs.

🔹 Code:
> Try: Shortcut keys, Markdown + Code, variable watching.

Experiment 3: Standard sorting/searching algorithms


🔹 Objective:
Implement standard sorting/searching algorithms in Python.

🔹 Code:
# Bubble Sort Example
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr

Experiment 4: Plotting data using charts


🔹 Objective:
Use matplotlib to create line, bar, and pie charts.

🔹 Code:
import matplotlib.pyplot as plt
x = ['A', 'B', 'C']
y = [10, 20, 15]
plt.bar(x, y)
plt.title('Bar Chart')
plt.show()

Experiment 5: Exploratory Data Analysis (EDA)


🔹 Objective:
Use pandas and statistics for mean, std, var.

🔹 Code:
import pandas as pd
data = {'A': [10, 20, 30, 40]}
df = pd.DataFrame(data)
print("Mean:", df['A'].mean())
print("Std Dev:", df['A'].std())

Experiment 6: Plotting distributions


🔹 Objective:
Plot histograms, boxplots, KDEs using seaborn.

🔹 Code:
import seaborn as sns
sns.histplot(df['A'], kde=True)

Experiment 7: Support Vector Machine (SVM)


🔹 Objective:
Classify data using Support Vector Machine from scikit-learn.

🔹 Code:
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
iris = datasets.load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2)
model = SVC()
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))

Experiment 8: K-means Clustering


🔹 Objective:
Use k-means for data clustering and visualize results.

🔹 Code:
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
kmeans = KMeans(n_clusters=3)
kmeans.fit(iris.data)
plt.scatter(iris.data[:, 0], iris.data[:, 1], c=kmeans.labels_)
plt.title("K-Means Clustering")
plt.show()

Experiment 9: Graphs for social networks


🔹 Objective:
Use networkx to create and visualize a basic graph.

🔹 Code:
import networkx as nx
G = nx.Graph()
G.add_edges_from([('A', 'B'), ('B', 'C'), ('C', 'A')])
nx.draw(G, with_labels=True)

Experiment 10: Centrality & PageRank


🔹 Objective:
Calculate graph metrics like centrality and PageRank.

🔹 Code:
print("Degree Centrality:", nx.degree_centrality(G))
print("PageRank:", nx.pagerank(G))

You might also like