Advertisement
gk231192

Module 9.3 SVM

Jul 3rd, 2025
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # 1. Data Set Up
  2.  
  3. import pandas as pd
  4. import numpy as np
  5. from sklearn.model_selection import train_test_split
  6. from sklearn.preprocessing import StandardScaler
  7. import seaborn as sns
  8. import matplotlib.pyplot as plt
  9. from sklearn.metrics import roc_curve, roc_auc_score
  10.  
  11.  
  12. # Load Titanic dataset
  13. titanic = sns.load_dataset('titanic')
  14.  
  15. # Keep only selected columns and drop rows with missing values
  16. df = titanic[['survived', 'sex', 'age', 'fare', 'pclass']].dropna()
  17. df['sex'] = df['sex'].map({'male': 0, 'female': 1})
  18.  
  19. # Feature matrix and target vector
  20. X = df[['sex', 'age', 'fare', 'pclass']]
  21. y = df['survived']
  22.  
  23. # Train-test split
  24. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
  25.  
  26. # Feature scaling
  27. scaler = StandardScaler()
  28. X_train_scaled = scaler.fit_transform(X_train)
  29. X_test_scaled = scaler.transform(X_test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement