Improved formatting for markdown codes and fixed title for all.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Practical-A1 (Uber)
|
||||
# Practical-1 (Uber)
|
||||
|
||||
Problem Statement: Predict the price of the Uber ride from a given pickup point to the agreed drop-off location.
|
||||
Perform following tasks:
|
||||
@@ -26,7 +26,7 @@ Perform following tasks:
|
||||
|
||||
## Code
|
||||
|
||||
0. Importing Libraries:
|
||||
### 0. Importing Libraries:
|
||||
|
||||
```python3
|
||||
# Import necessary libraries
|
||||
@@ -41,7 +41,7 @@ from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error
|
||||
from math import radians, cos, sin, asin, sqrt
|
||||
```
|
||||
|
||||
1. Data Loading & Preprocessing:
|
||||
### 1. Data Loading & Preprocessing:
|
||||
|
||||
```python3
|
||||
# Load the dataset
|
||||
@@ -72,7 +72,7 @@ df.drop(['pickup_datetime', 'key'], axis=1, inplace=True, errors='ignore')
|
||||
print("\nColumns after feature extraction:\n", df.columns)
|
||||
```
|
||||
|
||||
2. Outlier Detection & Removal:
|
||||
### 2. Outlier Detection & Removal:
|
||||
|
||||
```python3
|
||||
# Remove entries with unrealistic fares
|
||||
@@ -87,7 +87,7 @@ df = df[(df['dropoff_longitude'] <= 180) & (df['dropoff_longitude'] >= -180)]
|
||||
print("Data shape after removing outliers:", df.shape)
|
||||
```
|
||||
|
||||
3. Feature Engineering - Distance Calculation:
|
||||
### 3. Feature Engineering - Distance Calculation:
|
||||
|
||||
```python3
|
||||
# Define Haversine function to calculate distance between pickup and drop-off
|
||||
@@ -110,7 +110,7 @@ df['distance_km'] = df.apply(lambda x: haversine(x['pickup_latitude'], x['pickup
|
||||
df = df[df['distance_km'] > 0]
|
||||
```
|
||||
|
||||
4. Correlation Analysis:
|
||||
### 4. Correlation Analysis:
|
||||
|
||||
```python3
|
||||
plt.figure(figsize=(10, 6))
|
||||
@@ -119,7 +119,7 @@ plt.title("Feature Correlation Heatmap")
|
||||
plt.show()
|
||||
```
|
||||
|
||||
5. Model Training:
|
||||
### 5. Model Training:
|
||||
|
||||
```python3
|
||||
# Define features and target
|
||||
@@ -140,7 +140,7 @@ rf_model.fit(X_train, y_train)
|
||||
y_pred_rf = rf_model.predict(X_test)
|
||||
```
|
||||
|
||||
6. Model Evaluation:
|
||||
### 6. Model Evaluation:
|
||||
|
||||
```python3
|
||||
def evaluate_model(y_true, y_pred, model_name):
|
||||
@@ -158,7 +158,7 @@ lr_scores = evaluate_model(y_test, y_pred_lr, "Linear Regression")
|
||||
rf_scores = evaluate_model(y_test, y_pred_rf, "Random Forest Regressor")
|
||||
```
|
||||
|
||||
7. Comparison:
|
||||
### 7. Comparison:
|
||||
|
||||
```python3
|
||||
results = pd.DataFrame({
|
||||
@@ -1,4 +1,4 @@
|
||||
# Practical-A2 (Spam Email Detection)
|
||||
# Practical-2 (Spam Email Detection)
|
||||
|
||||
Problem Statement: Classify the email using the binary classification method. Email Spam detection has two states: a) Normal State – Not Spam, b) Abnormal State – Spam. Use K-Nearest Neighbors and Support Vector Machine for classification. Analyze their performance.
|
||||
|
||||
@@ -20,7 +20,7 @@ Problem Statement: Classify the email using the binary classification method. Em
|
||||
|
||||
## Code
|
||||
|
||||
1. Import libraries:
|
||||
### 1. Import libraries:
|
||||
|
||||
```python3
|
||||
import pandas as pd
|
||||
@@ -32,7 +32,7 @@ import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
```
|
||||
|
||||
2. Load dataset:
|
||||
### 2. Load dataset:
|
||||
|
||||
```python3
|
||||
df = pd.read_csv("emails.csv", encoding="ISO-8859-1") # Adjust path if needed
|
||||
@@ -53,7 +53,7 @@ print(df.columns)
|
||||
print(df.head(5))
|
||||
```
|
||||
|
||||
3. Data splitting (training and testing):
|
||||
### 3. Data splitting (training and testing):
|
||||
|
||||
```python3
|
||||
X_train, X_test, y_train, y_test = train_test_split(
|
||||
@@ -61,7 +61,7 @@ X_train, X_test, y_train, y_test = train_test_split(
|
||||
)
|
||||
```
|
||||
|
||||
4. KNN:
|
||||
### 4. KNN:
|
||||
|
||||
```python3
|
||||
knn = KNeighborsClassifier(n_neighbors=5)
|
||||
@@ -74,7 +74,7 @@ print("Classification Report:\n", classification_report(y_test, y_pred_knn))
|
||||
print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred_knn))
|
||||
```
|
||||
|
||||
5. SVM:
|
||||
### 5. SVM:
|
||||
|
||||
```python3
|
||||
svm = SVC(kernel='linear', random_state=42) # Linear kernel for binary classification
|
||||
@@ -87,7 +87,7 @@ print("Classification Report:\n", classification_report(y_test, y_pred_svm))
|
||||
print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred_svm))
|
||||
```
|
||||
|
||||
6. Plotting:
|
||||
### 6. Plotting:
|
||||
|
||||
```python3
|
||||
fig, ax = plt.subplots(1, 2, figsize=(12, 5))
|
||||
@@ -1,4 +1,4 @@
|
||||
# Practical-A3 (Gradient Descent Algorithm)
|
||||
# Practical-4 (Gradient Descent Algorithm)
|
||||
|
||||
Problem Statement: Implement Gradient Descent Algorithm to find the local minima of a function. For example, find the local minima of the function y=(x+3)² starting from the point x=2.
|
||||
|
||||
@@ -16,14 +16,14 @@ Problem Statement: Implement Gradient Descent Algorithm to find the local minima
|
||||
|
||||
## Code
|
||||
|
||||
0. Import libraries:
|
||||
### 0. Import libraries:
|
||||
|
||||
```python3
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
```
|
||||
|
||||
1. Define the function and its derivative:
|
||||
### 1. Define the function and its derivative:
|
||||
|
||||
```python3
|
||||
def f(x):
|
||||
@@ -33,7 +33,7 @@ def grad_f(x):
|
||||
return 2 * (x + 3) # derivative of f(x)
|
||||
```
|
||||
|
||||
2. Initialize parameters for Gradient Descent:
|
||||
### 2. Initialize parameters for Gradient Descent:
|
||||
|
||||
```python3
|
||||
x_current = 2 # starting point
|
||||
@@ -43,7 +43,7 @@ max_iterations = 25 # maximum iterations
|
||||
history = [x_current] # sotring history
|
||||
```
|
||||
|
||||
3. Gradient Descent Loop:
|
||||
### 3. Gradient Descent Loop:
|
||||
|
||||
```python3
|
||||
for i in range(max_iterations):
|
||||
@@ -60,14 +60,14 @@ for i in range(max_iterations):
|
||||
print(f"Iteration {i+1}: x = {x_current:.4f}, f(x) = {f(x_current):.4f}")
|
||||
```
|
||||
|
||||
4. Print the result:
|
||||
### 4. Print the result:
|
||||
|
||||
```python3
|
||||
print("Local minima at x =", x_current)
|
||||
print("Function value at local minima y =", f(x_current))
|
||||
```
|
||||
|
||||
5. Plotting:
|
||||
### 5. Plotting:
|
||||
|
||||
```python3
|
||||
plt.plot(history, [f(val) for val in history], marker='o')
|
||||
@@ -1,4 +1,4 @@
|
||||
# Practical-A6 (Clustering)
|
||||
# Practical-6 (Clustering)
|
||||
|
||||
Problem Statement: Implement K-Means clustering/ hierarchical clustering on `sales_data_sample.csv` dataset. Determine the number of clusters using the elbow method.
|
||||
|
||||
Reference in New Issue
Block a user