Ex No: 1
Aim:
To explore a dataset and describe it using basic statistics and represent it using simple graphs
Algorithm:
1. Start the program.
2. Import required libraries (pandas, numpy, matplotlib).
3. Create or load the dataset into a DataFrame.
4. Display first few rows using head().
5. Check dataset structure using info().
6. Generate summary statistics using describe().
7. Calculate: Mean, Median, Standard deviation, Minimum and Maximum
8. Plot:
○ Histogram for Salary
○ Bar chart for Department count
○ Scatter plot for Age vs Salary
9. Display graphs.
Ex No: 2
Aim:
To group data and find averages or counts for each group.
Algorithm:
1. Import the pandas library.
2. Create a DataFrame with employee data.
3. Group the data by Department using groupby().
4. Calculate:
○ Average Salary using mean()
○ Employee count using count()
5. Group the data by City.
6. Calculate average Experience.
7. Display the results.
8. Stop the program.
Ex No: 3
Aim:
To build a simple machine learning model from a dataset and show how well it works.
Algorithm:
1. Import required libraries.
2. Load Iris dataset from sklearn.
3. Explore dataset (shape, classes).
1
4. Split into features (X) and target (y).
5. Perform train-test split.
6. Standardize features.
7. Train Support Vector Machine classifier.
8. Perform cross-validation.
9. Evaluate using:
a. Accuracy
b. Confusion Matrix
c. Classification Report
10. Display results.
Ex No: 4
Aim:
To use graphs to find patterns or trends in a dataset.
Algorithm:
1. Import required libraries (pandas, matplotlib, seaborn).
2. Load the Iris dataset.
3. Convert it into a DataFrame.
4. Plot:
○ Line plot
○ Scatter plot
○ Pair plot
○ Box plot
5. Analyze patterns and relationships.
6. Display graphs.
Ex No: 5
Aim:
To compare two or more columns to find relationships in a dataset.
Algorithm:
1. Import required libraries (pandas, matplotlib, seaborn).
2. Load the Iris dataset.
3. Convert it into a DataFrame.
4. Select numerical columns.
5. Compute correlation matrix using corr().
6. Plot:
○ Scatter plot (between two variables)
○ Heatmap (for multiple variables)
7. Interpret relationships.
Ex No: 6
Aim:
2
To find the average, spread, and z-scores for numbers in a dataset.
Algorithm:
1. Import numpy and pandas
2. Create dataset
3. Calculate mean using mean()
4. Calculate variance and standard deviation
5. Compute z-scores
6. Display results
Ex No: 7
Aim:
To find which values are close to the average and which are far using z-scores.
Algorithm:
1. Input dataset
2. Compute mean
3. Compute standard deviation
4. Calculate z-score for each value
5. Compare absolute z-score with threshold (1 or 2)
6. Classify values as close or far
Ex No: 8
Aim:
To use a scatter plot to visualize the relationship between two variables and calculate the
correlation coefficient (r) to measure the strength and direction of their relationship.
Algorithm:
1. Start
2. Import required libraries
3. Create or load dataset
4. Plot scatter plot between X and Y
5. Calculate correlation using corr()
6. Display correlation value
7. Interpret result
3
Ex No: 9
Aim:
To find the line of best fit (regression line) for two variables. Calculate r² to see how well the line
fits the data.
Algorithm:
1. Input dataset
2. Calculate regression coefficients (a, b)
3. Form regression equation
4. Plot scatter plot
5. Plot regression line
6. Calculate r²
7. Interpret result
Ex No: 10
Aim:
To use a Multiple Linear Regression model to predict a target variable from multiple inputs,
and plot the predicted vs. actual values to evaluate model performance.
Algorithm:
1. Import required libraries
2. Create/load dataset
3. Separate features (X) and target (y)
4. Split into train and test sets
5. Train Multiple Linear Regression model
6. Predict test data
7. Calculate R² score
8. Plot Actual vs Predicted values
4
9. Interpret results
Ex No: 11
Aim:
To create a dashboard or summary using charts and key numbers.
Algorithm
1. Import required libraries
2. Create or load dataset
3. Calculate key metrics:
○ Total Sales
○ Average Sales
○ Maximum Sales
○ Total Orders
4. Create dashboard layout using matplotlib subplots
5. Plot:
○ Line chart (Sales trend)
○ Bar chart (Sales by category)
○ Pie chart (Category contribution)
6. Display dashboard
7. Interpret results
Ex No: 12
Aim:
To clean and preprocess a dataset by handling missing values, scaling features, treating outliers,
and creating dummy variables.
Algorithm
1. Import required libraries (pandas, numpy, sklearn).
2. Create or load the dataset into a DataFrame.
3. Identify missing values using isnull().
4. Replace missing numerical values with the mean of the column.
5. Detect outliers in Salary using IQR method.
6. Cap outliers using lower and upper bounds.
7. Separate numerical and categorical columns.
8. Apply feature scaling (StandardScaler or MinMaxScaler) on numerical features.
9. Convert categorical variables into dummy variables using get_dummies().
10. Combine scaled numerical data and dummy variables.
11. Display cleaned dataset.
5
Ex No:13
Aim:
To train and tune a model using cross-validation to understand and manage the bias variance
trade-off
Algorithm:
1. Import required libraries.
2. Load dataset.
3. Split dataset into features (X) and target (y).
4. Divide dataset into training and testing sets.
5. Choose a model (e.g., Decision Tree).
6. Define different hyperparameter values (e.g., max_depth).
7. Apply K-Fold Cross-Validation.
8. Calculate cross-validation accuracy for each parameter.
9. Select the best parameter with highest validation score.
10. Train final model using best parameter.
11. Evaluate final model on test data.
12. Analyze bias-variance behavior.
Ex No: 14
Aim:
To Perform Outlier Analysis on any data set.
Algorithm
1. Start the program.
2. Import required libraries (pandas, numpy, matplotlib, seaborn).
3. Create or load dataset into DataFrame.
4. Select numerical column for analysis (PurchaseAmount).
IQR Method:
5. Compute Q1 (25th percentile).
6. Compute Q3 (75th percentile).
6
7. Calculate IQR = Q3 − Q1.
8. Compute lower bound = Q1 − 1.5 × IQR.
9. Compute upper bound = Q3 + 1.5 × IQR.
10. Identify values outside bounds as outliers.
Z-Score Method:
11. Compute mean and standard deviation.
12. Calculate Z-score for each value.
13. Identify values where |Z| > 3 as outliers.
Visualization:
14. Plot boxplot to visualize outliers.
15. Display detected outliers.
Ex No:15
Aim:
To create and reshape matrices, apply matrix operations, and visualize data using 2D heatmaps
and 3D surface plots.
Problem Statement:
A data scientist is analyzing sales performance data of 4 regions over 5 months.
You are required to:
1. Create a matrix representing sales data.
2. Reshape the matrix into different dimensions.
3. Perform matrix operations:
○ Transpose
○ Matrix multiplication
○ Determinant
○ Inverse
4. Normalize the matrix.
5. Visualize the data using:
○ 2D Heatmap
○ 3D Surface Plot
7
Use NumPy and Matplotlib for implementation.
Algorithm:
1. Start the program.
2. Import required libraries: NumPy, Matplotlib.
3. Create a 4×5 matrix representing sales data.
4. Display the original matrix.
5. Reshape the matrix into 5×4 format.
6. Compute transpose of the matrix.
7. Perform matrix multiplication (Matrix × Transpose).
8. Extract a square sub-matrix (4×4) for determinant calculation.
9. Compute determinant.
10. If determinant ≠ 0, compute inverse.
11. Normalize matrix values using Min-Max normalization.
12. Plot 2D heatmap using imshow().
13. Create meshgrid and plot 3D surface using plot_surface().
14. Display plots.
Ex No:16
Aim:
Build a DataFrame, perform aggregation and transformation, filter and sort data, remove
duplicates, group, and join tables.
Algorithm
1. Import pandas library.
2. Create Employee DataFrame.
3. Create Bonus DataFrame.
4. Remove duplicate rows based on EmpID.
8
5. Merge Employee and Bonus tables using EmpID.
6. Calculate total and average salary (aggregation).
7. Create BonusAmount column using salary and bonus percent (transformation).
8. Create TotalIncome column.
9. Filter employees where Experience ≥ 3 and Salary > 50000.
10. Sort the filtered data in descending order of TotalIncome.
11. Group by Department.
12. Compute sum of TotalIncome, mean of PerformanceRating, and count of employees.
13. Display results.
Ex No: 17
Aim:
To simulate SQL-style operations like filtering, ordering, deduplication, and grouping in a
DataFrame.
Algorithm:
1. Import the pandas library.
2. Create the Customers DataFrame with the attributes CustomerID, CustomerName, City,
JoinDate, and Membership.
3. Create the Orders DataFrame with the attributes OrderID, CustomerID, OrderDate,
Product, Category, Quantity, and Price.
4. Create the Payments DataFrame with the attributes PaymentID, OrderID, PaymentMode,
and PaymentStatus.
5. Merge the Orders and Customers DataFrames using CustomerID as the common key.
6. Merge the resulting DataFrame with the Payments DataFrame using OrderID as the
common key.
7. Apply filtering conditions to select records where PaymentStatus is “Completed”,
Category is “Electronics”, and OrderDate is greater than 01-01-2023.
8. Create a new column named Revenue by multiplying Quantity and Price.
9. Remove duplicate records based on OrderID.
10. Group the filtered data by City and Membership.
11. Calculate Total Revenue as the sum of Revenue.
12. Calculate Average Order Value as the mean of Revenue.
13. Calculate the number of unique customers using distinct CustomerID count.
14. Sort the grouped result in descending order based on Total Revenue.
15. Select the top five records from the sorted result.
16. Display the final output.