0% found this document useful (0 votes)
6 views24 pages

Data Science Lab Manual

Uploaded by

henoya7914
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)
6 views24 pages

Data Science Lab Manual

Uploaded by

henoya7914
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

CS3361 DATA SCIENCE LABORATORY LTPC

0042
COURSE OBJECTIVES:
To understand the python libraries for data science
To understand the basic Statistical and Probability measures for data science.
To learn descriptive analytics on the benchmark data sets.
To apply correlation and regression analytics on standard data sets.
To present and interpret data using visualization packages in Python.
LIST OF EXPERIMENTS:
1. Download, install and explore the features of NumPy, SciPy, Jupyter, Statsmodels and Pandas
packages.
2. Working with Numpy arrays
3. Working with Pandas data frames
Reading data from text files, Excel and the web and exploring various commands for doing
descriptive analytics on the Iris data set.
5. Use the diabetes data set from UCI and Pima Indians Diabetes data set for performing the
following:
a. Univariate analysis: Frequency, Mean, Median, Mode, Variance, Standard Deviation,
Skewness and Kurtosis.
b. Bivariate analysis: Linear and logistic regression modeling
c. Multiple Regression analysis
d. Also compare the results of the above analysis for the two data sets.
6. Apply and explore various plotting functions on UCI data sets.
a. Normal curves
b. Density and contour plots
c. Correlation and scatter plots
d. Histograms
e. Three dimensional plotting
7. Visualizing Geographic Data with Basemap
LIST OF EQUIPMENTS :(30 Students per Batch)
Tools: Python, Numpy, Scipy, Matplotlib, Pandas, statmodels, seaborn, plotly, bokeh
Note: Example data sets like: UCI, Iris, Pima Indians Diabetes etc.
TOTAL: 60 PERIODS
COURSE OUTCOMES:
At the end of this course, the students will be able to:
CO1: Make use of the python libraries for data science
CO2: Make use of the basic Statistical and Probability measures for data science.
CO3: Perform descriptive analytics on the benchmark data sets.
CO4: Perform correlation and regression analytics on standard data sets
CO5: Present and interpret data using visualization packages in Python.
LIST OF EXPERIMENTS

Ex.No Experiment Name


1 Study of Numpy,Scipy,Jupiter,Statmodel,Panda Packages
2a Basics of Numpy Array
2b Slicing
2c Matrix Multiplication
2d Trignometric Function
2e Arithmetic Operation
3 Data Frame
4a Import csv File using Pandas
4b Read Excel File using Pandas
4c Calculate Mean,Median,Mode,SD,Variance from csv File
5a Calculate Frequency,SD,Skewness,Kurtosis
5b Linear and Logistic Model
5c Multiple Regression
5d Compare two data set
6a Normal Curve
6b Density and Contour Plots
6c Correlation and Scatterplot
6d Histogram
6e 3D Plotting
7 Geographic Data with BaseMap
Ex.No:1 Download, install and explore the features of NumPy, SciPy, Jupyter, Statsmodels
and Pandas packages.

Aim:
To Download, install and explore the features of NumPy, SciPy, Jupyter, Statsmodels and
Pandas packages.

Install numpy procedure:


1) Open the command prompt.
2) Use the pip command [pip install numpy].
3) Use the import command to use the package.

Explore features of numpy:


1) High performance N-Dimensionl array object
a)one-dimensional array
b)multi-dimensional array
2) It contains tools for integrating code from C/C++ and Fortran.
3) Additional linear algebra , fourier transform and random number capabilities.
4) It consists of a broadcasting functions.
5) It has data type definition capability to work with varied data basics.

Install scipy procedure:


1) Scientific python distribution.
2) Install scipy using pip command.
3) use scipy package manager.
4) other options...
[We can also build package from its source it is for development use. We can also use binary files
from repositories to install the package.]

Explore the features of scipy:


• Optimization
• Linear Algebra
• Integration
• Special Function
• Fast fourier transform
• Signal
• Image processing
• ODE Solving
• Other tasks common in science and technology.

Install Jupyter notebook using pip :


1) Command to install jupyter.
2) Begining files and data .
3) Install packages .
4) Finish installation.
Explore the features:
• Text and HTML ,
• Code and output,
• Visualization,
• Multimedia,
• Data
Install pandas Procedure :
1) Install with pip command in command prompt.
2) Install anaconda.
(OR)
1) Install python .
2) Use the command “pip install pandas”.
3) Once finished, use import to access package.

