0% found this document useful (0 votes)
2 views29 pages

Data Science Labook

The document outlines various assignments and tasks related to the implementation of Python libraries such as Numpy, Pandas, Matplotlib, Seaborn, Scikit-learn, and Scipy, focusing on data manipulation, visualization, cleaning, preprocessing, and model development. It includes specific instructions for creating arrays, performing statistical analysis, visualizing data, and building machine learning models for house price and loan approval predictions. Additionally, it emphasizes the importance of data collection, exploration, and evaluation techniques in data science.

Uploaded by

h7286780
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)
2 views29 pages

Data Science Labook

The document outlines various assignments and tasks related to the implementation of Python libraries such as Numpy, Pandas, Matplotlib, Seaborn, Scikit-learn, and Scipy, focusing on data manipulation, visualization, cleaning, preprocessing, and model development. It includes specific instructions for creating arrays, performing statistical analysis, visualizing data, and building machine learning models for house price and loan approval predictions. Additionally, it emphasizes the importance of data collection, exploration, and evaluation techniques in data science.

Uploaded by

h7286780
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

1.

Implementation of Python Libraries –Numpy and Pandas-


1.1 Numpy -

Create Arrays:

● create a 1-dimensional array arr1 with elements [1, 2, 3, 4, 5]?


● create a 2-dimensional array arr2 with elements [[1, 2, 3], [4, 5, 6]]?

Basic Array Operations:

●What is the shape of arr1 and arr2?


● calculate the sum of all elements in arr1?

● calculate the mean of all elements in arr2?

Generate Arrays:

● create a 2x3 array of zeros?


● create a 3x2 array of ones?

● create a 2x2 array of random numbers between 0 and 1?

Element-wise Operations:

● Given two arrays arr3 = [Link]([1, 2, 3, 4, 5]) and arr4 = [Link]([6, 7, 8, 9,


10]), compute their element-wise sum?
● Given arr3 and arr4, compute their element-wise multiplication?

Matrix Operations:

● perform matrix multiplication on the following matrices:


mat1 = [Link]([[1, 2], [3, 4]])
mat2 = [Link]([[5, 6], [7, 8]])
● compute the transpose of mat1?

Solution-
1.2 Pandas
Reading Data:

● read data from a CSV file into a DataFrame named df?


Basic Information:

●display the shape of the DataFrame?


● find the number of rows and columns in the DataFrame?
● list the column names of the DataFrame?
Summary Statistics:

● display summary statistics of the DataFrame?


Accessing Data:

● display the first few rows of the DataFrame?


● display the last few rows of the DataFrame?
● access a specific column named Distance in the DataFrame?
● access a subset of data, specifically rows 2 to 6 and columns Distance and Calories?
Filtering Data:

● filter rows where the Distance column is greater than 5 and display the shape of the
resulting DataFrame?
Grouping and Aggregating Data:

● group the data by the Distance column and calculate the mean of the Calories
column?
Handling Missing Values:

● count the number of missing values in each column of the DataFrame?


● drop rows with missing values and create a cleaned DataFrame?
Exporting Data:

● export the cleaned DataFrame to a CSV file named cleaned_data.csv?

Solution-
2. Implementation of Python Libraries – Matplotlib and Seaborn

Matplotlib-

Line Plot:

● create a simple line plot with x-values [0, 1, 2, 3, 4] and y-values [0, 1, 4, 9, 16]?
● Add a title 'Line Plot', an x-axis label 'X-Values', and a y-axis label 'Y-Values'.
● Add a legend labeled 'y = x^2'.
● Add a grid to the plot.

Solution-

Bar Plot:

● create a bar plot with categories ['A', 'B', 'C'] and corresponding values [3, 7, 5]?
● Add a title 'Bar Plot', an x-axis label 'Categories', and a y-axis label 'Values'.
● Add a legend labeled 'Category Values'.
● Add a grid to the plot.

Solution-

Seaborn

Line Plot:

● create a line plot using Seaborn with the following data:


 x-values = [0, 1, 2, 3, 4]
 y-values = [0, 1, 4, 9, 16]
