Posts

Download any dataset and do the following: a. Count number of categorical and numeric features b. Remove one correlated attribute (if any) c. Display five-number summary of each attribute and show it visually

Download any dataset and do the following: a. Count number of categorical and numeric features b. Remove one correlated attribute (if any) c. Display five-number summary of each attribute and show it visually CODE  import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # Load the Iris dataset into a pandas DataFrame iris_df = pd.read_csv('iris.data', header=None,                       names=['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'class']) # Count the number of categorical and numeric features categorical_features = iris_df.select_dtypes(include=['object']).columns numeric_features = iris_df.select_dtypes(include=['float64']).columns print(f"Number of categorical features: {len(categorical_features)}") print(f"Number of numeric features: {len(numeric_features)}") # Calculate the correlation matrix correlation_matrix = iris_df[numeric_features].corr() # Find the ...

Using Titanic dataset, do the following: a. Find total number of passengers with age less than 30 b. Find total fare paid by passengers of first class c. Compare number of survivors of each passenger class

  Using Titanic dataset, do the following: a. Find total number of passengers with age less than 30 b. Find total fare paid by passengers of first class c. Compare number of survivors of each passenger class CODE import seaborn as sns # Load the Titanic dataset from seaborn titanic = sns.load_dataset('titanic') # Find the total number of passengers with age less than 30 passengers_age_less_than_30 = titanic[titanic['age'] < 30] total_passengers_age_less_than_30 = len(passengers_age_less_than_30) print(f"Total number of passengers with age less than 30: {total_passengers_age_less_than_30}") # Find the total fare paid by passengers of first class total_fare_first_class = titanic[titanic['class'] == 'First']['fare'].sum() print(f"Total fare paid by passengers of first class: {total_fare_first_class}") # Compare the number of survivors of each passenger class survivors_by_class = titanic.groupby('class')['survived...

Load Titanic data from sklearn library, plot the following with proper legend and axis labels: a. Plot bar chart to show the frequency of survivors and non-survivors for male and female passengers separately b. Draw a scatter plot for any two selected features c. Compare density distribution for features age and passenger fare d. Use a pair plot to show pairwise bivariate distribution

 Load Titanic data from sklearn library, plot the following with proper legend and axis labels: a. Plot bar chart to show the frequency of survivors and non-survivors for male and female passengers separately b. Draw a scatter plot for any two selected features c. Compare density distribution for features age and passenger fare d. Use a pair plot to show pairwise bivariate distribution CODE import seaborn as sns import matplotlib.pyplot as plt # Load the Titanic dataset from seaborn titanic = sns.load_dataset('titanic') # Plot bar chart to show the frequency of survivors and non-survivors for male and female passengers separately plt.figure(figsize=(8, 6)) sns.countplot(x='sex', hue='survived', data=titanic) plt.xlabel('Sex') plt.ylabel('Frequency') plt.title('Survivors vs Non-Survivors by Gender') plt.legend(title='Survived', labels=['No', 'Yes']) plt.show() # Draw a scatter plot for any two selected features plt....

Import iris data using sklearn library . Compute mean, mode, median, standard deviation, confidence interval and standard error for each feature ii. Compute correlation coefficients between each pair of features and plot heatmap iii. Find covariance between length of sepal and petal iv. Build contingency table for class feature