Explore the features of pandas:


• Handling of data ,
• Alignment and indexing ,
• Handling missing data,
• Cleaning up data,
• Input and output tools,
• Multiple files formats are supported,
• A lot of time saving,
• Optimized performance,
• python support ,
• Visualize,
• Grouping ,
• Mask data,
• Unique data,
• perform mathematical operations on the data.

Install statemodels using pip:


Open the terminal and exicute the following command :
1) python m venv states m
2) source / states m / bin / activate
3) pip install statemodels

Features of statemodels:
• Linear regression models:
◦ Ordinary least squares
◦ Genralized least squares
◦ Weighed least squares
◦ Quantitive regression
• Discrete models:
◦ Logic and profit
◦ Multinomial logic
◦ Poisson and genralize poisson regression
◦ Zero – Inflated count model
◦ Integrity

GLM- Genralized Linear Model with support for all of the one parameter exponential distribution
baysion mixed GLM for binomial and poisson vector auto – regressive model .

Result:
Thus the study of downloading,installing procedures and features are studied.
Ex. No:2a Basics of Numpy Array

Aim:
To write a program for Calculating the basics of Numpy Arrays.

Program:
import numpy as np
a=np.array([1,2,3,4,5,6])
b=np.arange(7,13)
copied_array = a.copy()
viewed_array=b.view()
shaped_array=a.reshape(2,3)
min_value=np.amin(a)
max_value=np.max(a)
mean=np.mean(a)
median = np.median(a)
range_value = np.ptp(a)
variance = np.var(a)
std_value = np.std(a)
print("The array 'a' is ",a)
print("The array 'b' is ",b)
print("Copied array -> ",copied_array)
print("Viewed array -> ",viewed_array)
print("Shaped array -> ",shaped_array)
print("Minimum value -> ",min_value)
print("Maximum value -> ",max_value)
print("Mean -> ",mean)
print("Median -> ",median)
print("Range of array -> ",range_value)
print("Variance -> ",variance)
print("Standard Deviation -> ",std_value)
isall_values=np.all(a>0)
isany_values=np.any(a>0)
print("All values are greater than 0 -> ",isall_values)
print("Any of the values are greater than 0 -> ",isany_values)

Output:
The array 'a' is [1 2 3 4 5 6]
The array 'b' is [ 7 8 9 10 11 12]
Copied array -> [1 2 3 4 5 6]
Viewed array -> [ 7 8 9 10 11 12]
Shaped array -> [[1 2 3]
[4 5 6]]
Minimum value -> 1
Maximum value -> 6
Mean -> 3.5
Median -> 3.5
Range of array -> 5
Variance -> 2.9166666666666665
Standard Deviation -> 1.707825127659933
All values are greater than 0 -> True
Any of the values are greater than 0 -> True
Result:
Thus the Program get executed the output got verified Successfully.

Ex. No:2b Slicing concept in arrays


Aim:
To write a program for Slicing concept in arrays

Program:
import numpy as np
one_dim_arr=np.array([1,2,3,4,5])
two_dim_arr=np.array([[1,2,3,4,5],
[6,7,8,9,10]])
three_dim_arr=np.array([[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]])
print("One dimension array is sliced to ",one_dim_arr[1:4])
print("Two dimension array i sliced to ",two_dim_arr[:2,:2])
print("Three dimension array is sliced to ",three_dim_arr[:2,:2,:2])

Output:
One dimension array is sliced to [2 3 4]
Two dimension array is sliced to [[1 2]
[6 7]]
Three dimension array is sliced to [[[ 1 2]
[ 4 5]]

[[ 7 8]
[10 11]]]
Result:
Thus the Program get executed the output got verified Successfully.

Ex. No:2c Program for matrix multiplication

Aim:
To write a Program for matrix multiplication
Program:
import numpy as np
a=np.array([[0,0,0],[0,0,0],[0,0,0]])
b=np.array([[0,0,0],[0,0,0],[0,0,0]])
c=np.array([[0,0,0],[0,0,0],[0,0,0]])
print("Enter the values of first array : \n")
for i in range(3):
for j in range(3):
a[i][j]=int(input("Enter the element : "))
print("Enter the values of second array : \n")
for k in range(3):
for l in range(3):
b[k][l]=int(input("Enter the element : "))

for i in range(3):
for j in range(3):
for k in range(3):
c[i][j]+=a[i][k]*b[k][j]
print(c)