● Customize the plot by adding a title 'Line Plot', an x-axis label 'X-Values', and a y-axis
label 'Y-Values'.
● Add a legend labeled 'y = x^2'.
● Ensure the grid is visible.\

Solution-
3. Implementation of Python Libraries –Sci-kit learn and Scipy

Scipy-

Find the roots of the polynomial equation x^2−4x+3=0 using Scipy module.

Solution-
4. Assignment on Data collection resources-

Collect and read five datasets for the following two Projects/Problems from any

resource-

1. House Price prediction

2. Loan Approval Prediction

5. Assignment on Data Collection Methods-

1. Load the Data set of House Price Prediction project and perform

following operations on it-

· Print the first or last few rows of the DataFrame.

· Print the number of rows and columns in the DataFrame.

· View column names.

· Get a concise summary of the DataFrame including data types and missing values.

· Select a single columns

· Select multiple columns.


Solution-
6. Assignment on Data Collection Methods-

· Write a Python code to access data from a public API.

Solution-

1. Assignment on Data Cleaning Techniques-

1. Use the ‘House price prediction’ dataset and Perform the following data cleaning

tasks-

· Identify columns with missing values and implement an appropriate strategy to handle

missing values

· Check for duplicate rows and remove them


· Detect outliers in numeric columns and implement a method to handle outliers.

Solution-

8. Assignment on Data Preprocessing Techniques- 1

Load the House price prediction data set and perform following Techniques-
Data Transformation:

● Apply a transformation such as log transformation or square root transformation to a


numeric feature if suitable.

Feature Scaling:

● Implement feature scaling using standardization or normalization to ensure all features


have the same scale.

Encoding Categorical Variables:

● Encode categorical variables using one-hot encoding or label encoding as appropriate.

Data Splitting:

● Split the dataset into training and testing sets using appropriate ratios (e.g., 80%
training, 20% testing).
9. Assignment on Data Preprocessing Techniques- 2

Load the ‘Loan Approval prediction’ data set and perform following Techniques-

Data Transformation:

● Apply a transformation such as log transformation or square root transformation to a


numeric feature if suitable.

Feature Scaling:

● Implement feature scaling using standardization or normalization to ensure all features


have the same scale.

Encoding Categorical Variables:

● Encode categorical variables using one-hot encoding or label encoding as appropriate.


Data Splitting:

● Split the dataset into training and testing sets using appropriate ratios (e.g., 80%
training, 20% testing).

10 Assignment on Statistics-

Load the ‘House price prediction’ data set and Apply following Statistics Concepts

a. Descriptive Statistics:

● Calculate and interpret the mean, median, mode, standard deviation, and variance for
key features related to house prices.
● Provide insights into the central tendency, variability, and distribution of the data.

b. Inferential Statistics:

● Perform hypothesis testing on a relevant hypothesis related to house prices (e.g.,


average price difference between two types of houses).
● Construct a confidence interval to estimate a population parameter (e.g., mean house
price) with a specified level of confidence.
● Calculate the p-value for the hypothesis test conducted and interpret its significance.
14. Assignment on Data Visualization using Matplotlib

Take the first five rows of the 'House price prediction' dataset and use the Matplotlib library to

create the following graphs:

 Histogram of Price Distribution:

● Create a histogram that shows the distribution of house prices (price column).
● Set the number of bins to 5 and customize the plot with appropriate colors and labels.

 Scatter Plot: Price vs. Area:

● Generate a scatter plot that visualizes the relationship between house prices (price
column) and their corresponding areas (area column).
● Customize the scatter plot with green markers ('o') and ensure transparency
(alpha=0.7).
● Label the x-axis as 'Area' and the y-axis as 'Price'.

 Bar Plot: Number of Bedrooms:

● Construct a bar plot that illustrates the count of houses based on the number of
bedrooms (bedrooms column).
● Use a purple color for the bars and label the x-axis as 'Bedrooms' and the y-axis as
'Count'.

 Pie Chart: Furnishing Status:

