-
Notifications
You must be signed in to change notification settings - Fork 0
/
code1.py
50 lines (40 loc) · 1.57 KB
/
code1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 2 11:16:36 2022
@author: tahmi
"""
import numpy as np
import pandas as pd
import missingno as msno
import seaborn as sn
import matplotlib.pyplot as plt
from sklearn.preprocessing import normalize, StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_score
# Loading Data
features = ['age', 'sex', 'cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach', 'exang', 'oldpeak', 'slop', 'ca', 'thal', 'heartdisease']
clivelandData = pd.read_csv('Dataset/cleveland.csv', names = features)
hungarianData = pd.read_csv('Dataset/hungarian.csv', names = features)
switzerlandData = pd.read_csv('Dataset/switzerland.csv', names = features)
datatemp = [clivelandData, hungarianData, switzerlandData]
data = pd.concat(datatemp)
# Preprocessing Data
data = data.drop(['slop', 'ca', 'thal'], axis=1)
data = data.replace('?', np.nan)
imp = SimpleImputer(missing_values=np.nan, strategy='mean')
imputedData = imp.fit_transform(data)
# Creating Test and Train Data
X_train, X_test, y_train, y_test = train_test_split(imputedData[:, :-1], imputedData[:, -1], test_size=0.3, random_state=42)
# Scale Data
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Build and Train the Model
classifier = svm.SVC(kernel='rbf')
classifier.fit(X_train, y_train)
preds = classifier.predict(X_test)
# Accuracy of Predictions
score = accuracy_score(y_test, preds)
print("Prediction Accuracy is : %f" %(score * 100))