my code stock.com

aravindh ram

Breast cancer prediction using svc
by aravindh ram

Snippet options

Download: Download snippet as breast-cancer-prediction-using-svc.py.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

# coding: utf-8

# In[1]:


import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')


# In[17]:


from sklearn.datasets import load_breast_cancer


# In[19]:


cancer=load_breast_cancer()


# In[20]:


cancer.keys()


# In[31]:


bs=pd.DataFrame(cancer["data"],columns=cancer["feature_names"])


# In[29]:


bs.head()


# In[32]:


from sklearn.model_selection import train_test_split


# In[34]:


X=bs
y=cancer["target"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)


# In[35]:


from sklearn.svm import SVC


# In[36]:


m=SVC()


# In[37]:


m.fit(X_train,y_train)


# In[38]:


pred=m.predict(X_test)


# In[40]:


from sklearn.metrics import confusion_matrix,classification_report


# In[42]:


print(classification_report(y_test,pred))
print("/n")
print(confusion_matrix(y_test,pred))


# In[98]:


param_grid={"C":[2,5,10,20],"gamma":[0.1,0.01,0.11,0.001],'kernel': ['rbf']}


# In[99]:


from sklearn.model_selection import GridSearchCV


# In[100]:


cv=GridSearchCV(SVC(),param_grid,refit=True,verbose=2)


# In[101]:


cv.fit(X_test,y_test)


# In[102]:


cv.best_params_


# In[103]:


cv.best_estimator_


# In[104]:


predictt=cv.predict(X_test)


# In[105]:


from sklearn.metrics import classification_report,confusion_matrix


# In[106]:


print(confusion_matrix(y_test,predictt))
print("/n")
print(classification_report(y_test,predictt))


Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.