Vertopal.com_ML LAB 8
Vertopal.com_ML LAB 8
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.cluster import KMeans
from imblearn.over_sampling import SMOTE
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder,
StandardScaler,label_binarize
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score, classification_report,
confusion_matrix,roc_auc_score
from sklearn.ensemble import RandomForestClassifier
df=pd.read_csv("train.csv - train.csv.csv")
df.head()
[5 rows x 21 columns]
df.isnull().sum()
battery_power 0
blue 0
clock_speed 0
dual_sim 0
fc 0
four_g 0
int_memory 0
m_dep 0
mobile_wt 0
n_cores 0
pc 0
px_height 0
px_width 0
ram 0
sc_h 0
sc_w 0
talk_time 0
three_g 0
touch_screen 0
wifi 0
price_range 0
dtype: int64
y_pred = dt_model.predict(X_test)
y_prob_dt = dt_model.predict_proba(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
print("\nConfusion Matrix:\n", confusion_matrix(y_test, y_pred))
print("\nClassification Report:\n", classification_report(y_test,
y_pred))
Accuracy: 0.8725
Confusion Matrix:
[[90 10 0 0]
[ 4 89 7 0]
[ 0 11 76 13]
[ 0 0 6 94]]
Classification Report:
precision recall f1-score support
RandomForestClassifier(max_depth=10, random_state=42)
y_pred = dt_model.predict(X_test)
y_prob_dt = dt_model.predict_proba(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
print("\nConfusion Matrix:\n", confusion_matrix(y_test, y_pred))
print("\nClassification Report:\n", classification_report(y_test,
y_pred))
Accuracy: 0.83
Confusion Matrix:
[[89 11 0 0]
[ 6 82 12 0]
[ 0 17 75 8]
[ 0 0 14 86]]
Classification Report:
precision recall f1-score support
y_pred_rf = rf_model.predict(X_test)
y_prob_rf = rf_model.predict_proba(X_test)
# Accuracy Score
accuracy = accuracy_score(y_test, y_pred_rf)
print(f"Accuracy: {accuracy:.4f}")
# Classification Report
print("Classification Report:\n", classification_report(y_test,
y_pred_rf))
# Confusion Matrix
print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred_rf))
Accuracy: 0.8900
Classification Report:
precision recall f1-score support
Confusion Matrix:
[[95 5 0 0]
[ 5 84 11 0]
[ 0 13 82 5]
[ 0 0 5 95]]
# Scalability Issues
# Hyperparameter Sensitivity
# Model Training – The model learns patterns from the training data by
adjusting its parameters based on the input features and target
variable.
plt.tight_layout()
plt.show()
# Accuracy: 95.75%
# AUC-ROC: 0.9988