Output:
Enter the values of first array :

Enter the element : 1


Enter the element : 2
Enter the element : 3
Enter the element : 4
Enter the element : 5
Enter the element : 6
Enter the element : 7
Enter the element : 8
Enter the element : 9
Enter the values of second array :

Enter the element : 9


Enter the element : 8
Enter the element : 7
Enter the element : 6
Enter the element : 5
Enter the element : 4
Enter the element : 3
Enter the element : 2
Enter the element : 1

[[ 30 24 18]
[ 84 69 54]
[138 114 90]]

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:2d Program for trignometric functions in numpy array


Aim:
To write a Program for trignometric functions in numpy array

Program
import numpy as np
arr=[]
length_arr=int(input("Enter the length of the array : "))
for i in range(0,length_arr):
ele=int(input("Enter the element : "))
arr.append(ele)
print("Sine value of array is ",np.sin(arr))
print("Cosine value of array is ",np.cos(arr))
print("Tangent value of array is ",np.tan(arr))
print("Logarithm value of array is ",np.log(arr))
print("Exponential value of array is ",np.exp(arr))
Output:
Enter the length of the array : 5
Enter the element : 1
Enter the element : 2
Enter the element : 3
Enter the element : 4
Enter the element : 5
Sine value of array is [ 0.84147098 0.90929743 0.14112001 -0.7568025 -0.95892427]
Cosine value of array is [ 0.54030231 -0.41614684 -0.9899925 -0.65364362 0.28366219]
Tangent value of array is [ 1.55740772 -2.18503986 -0.14254654 1.15782128 -3.38051501]
Logarithm value of array is [0. 0.69314718 1.09861229 1.38629436 1.60943791]
Exponential value of array is [ 2.71828183 7.3890561 20.08553692 54.59815003
148.4131591 ]

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:2e Arithmetic operation program


