BuildingAI :Logistic Regression (Breast Cancer Prediction ) — Intermediate

import pandas as pd
data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data', header=None)data.columns = ['Sample code', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape','Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin','Normal Nucleoli', 'Mitoses','Class']data = data.drop(['Sample code'],axis=1)
predictors = ['Clump Thickness','Uniformity of Cell Size','Uniformity of Cell Shape', 'Marginal Adhesion','Single Epithelial Cell Size','Bland Chromatin','Normal Nucleoli','Mitoses']features = data[predictors]target=data.Class
from sklearn.model_selection import train_test_splitX_train,X_test,y_train,y_test=train_test_split(features,target,test_size=0.25,random_state=0) #splitting the dataset
from sklearn.linear_model import LogisticRegressioncancer=LogisticRegression() cancer.fit(X_train,y_train) #fitting the modelprediction = cancer.predict(X_test) #making prediction
from sklearn import metricscnf_matrix = metrics.confusion_matrix(y_test,pred1)print("Accuracy:",round(metrics.accuracy_score(y_test,pred1),2))
Accuracy output

--

--

Software Engineer• AI/ML• Mobile & Web Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store