BIDA PRACTICALS
Practical No. 3 : Aim: Perform the data classification using classification algorithm using R/Python
Python CODE:
import numpy as np
import matplotlib.pyplot as plt
rainfall = [799, 1174.8, 865.1, 1334.6, 635.4, 918.5,
685.5, 998.6,
784.2, 985, 882.8, 1071]
months = np.arange("2012-01", "2013-01",
dtype="datetime64[M]")
plt.figure()
plt.plot(months, rainfall, marker='o')
plt.title("Monthly Rainfall (2012)")
plt.xlabel("Month")
plt.ylabel("Rainfall (mm)")
plt.grid(True)
plt.savefig("rainfall.png")
plt.close()
plt.figure()
plt.plot(months, rainfall, marker='o')
plt.title("Monthly Rainfall (2012)")
plt.xlabel("Month")
plt.ylabel("Rainfall (mm)")
plt.grid(True)
plt.show()
------------------
PRACTICAL NO: 4 Aim: Perform the data clustering using clustering algorithm using R/python
R Code:
newiris <- iris
newiris$Species <- NULL
(kc <- kmeans(newiris,3))
table(iris$Species,kc$cluster)
plot(newiris[c("Sepal.Length","Sepal.Width")],col=kc$cluster)
points(kc$centers[,c("Sepal.Length","Sepal.Width")],col=1:3,pch=8,cex=2)
dev.off()
plot(newiris[c("Sepal.Length","Sepal.Width")],col=kc$cluster)
------------------
PRACTICAL NO:7 Aim: Write a python program to read data from csv file, perform simple data analysis and generate basic insights (use pandas as a python library)
Step 1:
>py D:/bi/get-pip.py
>pip install pandas
CODE:
import pandas as pd
df = pd.read_csv(r"C:\Users\yadav\Desktop\TYIT Study
Material\SEM 6th\BI\quality.csv")
print("dataset before skipping rows:")
print(df)
df = pd.read_csv(r"C:\Users\yadav\Desktop\TYIT Study
Material\SEM 6th\BI\quality.csv", skiprows=[4,5])
print("Dataset after skipping rows:")
print(df)
print(df.InpatientDays)
print(df.PoorCare)
------------------
PRACTICAL NO:9 Aim: Perform data visualization using Python on any sales data.
PREREQUISITES:
>pip install pandas
>pip install matplotlib
>python -m pip install seaborn
>pip install plotly
CODE:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
data = {
'Date': pd.date_range(start='2024-01-01', periods=10, freq='D'),
'Product': ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C', 'A'],
'Sales': [100, 150, 200, 120, 180, 220, 140, 160, 240, 180],
'Revenue': [1000, 1500, 2000, 1200, 1800, 2200, 1400, 1600, 2400, 1800]
}
df = pd.DataFrame(data)
print(df.head())
plt.figure(figsize=(10,5))
sns.lineplot(x='Date', y='Sales', data=df, marker='o', hue='Product')
plt.title("Sales Trend Over Time")
plt.xticks(rotation=45)
plt.show()
plt.figure(figsize=(8,5))
sns.barplot(x='Product', y='Sales', data=df, estimator=sum, palette="coolwarm")
plt.title("Total Sales per Product")
plt.show()
plt.figure(figsize=(6,6))
df.groupby('Product')['Sales'].sum().plot(kind='pie', autopct='%1.1f%%',
colormap="viridis")
plt.title("Sales Distribution by Product")
plt.ylabel("")
plt.show()
fig = px.bar(df, x='Date', y='Sales', color='Product', title="Interactive Sales
Trend")
fig.show()
------------------
PRACTICAL NO. 5 Perform the linear regression the given data warehouse data using R/Python
R- Code :
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152,
131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
relation <- lm(y~x)
print(relation)
print(summary(relation))
a <- data.frame(x = 170)
result <- predict(relation,a)
print(result)
png(file = "linearregression.png")
plot(y,x,col = "blue",main = "Height & Weight
Regression",
abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in
Kg",ylab = "Height in cm")
dev.off()
plot
(y,x,col = "blue",main = "Height & Weight Regression", abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab = "Height in cm")
Comments
Post a Comment