Aim:
To write a program for Calculating the Arithmetic operation program.
Program:
import numpy as np
arr1=[]
arr2=[]
print("Enter the values of first array : \n")
for i in range(5):
ele1=int(input("Enter the element : "))
arr1.append(ele1)
print("Enter the values of second array : \n")
for j in range(5):
ele2=int(input("Enter the element : "))
arr2.append(ele2)
arr_1=np.array(arr1)
arr_2=np.array(arr2)
print("Addition of 2 arrays : ",arr_1+arr_2)
print("Subtraction of 2 arrays : ",arr_1-arr_2)
print("Multiplication of 2 arrays : ",arr_1*arr_2)
print("Division of 2 arrays : ",arr_1/arr_2)
print("Floor division of 2 arrays : ",arr_1//arr_2)
print("Modulus of 2 arrays : ",arr_1%arr_2)
print("Powers of 2 arrays : ",arr_1**arr_2)

Output:
Enter the values of first array :

Enter the element : 1


Enter the element : 2
Enter the element : 3
Enter the element : 4
Enter the element : 5
Enter the values of second array :

Enter the element : 5


Enter the element : 4
Enter the element : 3
Enter the element : 2
Enter the element : 1
Addition of 2 arrays : [6 6 6 6 6]
Subtraction of 2 arrays : [-4 -2 0 2 4]
Multiplication of 2 arrays : [5 8 9 8 5]
Division of 2 arrays : [0.2 0.5 1. 2. 5. ]
Floor division of 2 arrays : [0 0 1 2 5]
Modulus of 2 arrays : [1 2 0 0 0]
Powers of 2 arrays : [ 1 16 27 16 5]

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:3 Program to show data by using dataframe in pandas


Aim:
To write a Program to show data by using dataframe in pandas

Program:
import pandas as pd
friends=[]
relations=[]
print("Enter your friends name : ")
for i in range(3):
friend=input("Enter the name : ")
friends.append(friend)
print("Enter your relation percent : ")
for j in range(3):
relation=int(input("Enter the percent : "))
relations.append(relation)
data={"Friends":friends,"Relation":relations}
df=pd.DataFrame(data)
print(df.to_string())

output:
Enter your friends name :
Enter the name : Barath
Enter the name : Sanjeeve
Enter the name : Dharani
Enter your relation percent :
Enter the percent : 90
Enter the percent : 80
Enter the percent : 70
Friends Relation
0 Barath 90
1 Sanjeeve 80
2 Dharani 70

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:4a Program for import data from CSV file


Aim:
To write a Program for import data from CSV file

Program:

import pandas as pd
df = pd.read_csv("iris_csv.csv")
print("The data in csv file :")
print(df[:10].to_string())
name=input("Enter the column name : ")
print(df[name][:10].to_string())

Output:

The data in csv file :


sepallength sepalwidth petallength petalwidth class
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
5 5.4 3.9 1.7 0.4 Iris-setosa
6 4.6 3.4 1.4 0.3 Iris-setosa
7 5.0 3.4 1.5 0.2 Iris-setosa
8 4.4 2.9 1.4 0.2 Iris-setosa
9 4.9 3.1 1.5 0.1 Iris-setosa
Enter the column name : petallength
0 1.4
1 1.4
2 1.3
3 1.5
4 1.4
5 1.7
6 1.4
7 1.5
8 1.4
9 1.5

Result:
Thus the Program get executed the output got verified Successfully.
Ex.No:4b Program for importing excel file using pandas
Aim:
To write a Program for importing excel file using pandas

Program:
import pandas as pd
num=int(input("Enter the amount of row to display : "))
data=pd.read_excel("maternal_health_risk.xls")
print(data[:num].to_string())
Output:
Enter the amount of row to display : 5
Age SystolicBP DiastolicBP BS BodyTemp HeartRate RiskLevel
0 25 130 80 15.0 98.0 86 high risk
1 35 140 90 13.0 98.0 70 high risk
2 29 90 70 8.0 100.0 80 high risk
3 30 140 85 7.0 98.0 70 high risk
4 35 120 60 6.1 98.0 76 low risk

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:4c Program for calculating the median, mode, variance, standard deviation, and
mean
Aim:
To write a Program for calculating the median, mode, variance, standard deviation, and mean.

Program:
import pandas as pd
data = pd.read_csv("iris_csv.csv")
column_name = input("Enter the column name : ")
print(data[column_name].head())
meanValue = data[column_name].mean()
medianValue = data[column_name].median()
modeValue = data[column_name].mode()
stdValue = data[column_name].std()
varValue = data[column_name].var()
print("The Mean value of ",column_name," : ",meanValue)
print("The Median value of ",column_name," : ",meanValue)
print("The Mode value of ",column_name," : ",modeValue)
print("The Standard Deviation value of ",column_name," : ",stdValue)
print("The Variance value of ",column_name," : ",varValue)

output:
Enter the column name : petallength
0 1.4
1 1.4
2 1.3
3 1.5
4 1.4
Name: petallength, dtype: float64
The Mean value of petallength : 3.758666666666666
The Median value of petallength : 3.758666666666666
The Mode value of petallength : 0 1.5
Name: petallength, dtype: float64
The Standard Deviation value of petallength : 1.7644204199522626
The Variance value of petallength : 3.113179418344519
Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:5a Program for calculating mean,median,mode,skewness and kurtosis

Aim:
To write a Program for calculating mean,median,mode,skewness and kurtosis

Program:
import pandas as pd
from scipy.stats import skew
from scipy.stats import kurtosis
data = pd.read_csv("diabetes.csv")
print(data.head())
column_name = input("Enter the column name : ")
mean_val = data[column_name].mean()
median_val=data[column_name].median()
mode_val = data[column_name].mode()
std_val = data[column_name].std()
freq_value = data[column_name].value_counts()
print("The mean value of ",column_name," : ",mean_val)
print("The median value of ",column_name," : ",median_val)
print("The mode value of ",column_name," : ",mode_val)
print("The standard deviation of ",column_name," : ",std_val)
print("The frequency of ",column_name," : ",freq_value)
print("The skewness : ",skew(data,axis=0,bias=True))
print("The kurtosis value : ",kurtosis(data,axis=0,bias=True))
Output:
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI DiabetesPedigreeFunction Age
Outcome
0 6 148 72 35 0 33.6 0.627 50 1
1 1 85 66 29 0 26.6 0.351 31 0
2 8 183 64 0 0 23.3 0.672 32 1
3 1 89 66 23 94 28.1 0.167 21 0
4 0 137 40 35 168 43.1 2.288 33 1
Enter the column name : Glucose
The mean value of Glucose : 120.89453125
The median value of Glucose : 117.0
The mode value of Glucose : 0 99
1 100
Name: Glucose, dtype: int64
The standard deviation of Glucose : 31.97261819513622
The frequency of Glucose : 99 17
100 17
111 14
129 14
125 14
..
191 1
177 1
44 1
62 1
190 1
Name: Glucose, Length: 136, dtype: int64
The skewness : [ 0.89991194 0.17341396 -1.84000523 0.10915876 2.26781046 -0.42814328
1.9161592 1.12738926 0.6337757 ]
The kurtosis value : [ 0.15038274 0.62881333 5.13869066 -0.52449449 7.15957492 3.26125742
5.55079205 0.63117694 -1.59832836]

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:5b Program for linear and logistic regression modelling


Aim:
To write a program for linear and logistic regression modelling.

Program:
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix,accuracy_score
data = pd.read_csv("diabetes.csv")
print(data.head())
print(data.corr())
column_name_x = input("Enter the column name in axis-x : ")
column_name_y = input("Enter the column name in axis-y : ")
y=data[column_name_y]
x=data[[column_name_x]]
x=sm.add_constant(x)
model = sm.OLS(y,x).fit()
plt.xlabel(column_name_x)
print(model.summary())
xLogic = data.drop(column_name_x,axis=1)
yLogic = data[column_name_x]
xTrain,xTest,yTrain,yTest = train_test_split(x,y,test_size=0.33,random_state=1)
logicmodel = LogisticRegression()
logicmodel.fit(xTrain,yTrain)
predict = logicmodel.predict(xTest)
print(classification_report(yTest,predict))
print(confusion_matrix(yTest,predict))
print(accuracy_score(yTest,predict))
plt.scatter(data[column_name_x],data[column_name_y])
plt.title("Diabetes Comparison")
plt.xlabel(column_name_x)
plt.ylabel(column_name_y)
plt.show()
Output:
Pregnancies Glucose BloodPressure ... DiabetesPedigreeFunction Age Outcome
0 6 148 72 ... 0.627 50 1
1 1 85 66 ... 0.351 31 0
2 8 183 64 ... 0.672 32 1
3 1 89 66 ... 0.167 21 0
4 0 137 40 ... 2.288 33 1
[5 rows x 9 columns]
Pregnancies Glucose ... Age Outcome
Pregnancies 1.000000 0.129459 ... 0.544341 0.221898
Glucose 0.129459 1.000000 ... 0.263514 0.466581
BloodPressure 0.141282 0.152590 ... 0.239528 0.065068
SkinThickness -0.081672 0.057328 ... -0.113970 0.074752
Insulin -0.073535 0.331357 ... -0.042163 0.130548
BMI 0.017683 0.221071 ... 0.036242 0.292695
DiabetesPedigreeFunction -0.033523 0.137337 ... 0.033561 0.173844
Age 0.544341 0.263514 ... 1.000000 0.238356
Outcome 0.221898 0.466581 ... 0.238356 1.000000
[9 rows x 9 columns]
Enter the column name in axis-x : Glucose
Enter the column name in axis-y : BloodPressure
OLS Regression Results
=======================================================================
Dep. Variable: BloodPressure R-squared: 0.023
Model: OLS Adj. R-squared: 0.022
Method: Least Squares F-statistic: 18.26
Date: Sat, 19 Nov 2022 Prob (F-statistic): 2.17e-05
Time: 20:31:04 Log-Likelihood: -3355.8
No. Observations: 768 AIC: 6716.
Df Residuals: 766 BIC: 6725.
Df Model: 1
Covariance Type: nonrobust
=======================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 57.9377 2.703 21.433 0.000 52.631 63.244
Glucose 0.0924 0.022 4.273 0.000 0.050 0.135
=======================================================================
Omnibus: 318.039 Durbin-Watson: 1.961
Prob(Omnibus): 0.000 Jarque-Bera (JB): 1397.465
Skew: -1.903 Prob(JB): 3.50e-304
Kurtosis: 8.403 Cond. No. 489.
=======================================================================
Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:5c Program for multiple regression analysis

Aim:
To write a Program for multiple regression analysis

Program:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv("iris_csv.csv")
data_setosa = data.loc[data['class']=='Iris-setosa']
data_virginica = data.loc[data['class']=='Iris-virginica']
data_versicolor = data.loc[data['class']=='Iris-versicolor']
plt.plot(data_setosa['sepallength'],np.zeros_like(data_setosa['sepallength']), 'o')
plt.plot(data_virginica['sepallength'],np.zeros_like(data_virginica['sepallength']),'o')
plt.plot(data_versicolor['sepallength'],np.zeros_like(data_versicolor['sepall ength']),'o')
plt.xlabel('petallength')
sns.FacetGrid(data,hue="class").map(plt.scatter,"petallength","sepallength").add_legend()
plt.show()
Output:

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:5d Program to compare two datasets


Aim:
To write a Program to compare two datasets

Program:

import pandas as pd
import matplotlib.pyplot as plt
data1=pd.read_csv("india.csv").fillna(0)
data2=pd.read_csv("abroad.csv").fillna(0)
print(data1.head())
print(data2.head())
plt.title("Comparing two data sets")
column_data=input("Enter the column two compare : ")
plt.xlabel(column_data)
plt.ylabel(column_data)
plt.bar(data1[column_data],data2[column_data])
plt.show()
Output:
Minutes Asleep Minutes Awake Number of Awakenings Time in Bed Minutes REM Sleep Minutes
Light Sleep Minutes Deep Sleep
0 362 37 22 399 105.0 158.0 99.0
1 85 3 0 88 0.0 0.0 0.0
2 398 84 26 482 70.0 237.0 91.0
3 196 21 12 217 44.0 131.0 21.0
4 164 21 16 185 41.0 83.0 40.0
Minutes Asleep Minutes Awake Number of Awakenings Time in Bed Minutes REM Sleep Minutes
Light Sleep Minutes Deep Sleep
0 157 16 1 173 0.0 0.0 0.0
1 165 26 13 191 40.0 103.0 22.0
2 343 73 28 416 78.0 204.0 61.0
3 220 30 18 250 43.0 130.0 47.0
4 238 30 19 268 65.0 139.0
Enter the column two compare : Minutes Awake

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:6a Program for generating normal curve from an data

Aim:
To write a Program for generating normal curve from an data

Program:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("prices.csv")
x=data["Model"]
y=data["Price"]
plt.plot(x,y)
plt.show()
Output:

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:6b Program to generate density and contour plots

Aim:
To write a Program to generate density and contour plots

Program:

import matplotlib.pyplot as plt


import numpy as np
import pandas as pd
data = pd.read_csv("iris_csv.csv")
print(data.head())
data_column_one = input("Enter the column 1 : ")
data_column_two = input("Enter the column 2 : ")
feature_x = data[data_column_one]
feature_y = data[data_column_two]
[X, Y] = np.meshgrid(feature_x,feature_y)
Z = np.cos(X / 2) + np.sin(Y / 4)
plt.contour(X,Y,Z)
plt.title('Contour Plot')
plt.xlabel('feature_x')
plt.ylabel('feature_y')
plt.show()
Output:
sepallength sepalwidth petallength petalwidth class
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
Enter the column 1 : sepalwidth
Enter the column 2 : petalwidth

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:6c Program to implement correlation and scatter plots

Aim:
To write a Program to implement correlation and scatter plots

Program:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_excel("maternal_health_risk.xls")
x=data["SystolicBP"]
y=data["DiastolicBP"]
plt.scatter(x,y)
plt.show()
correlation = data.corr()
print(correlation.to_string())
Output:

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:6d Program to generate histogram from given dataset

Aim:
To write a Program to generate histogram from given dataset

Program:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("prices.csv")
print(data.to_string())
plt.hist(data["Price"],bins=[300,400,500,600,700,800,900,1000,1100])
plt.show()
Output:
Company Model Price
0 Samsung s10 899
1 Samsung s20 999
2 Samsung note20 1199
3 Apple iPhoneX 415
4 Apple iPhone11 699
5 Apple iPhone11pro 999
6 Apple iPhoneSE 399
Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:6e Program to implement three dimensional plotting

Aim:
To write a Program to implement three dimensional plotting

Program:
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.axes(projection ='3d')
z = np.linspace(0, 1, 100)
x = z * np.sin(25 * z)
y = z * np.cos(25 * z)
ax.plot3D(x, y, z, 'green')
ax.set_title('3D line plot')
plt.show()
Output:

Result:
Thus the Program get executed the output got verified Successfully.

Ex.No:7 Program to implement three dimensional plotting

Aim:
To write a Program to implement three dimensional plotting

Program:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
map=Basemap(llcrnrlat=5,urcrnrlat=37,llcrnrlon=67,urcrnrlon=99,lat_0=28,lon_0=77)
plt.title("Indian Map")
map.drawcoastlines()
map.fillcontinents(color="green")
map.drawcountries()
map.drawmapboundary(fill_color='lightblue')
plt.show()
Output:

Result:
Thus the Program get executed the output got verified Successfully.

You might also like