Challenge

Supervised Learning - Classification Week 7 Challenge

1.

Pros:

  • High accuracy: SVMs are known for their high accuracy, especially in cases where the classes are well-separated.
  • Robust to noise: SVMs are relatively robust to noise, which means that they can still perform well even if the data contains some errors.
  • Scalable: SVMs can be scaled to large datasets without sacrificing accuracy.
  • Interpretability: SVMs are relatively interpretable, which means that it is possible to understand how the model makes its predictions.

Cons:

  • Computationally expensive: SVMs can be computationally expensive to train, especially for large datasets.
  • Sensitive to hyperparameters: The performance of SVMs can be sensitive to the choice of hyperparameters, which can make it difficult to tune the model.
  • Not suitable for all problems: SVMs are not suitable for all problems, such as problems where the classes are not well-separated.

Overall, SVMs are a powerful machine learning algorithm that can be used for a variety of tasks. They are known for their high accuracy and robustness to noise. However, they can be computationally expensive to train and sensitive to hyperparameters.

2.

import numpy as np
import pandas as pd
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_auc_score, log_loss

# Load the dataset
data = pd.read_csv(r"C:\Users\venka\Downloads\Mechanical_datasets-20230715T140641Z-001.zip.csv",encoding="unicode_escape")
data = pd.read_csv(r"C:\Users\venka\Downloads\__MACOSX-20230715T140623Z-001.zip.csv,"encoding="unicode_escape")

# Split the data into train and test sets
X_train, X_test, y_train, y_test = train_test_split(data.drop("Other_Faults", axis=1), data["Other_Faults"], test_size=0.25)

# Train the SVM classifier
clf = SVC(kernel="linear", C=1.0, gamma="scale")
clf.fit(X_train, y_train)

# Evaluate the performance of the classifier
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)
auc = roc_auc_score(y_test, y_pred)
log_loss = log_loss(y_test, y_pred)

print("Accuracy:", accuracy)
print("Precision:", precision)
print("Recall:", recall)
print("F1:", f1)
print("AUC:", auc)
print("Log loss:", log_loss)

conclusion :The output of the code will be the accuracy, precision, recall, F1 score, AUC, and log loss of the SVM classifier. The results will vary depending on the hyperparameters that are used.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.