Import iris data using sklearn library or (Download IRIS data from: (https://archive.ics.uci.edu/ml/datasets/iris or import it from sklearn.datasets) i. Compute mean, mode, median, standard deviation, confidence interval and standard error for each feature ii. Compute correlation coefficients between each pair of features and plot heatmap iii. Find covariance between length of sepal and petal iv. Build contingency table for class feature CODE  import numpy as np import pandas as pd from sklearn.datasets import load_iris from scipy import stats import seaborn as sns import matplotlib.pyplot as plt # Load the Iris dataset iris = load_iris() data = iris.data feature_names = iris.feature_names target = iris.target target_names = iris.target_names # Convert data to a pandas DataFrame for easier analysis df = pd.DataFrame(data, columns=feature_names) df['class'] = target_names[target] # Compute mean, mode, median, standard deviation, confidence interval, and standard error for each f...

Load a Pandas dataframe with a selected dataset. Identify and count the missing values in a dataframe. Clean the data after removing noise as follows: a. Drop duplicate rows. b. Detect the outliers and remove the rows having outliers c. Identify the most correlated positively correlated attributes and negatively correlated attributes

  Load a Pandas dataframe with a selected dataset. Identify and count the missing values in a dataframe. Clean the data after removing noise as follows: a. Drop duplicate rows. b. Detect the outliers and remove the rows having outliers c. Identify the most correlated positively correlated attributes and negatively correlated attributes CODE import pandas as pd # Load the dataset df = pd.read_csv('your_dataset.csv') # Identify and count missing values missing_values = df.isnull().sum() print("Missing values:") print(missing_values) # Drop duplicate rows df = df.drop_duplicates() # Detect outliers and remove rows with outliers def remove_outliers(df, column):     Q1 = df[column].quantile(0.25)     Q3 = df[column].quantile(0.75)     IQR = Q3 - Q1     lower_bound = Q1 - 1.5 * IQR     upper_bound = Q3 + 1.5 * IQR     return df[(df[column] >= lower_bound) & (df[column] <= upper_bound)] columns_to_check = ['column1', 'c...

Implement queue data structure and its operations using arrays.

 Implement queue data structure and its operations using arrays. #include <iostream> using namespace std; const int MAX_SIZE = 100; class Queue { private:     int front;          // Index of the front element in the queue     int rear;           // Index of the rear element in the queue     int arr[MAX_SIZE];  // Array to store the queue elements public:     Queue() {         front = -1;     // Initialize front to -1 to indicate an empty queue         rear = -1;      // Initialize rear to -1 to indicate an empty queue     }     bool isEmpty() {         return (front == -1);     }     bool isFull() {         return ((rear + 1) % MAX_SIZE == front);     }     void enqueue(int value) {         ...

Implement stack data structure and its operations using singly linked lists.

Implement stack data structure and its operations using singly linked lists.  #include <iostream> using namespace std; class Node { public:     int data;    // Data stored in the node     Node* next;  // Pointer to the next node     // Constructor     Node(int value) {         data = value;         next = nullptr;     } }; class Stack { private:     Node* top;  // Pointer to the top node of the stack public:     // Constructor     Stack() {         top = nullptr;     }     bool isEmpty() {         return (top == nullptr);     }     void push(int value) {         Node* newNode = new Node(value);         newNode->next = top;         top = newNode;         cout << "Pushed ele...

Implement stack data structure and its operations using arrays.

Implement stack data structure and its operations using arrays.  #include <iostream> using namespace std; const int MAX_SIZE = 100; class Stack { private:     int top;            // Index of the top element in the stack     int arr[MAX_SIZE];  // Array to store the stack elements public:     Stack() {         top = -1;       // Initialize top to -1 to indicate an empty stack     }     bool isEmpty() {         return (top == -1);     }     bool isFull() {         return (top == MAX_SIZE - 1);     }     void push(int value) {         if (isFull()) {             cout << "Stack Overflow: Cannot push element " << value << ". Stack is full." << endl;             return;   ...

Implement singly linked lists.

 Implement singly linked lists. #include <iostream> using namespace std; // Node class represents a single node in the linked list class Node { public:     int data;        // Data stored in the node     Node* next;    // Pointer to the next node     // Constructor     Node(int value) {         data = value;         next = nullptr;     } }; // Linked list class represents the entire linked list class LinkedList { private:     Node* head;    // Pointer to the head node public:     // Constructor     LinkedList() {         head = nullptr;     }     // Destructor to free memory     ~LinkedList() {         Node* current = head;         while (current != nullptr) {             Node* next = current->next...

Implement following recursive functions: a. Factorial of a number b. Nth fibonacci number

Implement following recursive functions: a. Factorial of a number b. Nth fibonacci number  #include <iostream> using namespace std; // Recursive function to calculate the factorial of a number int factorial(int n) {     // Base case: factorial of 0 is 1     if (n == 0) {         return 1;     }     // Recursive case: multiply n with factorial of (n-1)     return n * factorial(n - 1); } // Recursive function to calculate the nth Fibonacci number int fibonacci(int n) {     // Base cases: Fibonacci numbers for n = 0 and n = 1 are 0 and 1 respectively     if (n == 0) {         return 0;     }     if (n == 1) {         return 1;     }     // Recursive case: sum of the previous two Fibonacci numbers     return fibonacci(n - 1) + fibonacci(n - 2); } int main() {     int number;     // F...