FDS LAB PROGRAMS
FDS LAB PROGRAMS
Procedure:
The Python programming language is an increasingly popular choice for both beginners and experienced
developers. Flexible and versatile, Python has strengths in scripting, automation, data analysis, machine
learning, and back-end development.
You’ll need a computer running Windows 10 with administrative privileges and an internet
connection.
1. After the installer is downloaded, double-click the .exe file, for example python-3.10.10-
amd64.exe, to run the Python installer.
2. Select the Install launcher for all users checkbox, which enables all users of the computer to
access the Python launcher application.
3. Select the Add python.exe to PATH checkbox, which enables users to launch Python from the
command line.
4. If you’re just getting started with Python and you want to install it with default features as
described in the dialog, then click Install Now and go to Step 4 - Verify the Python Installation.
To install other optional and advanced features, click Customize installation and continue.
5. The Optional Features include common tools and resources for Python and you can install all of
them, even if you don’t plan to use them.
Select some or all of the following options:
Documentation: recommended
pip: recommended if you want to install other Python packages, such as NumPy or pandas
tcl/tk and IDLE: recommended if you plan to use IDLE or follow tutorials that use it
Python test suite: recommended for testing and learning
py launcher and for all users: recommended to enable users to launch Python from the command line
6. Click Next.
7. The Advanced Options dialog displays.
Select the options that suit your requirements:
Install for all users: recommended if you’re not the only user on this computer
Associate files with Python: recommended, because this option associates all the Python file types with
the launcher or editor
Create shortcuts for installed applications: recommended to enable shortcuts for Python applications
Add Python to environment variables: recommended to enable launching Python
Precompile standard library: not required, it might down the installation
Download debugging symbols and Download debug binaries: recommended only if you plan to create
C or C++ extensions
Make note of the Python installation directory in case you need to reference it later.
8. Click Install to start the installation.
9. After the installation is complete, a Setup was successful message displays.
Step 3 — Adding Python to the Environment Variables (optional)
Skip this step if you selected Add Python to environment variables during installation.
If you want to access Python through the command line but you didn’t add Python to your
environment variables during installation, then you can still do it manually.
Before you start, locate the Python installation directory on your system. The following directories
are examples of the default directory paths:
C:\Program Files\Python310: if you selected Install for all users during installation, then the
directory will be system wide
C:\Users\Sammy\AppData\Local\Programs\Python\Python310: if you didn’t select Install for all
users during installation, then the directory will be in the Windows user path
Note that the folder name will be different if you installed a different version, but will still start
with Python.
You can verify whether the Python installation is successful either through the command line or
through the Integrated Development Environment (IDLE) application, if you chose to install it.
Go to Start and enter cmd in the search bar. Click Command Prompt.
python --version
Output
Python 3.10.10
You can also check the version of Python by opening the IDLE application. Go to Start and
enter python in the search bar and then click the IDLE app, for example IDLE (Python 3.10 64-
bit).
You can start coding in Python using IDLE or your preferred code editor.
Description:
Jupyter Notebook is an open-source web application that allows you to create and share
documents that contain live code, equations, visualizations, and narrative text. Uses
include data cleaning and transformation, numerical simulation, statistical modeling,
data visualization, machine learning, and much more.
Jupyter has support for over 40 different programming languages and Python is one of
them. Python is a requirement (Python 3.3 or greater, or Python 2.7) for installing the
Jupyter Notebook itself.
Finished Installation:
Launching Jupyter:
Task1 2.a) write a numpy program to add a border filled with 0’s around the existing array
AIM: to create a NumPy program to add a border (filled with 0's) around an existing array.
Description:
program:
Output:
Task-1 2.b) Write a NumPy program to get the unique elements of an array.
Description:
Program:
Output:
Task-1 2.c) Write a NumPy program to get the values and indices of the elements
that are bigger than 10 in an given array.
AIM: TO Write a NumPy program to get the values and indices of the elements that are
bigger than 10 in an given array.
DESCRIPTION:
PROGRAM:
OUTPUT:
Aim: To Write a Pandas program to create and display a DataFrame from a specified
dictionary data which has the index labels.
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
program:
import pandas as pd
import numpy as np
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no',
'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data , index=labels)
print(df)
Output :
TASK- Write a Pandas program to select the rows where the score is missing,
2-3(b) i.e. is NaN.
Aim: To Write a Pandas program to select the rows where the score is missing, i.e. is
NaN.
Sample DataFrame:
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
Program:
import pandas as pd
import numpy as np
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data , index=labels)
print(df[df['score'].isnull
Output:
Task-3 4.a) Write a Python program to draw a scatter plot with empty circles taking a random
distribution in X and Y and plotted against each other.
Aim: To Write a Python program to draw a scatter plot with empty circles taking a random distribution in X and
Y and plotted against each other.
Code:
Output:
Task-3 4.b) Write a Python program to draw a pie chart with a title of popularity of programming
languages.
Aim: To Write a Python program to draw a pie chart with a title of popularity of programming languages.
Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++
Popularity: 22.2, 17.6, 8.8, 8, 7.7, 6.7
Program:
plt.axis('equal')
plt.legend(title=”Popularity of Programming Languages”)
plt.show()
Output:
TASK-4 5.A) INSTALL PLOTLY
AIM : To install Plotly Succesfully in our PC
Procedure:
Now Plotly is Downloaded Successfully and Open the Jupyter Notebook and type Plotly Programs
TASK-4 5.B) Create Line Chart ,Bar Chart, Pie Chart Using Plotly
Aim: To Create Line Chart ,Bar Chart, Pie Chart Using Plotly
1. Line chart:
Program:
import plotly.express as px
x = [1,2,3,4,5]
y = [1,3,4,5,6]
fig.show()
OUTPUT:
output:
3. Pie chart: A pie chart represents the distribution of different
variables among total. In the pie chart each slice shows its
contribution to the total amount.
Program:
# import all required libraries
import numpy as np
import plotly
import plotly.graph_objects as go
import plotly.offline as pyo
init_notebook_mode(connected = True)
'Australia','Brazil',
'Mexico','Russia',
'Germany','Switzerland',
'Texas']
# values corresponding to
each # individual country
present in # countries
fig = go.Figure(data=[go.Pie(labels=countries,
values=values)])
fig.show()
TASK-4 Create Box Plots, Violin Plots, Heatmaps Using Plotly
5.c)
3. Heatmaps
Description:
Program:
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
data_set= pd.read_csv('Salary_Data.csv')
x= data_set.iloc[:, :-1].values
y= data_set.iloc[:, 1].values
# Splitting the dataset into training and test set.
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 1/3, random_s
tate=0)
#Fitting the Simple Linear Regression model to the training dataset
from sklearn.linear_model import LinearRegression
regressor= LinearRegression()
regressor.fit(x_train, y_train)
#Prediction of Test and Training set result
y_pred= regressor.predict(x_test)
x_pred= regressor.predict(x_train)
mtp.scatter(x_train, y_train, color="green")
mtp.plot(x_train, x_pred, color="red")
mtp.title("Salary vs Experience (Training Dataset)")
mtp.xlabel("Years of Experience")
mtp.ylabel("Salary(In Rupees)")
mtp.show()
#visualizing the Test set results
mtp.scatter(x_test, y_test, color="blue")
mtp.plot(x_train, x_pred, color="red")
mtp.title("Salary vs Experience (Test Dataset)")
mtp.xlabel("Years of Experience")
mtp.ylabel("Salary(In Rupees)")
mtp.show()
Task5 6.b) Develop the Multiple Linear Regression with python
Aim: To Develop the Multiple Linear Regression with python
Description:
Program:
# importing libraries
import numpy as np
import pandas as pd
dataset=pd.read_csv("C:/Users/NECG/Desktop/50_StartsUp.c
sv") x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1]
ColumnTransformer from
sklearn.preprocessing import
OneHotEncoder
ct=ColumnTransformer(transformers=[('encoder',OneHotEncoder(),
[3])],remainder='passthrough') x=np.array(ct.fit_transform(x))
X=x[:,1:]
LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,y_train)
results
y_pred=regressor.predi
ct(X_test) y_test
y_pred
mean_squared_error
mean_squared_error(y_test,y_pr
ed)
from sklearn.metrics
import r2_score
r2_score(y_test,y_pred)
mtp.scatter(x_train,y_train,color="green")
mtp.plot(x_train,x_pred,color="red") mtp.title("Salary vs
mtp.ylabel("Salary(In Rupees)")
mtp.show()
mtp.scatter(x_train,y_train,color="blue")
mtp.plot(x_train,x_pred,color="red")
mtp.xlabel("Years of Experience")
mtp.ylabel("Salary(In Rupees)")
mtp.show()
Output:
TASK-6
7. Write a program to implement Logistic Regression.
For this problem, we will build a Machine Learning model using the Logistic
regression algorithm. The dataset is shown in the below image. In this
problem, we will predict the purchased variable (Dependent
Variable) by using age and salary (Independent variables).
Program:
dataset = np.array(
[['Asset Flip', 100, 1000],
['Text Based', 500, 3000],
['Visual Novel', 1500, 5000],
['2D Pixel Art', 3500, 8000],
['2D Vector Art', 5000, 6500],
['Strategy', 6000, 7000],
['First Person Shooter', 8000, 15000],
['Simulator', 9500, 20000],
['Racing', 12000, 21000],
['RPG', 14000, 25000],
['Sandbox', 15500, 27000],
['Open-World', 16500, 30000],
['MMOFPS', 25000, 52000],
['MMORPG', 30000, 80000]
])
# print X
print(X)
# print y
print(y)
# import the regressor
from sklearn.tree import DecisionTreeRegressor
# specify title
plt.title('Profit to Production Cost (Decision Tree Regression)')
# import export_graphviz
from sklearn.tree import export_graphviz
TASK-8 10. Write a program to implement the K-Nearest Neighbour(KNN) algorithm to classify the
given dataset
Aim: To Write a program to implement the K-Nearest Neighbour(KNN) algorithm to classify the given
dataset
Program:
# Loading data
irisData = load_iris()
knn = KNeighborsClassifier(n_neighbors=7)
knn.fit(X_train, y_train)
# Generate plot
plt.plot(neighbors, test_accuracy, label = 'Testing dataset Accuracy')
plt.plot(neighbors, train_accuracy, label = 'Training dataset Accuracy')
plt.legend()
plt.xlabel('n_neighbors')
plt.ylabel('Accuracy')
plt.show()
OUTPUT:
Task 9 11. Write a program to implement the Naive Bayesian classifier for a simple training data set to be
stored in .CSV file.
Aim: To implement the Naive Bayesian classifier for a simple training data set to be stored in .CSV file.
Program:
Aim: Program to implement clustering algorithm to cluster the set of data stored
in .CSV file.
Program:
# importing libraries
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('Mall_Customers_data.csv')