BVH

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import numpy as np

import pandas as pd
import tensorflow as tf
import sklearn.metrics as metrics
from sklearn.preprocessing import normalize

# for visualization
import matplotlib.pyplot as plt
import seaborn as sns
import datetime as dt
%matplotlib inline

# Import Warnings
import warnings
warnings.simplefilter(action="ignore")

# for data splitting, transforming and model training


from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# import SVC classifier
from sklearn.svm import SVC
# import metrics to compute accuracy
from sklearn.metrics import accuracy_score

=============================================================
def show_data(data):
sns.pairplot(data,hue="diagnosis")
plt.show()
=============================================================
def preprocessing_data():
#data collection
data = pd.read_csv('Breast.csv') # Load the Iris dataset into a Pandas
DataFrame
print(data.head())
#print(data)
print(data.describe())
#data cleaning
data.drop('id',axis=1,inplace=True) #dropping the id column as it is unecessary
data.drop('Unnamed: 32',axis=1,inplace=True)
# print(data)
print(data.isna().sum())# Checking for missing values
#data.dropna(inplace=True)

print(data.duplicated().sum()) # Checking for dupliacted values


data.drop_duplicates(inplace=True) # Remove dupliacted values
print(data.info())

#show data
#show_data(data)

train, test = train_test_split(data, test_size = 0.2) # the attribute


test_size=0.2 splits the data into 80% and 20% ratio. train=80% and test=20%

X_train=
train[['radius_mean','texture_mean','perimeter_mean','area_mean','smoothness_mean',
'compactness_mean','concavity_mean','concave points_mean',
'symmetry_mean','fractal_dimension_mean','radius_se','texture_se','perimeter_se','a
rea_se','smoothness_se','compactness_se','concavity_se','concave
points_se','symmetry_se','fractal_dimension_se','radius_worst','texture_worst','per
imeter_worst','area_worst','smoothness_worst','compactness_worst','concavity_worst'
,'concave points_worst','symmetry_worst','fractal_dimension_worst']] # taking the
training data features
y_train=train.diagnosis
# output of our training data
X_test=
test[['radius_mean','texture_mean','perimeter_mean','area_mean','smoothness_mean','
compactness_mean','concavity_mean','concave points_mean',
'symmetry_mean','fractal_dimension_mean','radius_se','texture_se','perimeter_se','a
rea_se','smoothness_se','compactness_se','concavity_se','concave
points_se','symmetry_se','fractal_dimension_se','radius_worst','texture_worst','per
imeter_worst','area_worst','smoothness_worst','compactness_worst','concavity_worst'
,'concave points_worst','symmetry_worst','fractal_dimension_worst']] # taking the
training data features # taking test data features
y_test=test.diagnosis

#data transformation

sc = StandardScaler()

X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# #data transformation

return (X_train, X_test, y_train, y_test)


===================================================================================
============
def SVM_Classifier(X_train, X_test, y_train, y_test):
svc=SVC()

# fit classifier to training set

svc.fit(X_train,y_train)

# make predictions on test set


y_pred=svc.predict(X_test)

# compute and print accuracy score


print('Model accuracy score with default hyperparameters: {0:0.4f}'.
format(accuracy_score(y_test, y_pred)))
# Setting parameters of model KNN step by step
===================================================================================
if __name__ == "__main__":
(X_train, X_test, y_train, y_test)=preprocessing_data()
SVM_Classifier(X_train, X_test, y_train, y_test)

You might also like