● Create a pie chart to display the distribution of houses based on their furnishing status
(furnishingstatus column).
● Show the percentage distribution using '%1.1f%%' format.

Use custom colors for each category: '#ff9999' for 'furnished', '#66b3ff' for 'semi-furnished', and
'#99ff99' for others
14. Assignment on Data Visualization using Seaborn

· Take the first five rows of the 'House price prediction' dataset and use the seaborn

library to create the following graphs-

a. Scatter Plot:
● Create a scatter plot to visualize the relationship between house price and area.
● Provide appropriate labels for axes and a title for the plot.

b. Bar Plot:

● Generate a bar plot to show the average house price based on the number of
bedrooms.
● Label the x-axis with Number of Bedrooms, y-axis with Average Price, and provide a title
for the plot.

c. Histogram:

● Construct a histogram to display the distribution of house prices.


● Use 5 bins for better representation of data distribution.
● Include a kernel density estimate (KDE) to visualize the density.
● Set appropriate labels for the axes and give a title to the plot.

d. Box Plot:

● Create a box plot to explore the spread of house prices based on the number of stories.
● Label the x-axis with Number of Stories, y-axis with Price, and provide a title for the plot.
11. Assignment on EDA Techniques-

Take the first five rows of the 'House price prediction' dataset then perform

univariate analysis for the following-

Histogram of Price:
● Display the distribution of house prices with a histogram.
● Include a Kernel Density Estimate (KDE) to show the probability density function.

Histogram of Area:
● Display the distribution of house areas with a histogram.
● Include a KDE.

Solution-
1. Assignment on EDA Techniques-

Take the first five rows of the 'House price prediction' dataset then perform Bivariate
analysis for the following-

Scatter Plot: Price vs. Area


● Create a scatter plot to visualize the relationship between house prices (price) and
house area (area).
● Include proper labels and titles.

Scatter Plot: Price vs. Bedrooms

● Create a scatter plot to visualize the relationship between house prices (price) and
number of bedrooms (bedrooms).
● Include proper labels and titles.
13 . Assignment on EDA Techniques-

Take the first five rows of the 'House price prediction' dataset then perform multivariate
analysis for the following-

Create a heatmap to visualize the correlation matrix for the variables price, area, bedrooms,
and stories.
Ensure the heatmap includes annotations for correlation values.

16. Assignment on Model Development-1(Linear Regression)

Build a simple linear regression model to predict the relationship between the size of a house
(area) and its price.

Dataset Description:

The dataset provided contains data on houses with the following relevant columns:

● Area: The size of the house in square feet.


● Price: The price of the house in dollars.
17. Assignment on Model Development-2 (KNN algorithm)

build a K-Nearest Neighbors (KNN) model to classify houses into different price categories
based on their size (area) and number of bedrooms.

Dataset Description:
The dataset provided contains data on houses with the following relevant columns:

● Area: The size of the house in square feet.


● Bedrooms: The number of bedrooms in the house.
● Price Category: The category of the house price (e.g., 'Low', 'Medium', 'High').

Use the KNN algorithm to classify houses into Price Category based on Area and Bedrooms as
input features.

18. Assignment on Model Development-3 (K-means clustering algorithm)

Implement the K-Means clustering algorithm to group houses into distinct clusters based on
their size (area) and number of bedrooms. The goal is to identify natural groupings in the
dataset that could help in understanding the segmentation of houses.
Dataset Description:

The dataset provided contains data on houses with the following relevant columns:

● Area: The size of the house in square feet.


● Bedrooms: The number of bedrooms in the house.

19. Assignment on Model Evaluation metrics and Techniques for Regression


Build a linear regression model using the [Link] dataset and evaluate the performance
using regression evaluation metrics.
Sample Solution-
20. Assignment on Model Evaluation metrics and Techniques for Classification
Build a classification model using the [Link] dataset to predict whether a loan will be
approved or not. Evaluate the performance using classification evaluation metrics.

Solution-

You might also like