<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Karan Choudhary</title>
    <description>The latest articles on DEV Community by Karan Choudhary (@ncukaran18csu103).</description>
    <link>https://dev.to/ncukaran18csu103</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F449610%2Fed8cb5e9-a3f4-4328-8060-9ec28018e328.jpg</url>
      <title>DEV Community: Karan Choudhary</title>
      <link>https://dev.to/ncukaran18csu103</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ncukaran18csu103"/>
    <language>en</language>
    <item>
      <title>End to End Deployment of Heart Disease Prediction Through Flask With Machine Learning Algorithm</title>
      <dc:creator>Karan Choudhary</dc:creator>
      <pubDate>Thu, 03 Sep 2020 17:55:54 +0000</pubDate>
      <link>https://dev.to/ncukaran18csu103/end-to-end-deployment-of-heart-disease-prediction-through-flask-with-machine-learning-algorithm-406f</link>
      <guid>https://dev.to/ncukaran18csu103/end-to-end-deployment-of-heart-disease-prediction-through-flask-with-machine-learning-algorithm-406f</guid>
      <description>&lt;p&gt;Artificial Intelligence directly translates to conceptualizing and building machines that can think and hence are independently capable of performing tasks, thus exhibiting intelligence. If this advancement in technology is a boon or a bane to humans and our surroundings is a never-ending debate.&lt;br&gt;
Every coin has its two faces so it is difficult to judge on the basis as a human being and make a quick decision about it and say about the technology. Everything in this world whether it is living or no living it has its positive and negative impact over the world and is cache is popularity when it is fruitful for the society and living being other than its ill and major impact for the long term on the living beings.&lt;br&gt;
Healthcare is no different. Particularly in the case of automation, machine learning, and artificial intelligence (AI), doctors, hospitals, insurance companies, and industries with ties to healthcare have all been impacted - in many cases in more positive, substantial ways than other industries.&lt;br&gt;
Before starting we should discuss about the dataset we are using for the prediction&amp;nbsp;.&lt;br&gt;
Age,Sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,slope,ca,&lt;br&gt;
thal, Target&lt;br&gt;
These are some of the major independent value of the dataset which we are training for the prediction of the heart disease.&lt;br&gt;
Installing Flask on your&amp;nbsp;Machine&lt;br&gt;
Installing Flask is simple and straightforward. Here, I am assuming you already have Python 3 and pip installed. To install Flask, you need to run the following command:&lt;br&gt;
sudo apt-get install python3-flask&lt;br&gt;
pip install flask&lt;br&gt;
That's it! You're all set to dive into the problem statement take one step closer to deploying your machine learning model through flask.&lt;br&gt;
Starting of implementation&lt;br&gt;
Here we have folder structure of the machine learning deployment model through flask.&lt;br&gt;
We will be implementing these code in jupyter and sublime text editor.Implementing the machine learning models lets go for importing library.&lt;/p&gt;

&lt;h1&gt;
  
  
  import libraries
&lt;/h1&gt;

&lt;p&gt;import pandas as pd # for data manipulation or analysis&lt;br&gt;
import numpy as np # for numeric calculation&lt;br&gt;
import matplotlib.pyplot as plt # for data visualization&lt;br&gt;
import seaborn as sns # for data visualization&lt;br&gt;
import pickle #for dumping the model or we can use joblib library&lt;br&gt;
Now next step is to load the data through pandas.&lt;br&gt;
heart_df = pd.read_csv('heart_disease.csv')&lt;br&gt;
Now next step is to see the data frame of the data.&lt;/p&gt;

&lt;h1&gt;
  
  
  Head of heart DataFrame
&lt;/h1&gt;

&lt;p&gt;heart_df.head(6)&lt;br&gt;
Info about the model(gives null value and count the non float values)&lt;/p&gt;

&lt;h1&gt;
  
  
  Information of heart Dataframe
&lt;/h1&gt;

&lt;p&gt;heart_df.info()&lt;br&gt;
Numerical description about the data (mean,median,25%,interquantile range and many other value of each feature.&lt;/p&gt;

&lt;h1&gt;
  
  
  Numerical distribution of data
&lt;/h1&gt;

&lt;p&gt;heart_df.describe()&lt;br&gt;
Heatmap&lt;/p&gt;

&lt;h1&gt;
  
  
  heatmap of DataFrame
&lt;/h1&gt;

&lt;p&gt;plt.figure(figsize=(16,9))&lt;br&gt;
sns.heatmap(heart_df)&lt;br&gt;
Heatmap of a correlation matrix&lt;br&gt;
heart_df.corr()#gives the correlation between them&lt;/p&gt;

&lt;h1&gt;
  
  
  Heatmap of Correlation matrix of breast heartDataFrame
&lt;/h1&gt;

&lt;p&gt;plt.figure(figsize=(20,20))&lt;br&gt;
sns.heatmap(heart_df.corr(), annot = True, cmap ='coolwarm', linewidths=2)&lt;br&gt;
Split DataFrame in Train and&amp;nbsp;Test&lt;br&gt;
Input variable&lt;/p&gt;

&lt;h1&gt;
  
  
  input variable
&lt;/h1&gt;

&lt;p&gt;X = heart_df.drop(['target'], axis = 1) &lt;br&gt;
X.head(6)&lt;br&gt;
Output variable&lt;/p&gt;

&lt;h1&gt;
  
  
  output variable
&lt;/h1&gt;

&lt;p&gt;y = heart_df['target'] &lt;br&gt;
y.head(6)&lt;br&gt;
Split dataset for training&amp;nbsp;and&lt;/p&gt;

&lt;h1&gt;
  
  
  split dataset into train and test
&lt;/h1&gt;

&lt;p&gt;from sklearn.model_selection import train_test_split&lt;br&gt;
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state= 5)&lt;br&gt;
Feature scaling of&amp;nbsp;data&lt;br&gt;
from sklearn.preprocessing import StandardScaler&lt;br&gt;
sc = StandardScaler()&lt;br&gt;
X_train_sc = sc.fit_transform(X_train)&lt;br&gt;
X_test_sc = sc.transform(X_test)&lt;br&gt;
Machine Learning Model&amp;nbsp;Building&lt;br&gt;
1.Suppor vector Classifier&lt;br&gt;
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score  #for classification report&lt;/p&gt;

&lt;h1&gt;
  
  
  Svm model
&lt;/h1&gt;

&lt;p&gt;from sklearn.svm import SVC&lt;br&gt;
svc_classifier = SVC()&lt;br&gt;
svc_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_scv = svc_classifier.predict(X_test)&lt;br&gt;
accuarcy_svm=accuracy_score(y_test, y_pred_scv)&lt;br&gt;
print(accuarcy_svm)#Output 0.5789473684210527&lt;br&gt;
2.Logistic Regression&lt;/p&gt;

&lt;h1&gt;
  
  
  Logistic Regression
&lt;/h1&gt;

&lt;p&gt;from sklearn.linear_model import LogisticRegression&lt;br&gt;
lr_classifier = LogisticRegression(random_state = 51, penalty = 'l1')&lt;br&gt;
lr_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_lr = lr_classifier.predict(X_test)&lt;br&gt;
accuracy_score(y_test, y_pred_lr)&lt;br&gt;
accuarcy_lr=accuracy_score(y_test, y_pred_lr)&lt;br&gt;
print(accuarcy_lr)#Output 0.9736842105263158&lt;br&gt;
3.Decision Tree Classifier&lt;/p&gt;

&lt;h1&gt;
  
  
  Decision Tree Classifier
&lt;/h1&gt;

&lt;p&gt;from sklearn.tree import DecisionTreeClassifier&lt;br&gt;
dt_classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 51)&lt;br&gt;
dt_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_dt = dt_classifier.predict(X_test)&lt;br&gt;
accuarcy_dt=accuracy_score(y_test, y_pred_dt)&lt;br&gt;
print(accuarcy_dt)&lt;/p&gt;

&lt;h1&gt;
  
  
  Output 0.9473684210526315
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;XGboost classsifier
# XGBoost Classifier
from xgboost import XGBClassifier
xgb_classifier = XGBClassifier()
xgb_classifier.fit(X_train, y_train)
y_pred_xgb = xgb_classifier.predict(X_test)
y_pred_xgb=accuracy_score(y_test, y_pred_xgb)
accuarcy_xgb=accuracy_score(y_test, y_pred_xgb)
print(accuarcy_xgb)
#Output 0.9823684210526315
Similarly, we have to do for test data and implement them on we can see that their will be no overfitting and underfitting the test data. their should low bias and low variance.
Accuracy on test data and the similar code for test data&amp;nbsp;.
#accuracy of all the classifier test data
Accuracy of Support vector Classifier - 0.5789456522520
Accuracy of Decision tree Classifier -0.8473684210526315
Accuracy of Logistic regression- 0.570456140350877
Accuracy of XGBoost Classifier - 0.982456140350877
As,we can conclude the test data is performing nearly good result in Xgboost classifier with low bias and variance.
For further improving we should go for the tuning method such as randomised search and grid search on Xgboost because we want our accuracy to be more optimal and fix all contraints like precision&amp;nbsp;,recall&amp;nbsp;,beta value and support which are import to satisfy to overcome the Type I and Type II Error.
Randomized search
Applying randomized search on the model which works on sample of data and it works more faster than any search tuning method
params={
"learning_rate" : [0.05, 0.10, 0.15, 0.20, 0.25, 0.30 ] ,
"max_depth" : [ 3, 4, 5, 6, 8, 10, 12, 15],
"min_child_weight" : [ 1, 3, 5, 7 ],
"gamma" : [ 0.0, 0.1, 0.2 , 0.3, 0.4 ],
"colsample_bytree" : [ 0.3, 0.4, 0.5 , 0.7 ] 
}
# Randomized Search
from sklearn.model_selection import RandomizedSearchCV
random_search = RandomizedSearchCV(xgb_classifier, param_distributions=params, scoring= 'roc_auc', n_jobs= -1, verbose= 3)
random_search.fit(X_train, y_train)
Finding the best and optimize parameter.
random_search.best_params_#output
{'min_child_weight': 1,
'max_depth': 12,
'learning_rate': 0.3,
'gamma': 0.3,
'colsample_bytree': 0.7}
random_search.best_estimator_
#output
XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
   colsample_bynode=1, colsample_bytree=0.7, gamma=0.3,
   learning_rate=0.3, max_delta_step=0, max_depth=12,
   min_child_weight=1, missing=None, n_estimators=100, n_jobs=1,
   nthread=None, objective='binary:logistic', random_state=0,
   reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
   silent=None, subsample=1, verbosity=1)
# training XGBoost classifier with best parameters
xgb_classifier_pt = XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=0.4, gamma=0.2,
learning_rate=0.1, max_delta_step=0, max_depth=15,
min_child_weight=1, missing=None, n_estimators=100, n_jobs=1,
nthread=None, objective='binary:logistic', random_state=0,
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
silent=None, subsample=1, verbosity=1)xgb_classifier_pt.fit(X_train, y_train)
y_pred_xgb_pt = xgb_classifier_pt.predict(X_test)
Accuracy after model
accuracy_score(y_test, y_pred_xgb_pt)#output  - 0.9824561403508771
Grid search
Applying grid search on the model which works on whole data.
Training the model
from sklearn.model_selection import GridSearchCV 
grid_search = GridSearchCV(xgb_classifier, param_grid=params, scoring= 'roc_auc', n_jobs= -1, verbose= 3)
grid_search.fit(X_train, y_train)
Now comes the implementing it
xgb_classifier_pt_gs = XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=0.3, gamma=0.0,
learning_rate=0.3, max_delta_step=0, max_depth=3,
min_child_weight=1, missing=None, n_estimators=100, n_jobs=1,
nthread=None, objective='binary:logistic', random_state=0,
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
silent=None, subsample=1, verbosity=1)xgb_classifier_pt_gs.fit(X_train, y_train)
y_pred_xgb_pt_gs = xgb_classifier_pt_gs.predict(X_test)
accuracy_score(y_test, y_pred_xgb_pt_gs)
#output 0.9824561403508771
As,we are getting the nearly same accuracy after applying these tuning method so we will use grid search in this know comes the part of classification report and types of error.
Confusion matrix
It gives the value of true positive and false negative which will help to predict how much our model is optimized to predict it.
from sklearn.metrics import confusion_matrix, classification_report
cm = confusion_matrix(y_test, y_pred_xgb_pt)
plt.title('Heatmap of Confusion Matrix', fontsize = 15)
sns.heatmap(cm, annot = True)
plt.show()
Saving model for deployment
pickle.dump(xgb_classifier_pt, open('heart_disease_detector.pickle', 'wb'))# load model
heart_disease_detector_model = pickle.load(open('heart_disease_detector_detector.pickle', 'rb'))
Now are model is dumb into pickle file.now its time for the flask for the model to deploy.
Now we have to switch towards sublime text editor for the deployment.the main aim is to used html,css with flask in it.
from flask import Flask,render_template,url_for,request
import pandas as pd&amp;nbsp;
from sklearn.externals import joblib
import numpy as np
app = Flask(&lt;strong&gt;name&lt;/strong&gt;)
@app.route('/')
def home():
&amp;nbsp;return render_template('home.html')
def getParameters():
&amp;nbsp;parameters = []
&amp;nbsp;#parameters.append(request.form('name'))
&amp;nbsp;parameters.append(request.form['age'])
&amp;nbsp;parameters.append(request.form['sex'])
&amp;nbsp;parameters.append(request.form['cp'])
&amp;nbsp;parameters.append(request.form['trestbps'])
&amp;nbsp;parameters.append(request.form['chol'])
&amp;nbsp;parameters.append(request.form['fbs'])
&amp;nbsp;parameters.append(request.form['restecg'])
&amp;nbsp;parameters.append(request.form['thalach'])
&amp;nbsp;parameters.append(request.form['exang'])
&amp;nbsp;parameters.append(request.form['oldpeak'])
&amp;nbsp;parameters.append(request.form['slope'])
&amp;nbsp;parameters.append(request.form['ca'])
&amp;nbsp;parameters.append(request.form['thal'])
&amp;nbsp;return parameters
@app.route('/predict',methods=['POST'])
def predict():
&amp;nbsp;model = open("data/Heart_model.pkl","rb")
&amp;nbsp;clfr = joblib.load(model)
if request.method == 'POST':
&amp;nbsp;parameters = getParameters()
&amp;nbsp;inputFeature = np.asarray(parameters).reshape(1,-1)
&amp;nbsp;my_prediction = clfr.predict(inputFeature)
&amp;nbsp;return render_template('result.html',prediction = int(my_prediction[0]))
if &lt;strong&gt;name&lt;/strong&gt; == '&lt;strong&gt;main&lt;/strong&gt;':
&amp;nbsp;app.run(debug=True)
The code here depicts the loading of dumb model and then we are accessing the home.html file for the home page which we can discuss further.
then we have the predict function which will be implemented when we will enter the input 13 constraints as an input in the box and then array of size 13 goes to the data frame for the prediction and return will make the after.html file which tell about the output as an healthy heart according to the value input by user and new webpage open with this classification whelther aperson suffering from it or not.
In this file we have stored the data and then we will come to know about the input through the data entered by the user and we will come to output and with best prediction on the basis of input value we will enter&amp;nbsp;.Basically this file will work when we have data input from the home.html file where user wll enter the data on the basis of his/her profile.
Basically this file works as an home page to the web app through flask. We are counter with the input value on the basic of a person profile and how a person will be responsible for his health and how to mange its health for the future for long lasting&amp;nbsp;.
home of flask&amp;nbsp;appThis webpage helps us to enter the details and then by clicking the predict button we will come to an output about personal heart's health.
This will be predict that the prediction will be healthy heart&amp;nbsp;.
If you want to implement code from your hand then click the button and implement code end to end with explanation in brief.
If u like to read this article and have common interest in similar projects then we can grow our network and can work for more real time projects.
For more details connect with me on my Linkedin account!
THANKS!!!!&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>End to End Deployment of Breast Cancer Prediction Through Machine Learning using Flask
</title>
      <dc:creator>Karan Choudhary</dc:creator>
      <pubDate>Sun, 09 Aug 2020 14:16:08 +0000</pubDate>
      <link>https://dev.to/ncukaran18csu103/end-to-end-deployment-of-breast-cancer-prediction-through-machine-learning-using-flask-2ga5</link>
      <guid>https://dev.to/ncukaran18csu103/end-to-end-deployment-of-breast-cancer-prediction-through-machine-learning-using-flask-2ga5</guid>
      <description>&lt;p&gt;Artificial intelligence in healthcare is the use of complex algorithms and software in another words artificial intelligence (AI) to emulate human cognition in the analysis, interpretation, and comprehension of complicated medical and healthcare data. Specifically, AI is the ability of computer algorithms to approximate conclusions without direct human input.&lt;br&gt;
The aim of health-related AI applications is to analyze relationships between prevention or treatment techniques and patient outcomes.&lt;br&gt;
Before starting of the code and theory part of machine learning first we learn about flask and deployment part.&lt;br&gt;
Flask is a web application framework written in Python. It has multiple modules that make it easier for a web developer to write applications without having to worry about the details like protocol management, thread management, etc.&lt;br&gt;
Flask gives is a variety of choices for developing web applications and it gives us the necessary tools and libraries that allow us to build a web application.&lt;br&gt;
Installing Flask on your&amp;nbsp;Machine&lt;br&gt;
Installing Flask is simple and straightforward. Here, I am assuming you already have Python 3 and pip installed. To install Flask, you need to run the following command:&lt;br&gt;
sudo apt-get install python3-flask&lt;br&gt;
pip install flask&lt;br&gt;
That's it! You're all set to dive into the problem statement take one step closer to deploying your machine learning model through flask.&lt;br&gt;
Starting of implementation&lt;br&gt;
Here we have folder structure of the machine learning deployment model through flask.&lt;br&gt;
We will be implementing these code in jupyter and sublime text editor.Implementing the machine learning models lets go for importing library.&lt;/p&gt;

&lt;h1&gt;
  
  
  import libraries
&lt;/h1&gt;

&lt;p&gt;import pandas as pd # for data manupulation or analysis&lt;br&gt;
import numpy as np # for numeric calculation&lt;br&gt;
import matplotlib.pyplot as plt # for data visualization&lt;br&gt;
import seaborn as sns # for data visualization&lt;br&gt;
import pickle #for dumping the model or we can use joblib library&lt;br&gt;
Now next step is to load the data through pandas.&lt;br&gt;
cancer_df = pd.read_csv('breast_cancer .csv')&lt;br&gt;
Now next step is to see the data frame of the data.&lt;/p&gt;

&lt;h1&gt;
  
  
  Head of cancer DataFrame
&lt;/h1&gt;

&lt;p&gt;cancer_df.head(6)&lt;br&gt;
Info about the model(gives null value and count the non float values)&lt;/p&gt;

&lt;h1&gt;
  
  
  Information of cancer Dataframe
&lt;/h1&gt;

&lt;p&gt;cancer_df.info()&lt;br&gt;
Numerical description about the data (mean,median,25%,interquantile range and many other value of each feature.&lt;/p&gt;

&lt;h1&gt;
  
  
  Numerical distribution of data
&lt;/h1&gt;

&lt;p&gt;cancer_df.describe()&lt;br&gt;
Heatmap&lt;/p&gt;

&lt;h1&gt;
  
  
  heatmap of DataFrame
&lt;/h1&gt;

&lt;p&gt;plt.figure(figsize=(16,9))&lt;br&gt;
sns.heatmap(cancer_df)&lt;br&gt;
Heatmap of a correlation matrix&lt;br&gt;
cancer_df.corr()#gives the correlation between them&lt;/p&gt;

&lt;h1&gt;
  
  
  Heatmap of Correlation matrix of breast cancer DataFrame
&lt;/h1&gt;

&lt;p&gt;plt.figure(figsize=(20,20))&lt;br&gt;
sns.heatmap(cancer_df.corr(), annot = True, cmap ='coolwarm', linewidths=2)&lt;br&gt;
plt.figure(figsize=(16,9))&lt;br&gt;
sns.heatmap(cancer_df)# create second DataFrame by droping target&lt;br&gt;
cancer_df2 = cancer_df.drop(['target'], axis = 1)&lt;br&gt;
print("The shape of 'cancer_df2' is : ", cancer_df2.shape&lt;br&gt;
a&lt;br&gt;
plt.figure(figsize=(16,9))&lt;br&gt;
sns.heatmap(cancer_df)cancer_df2.corrwith(cancer_df.target) # visualize correlation barplot&lt;br&gt;
plt.figure(figsize = (16,5))&lt;br&gt;
ax = sns.barplot(cancer_df2.corrwith(cancer_df.target).index, cancer_df2.corrwith(cancer_df.target))&lt;br&gt;
ax.tick_params(labelrotation = 90) # **** img 10 ***&lt;br&gt;
plotSplit DataFrame in Train and&amp;nbsp;Test&lt;br&gt;
Input variable&lt;/p&gt;

&lt;h1&gt;
  
  
  input variable
&lt;/h1&gt;

&lt;p&gt;X = cancer_df.drop(['target'], axis = 1) &lt;br&gt;
X.head(6)&lt;br&gt;
Output variable&lt;/p&gt;

&lt;h1&gt;
  
  
  output variable
&lt;/h1&gt;

&lt;p&gt;y = cancer_df['target'] &lt;br&gt;
y.head(6)&lt;br&gt;
Split dataset for training&amp;nbsp;and&lt;/p&gt;

&lt;h1&gt;
  
  
  split dataset into train and test
&lt;/h1&gt;

&lt;p&gt;from sklearn.model_selection import train_test_split&lt;br&gt;
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state= 5)&lt;br&gt;
Feature scaling of&amp;nbsp;data&lt;br&gt;
from sklearn.preprocessing import StandardScaler&lt;br&gt;
sc = StandardScaler()&lt;br&gt;
X_train_sc = sc.fit_transform(X_train)&lt;br&gt;
X_test_sc = sc.transform(X_test)&lt;br&gt;
Machine Learning Model&amp;nbsp;Building&lt;br&gt;
1.Suppor vector Classifier&lt;br&gt;
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score  #for classification report&lt;/p&gt;

&lt;h1&gt;
  
  
  Svm model
&lt;/h1&gt;

&lt;p&gt;from sklearn.svm import SVC&lt;br&gt;
svc_classifier = SVC()&lt;br&gt;
svc_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_scv = svc_classifier.predict(X_test)&lt;br&gt;
accuarcy_svm=accuracy_score(y_test, y_pred_scv)&lt;br&gt;
print(accuarcy_svm)&lt;/p&gt;

&lt;h1&gt;
  
  
  Output 0.5789473684210527
&lt;/h1&gt;

&lt;p&gt;2.Logistic Regression&lt;/p&gt;

&lt;h1&gt;
  
  
  Logistic Regression
&lt;/h1&gt;

&lt;p&gt;from sklearn.linear_model import LogisticRegression&lt;br&gt;
lr_classifier = LogisticRegression(random_state = 51, penalty = 'l1')&lt;br&gt;
lr_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_lr = lr_classifier.predict(X_test)&lt;br&gt;
accuracy_score(y_test, y_pred_lr)&lt;br&gt;
accuarcy_lr=accuracy_score(y_test, y_pred_lr)&lt;br&gt;
print(accuarcy_lr)&lt;/p&gt;

&lt;h1&gt;
  
  
  Output 0.9736842105263158
&lt;/h1&gt;

&lt;p&gt;3.Decision Tree Classifier&lt;/p&gt;

&lt;h1&gt;
  
  
  Decision Tree Classifier
&lt;/h1&gt;

&lt;p&gt;from sklearn.tree import DecisionTreeClassifier&lt;br&gt;
dt_classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 51)&lt;br&gt;
dt_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_dt = dt_classifier.predict(X_test)&lt;br&gt;
accuarcy_dt=accuracy_score(y_test, y_pred_dt)&lt;br&gt;
print(accuarcy_dt)&lt;/p&gt;

&lt;h1&gt;
  
  
  Output 0.9473684210526315
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;XGboost classsifier&lt;/p&gt;
&lt;h1&gt;
  
  
  XGBoost Classifier
&lt;/h1&gt;

&lt;p&gt;from xgboost import XGBClassifier&lt;br&gt;
xgb_classifier = XGBClassifier()&lt;br&gt;
xgb_classifier.fit(X_train, y_train)&lt;br&gt;
y_pred_xgb = xgb_classifier.predict(X_test)&lt;br&gt;
y_pred_xgb=accuracy_score(y_test, y_pred_xgb)&lt;br&gt;
accuarcy_xgb=accuracy_score(y_test, y_pred_xgb)&lt;br&gt;
print(accuarcy_xgb)&lt;/p&gt;
&lt;h1&gt;
  
  
  Output 0.9823684210526315
&lt;/h1&gt;

&lt;p&gt;Similarly, we have to do for test data and implement them on we can see that their will be no overfitting and underfitting the test data. their should low bias and low variance.&lt;br&gt;
Accuracy on test data and the similar code for test data&amp;nbsp;.&lt;/p&gt;
&lt;h1&gt;
  
  
  accuracy of all the classifier test data
&lt;/h1&gt;

&lt;p&gt;Accuracy of Support vector Classifier - 0.5789456522520&lt;br&gt;
Accuracy of Decision tree Classifier -0.8473684210526315&lt;br&gt;
Accuracy of Logistic regression- 0.570456140350877&lt;br&gt;
Accuracy of XGBoost Classifier - 0.982456140350877&lt;br&gt;
As,we can conclude the test data is performing nearly good result in Xgboost classifier with low bias and variance.&lt;br&gt;
For further improving we should go for the tuning method such as randomised search and grid search on Xgboost because we want our accuracy to be more optimal and fix all contraints like precision&amp;nbsp;,recall&amp;nbsp;,beta value and support which are import to satisfy to overcome the Type I and Type II Error.&lt;br&gt;
Randomized search&lt;br&gt;
Applying randomized search on the model which works on sample of data and it works more faster than any search tuning method&lt;br&gt;
params={&lt;br&gt;
"learning_rate" : [0.05, 0.10, 0.15, 0.20, 0.25, 0.30 ] ,&lt;br&gt;
"max_depth" : [ 3, 4, 5, 6, 8, 10, 12, 15],&lt;br&gt;
"min_child_weight" : [ 1, 3, 5, 7 ],&lt;br&gt;
"gamma" : [ 0.0, 0.1, 0.2 , 0.3, 0.4 ],&lt;br&gt;
"colsample_bytree" : [ 0.3, 0.4, 0.5 , 0.7 ] &lt;br&gt;
}&lt;/p&gt;
&lt;h1&gt;
  
  
  Randomized Search
&lt;/h1&gt;

&lt;p&gt;from sklearn.model_selection import RandomizedSearchCV&lt;br&gt;
random_search = RandomizedSearchCV(xgb_classifier, param_distributions=params, scoring= 'roc_auc', n_jobs= -1, verbose= 3)&lt;br&gt;
random_search.fit(X_train, y_train)&lt;br&gt;
Finding the best and optimize parameter.&lt;br&gt;
random_search.best_params_&lt;/p&gt;
&lt;h1&gt;
  
  
  output
&lt;/h1&gt;

&lt;p&gt;{'min_child_weight': 1,&lt;br&gt;
'max_depth': 12,&lt;br&gt;
'learning_rate': 0.3,&lt;br&gt;
'gamma': 0.3,&lt;br&gt;
'colsample_bytree': 0.7}&lt;br&gt;
random_search.best_estimator_&lt;/p&gt;
&lt;h1&gt;
  
  
  output
&lt;/h1&gt;

&lt;p&gt;XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,&lt;br&gt;
   colsample_bynode=1, colsample_bytree=0.7, gamma=0.3,&lt;br&gt;
   learning_rate=0.3, max_delta_step=0, max_depth=12,&lt;br&gt;
   min_child_weight=1, missing=None, n_estimators=100, n_jobs=1,&lt;br&gt;
   nthread=None, objective='binary:logistic', random_state=0,&lt;br&gt;
   reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,&lt;br&gt;
   silent=None, subsample=1, verbosity=1)&lt;/p&gt;
&lt;h1&gt;
  
  
  training XGBoost classifier with best parameters
&lt;/h1&gt;

&lt;p&gt;xgb_classifier_pt = XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,&lt;br&gt;
colsample_bynode=1, colsample_bytree=0.4, gamma=0.2,&lt;br&gt;
learning_rate=0.1, max_delta_step=0, max_depth=15,&lt;br&gt;
min_child_weight=1, missing=None, n_estimators=100, n_jobs=1,&lt;br&gt;
nthread=None, objective='binary:logistic', random_state=0,&lt;br&gt;
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,&lt;br&gt;
silent=None, subsample=1, verbosity=1)&lt;br&gt;
xgb_classifier_pt.fit(X_train, y_train)&lt;br&gt;
y_pred_xgb_pt = xgb_classifier_pt.predict(X_test)&lt;br&gt;
Accuracy after model&lt;br&gt;
accuracy_score(y_test, y_pred_xgb_pt)&lt;/p&gt;
&lt;h1&gt;
  
  
  output  - 0.9824561403508771
&lt;/h1&gt;

&lt;p&gt;Grid search&lt;br&gt;
Applying grid search on the model which works on whole data.&lt;br&gt;
Training the model&lt;br&gt;
from sklearn.model_selection import GridSearchCV &lt;br&gt;
grid_search = GridSearchCV(xgb_classifier, param_grid=params, scoring= 'roc_auc', n_jobs= -1, verbose= 3)&lt;br&gt;
grid_search.fit(X_train, y_train)&lt;br&gt;
Now comes the implementing it&lt;br&gt;
xgb_classifier_pt_gs = XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,&lt;br&gt;
colsample_bynode=1, colsample_bytree=0.3, gamma=0.0,&lt;br&gt;
learning_rate=0.3, max_delta_step=0, max_depth=3,&lt;br&gt;
min_child_weight=1, missing=None, n_estimators=100, n_jobs=1,&lt;br&gt;
nthread=None, objective='binary:logistic', random_state=0,&lt;br&gt;
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,&lt;br&gt;
silent=None, subsample=1, verbosity=1)&lt;br&gt;
xgb_classifier_pt_gs.fit(X_train, y_train)&lt;br&gt;
y_pred_xgb_pt_gs = xgb_classifier_pt_gs.predict(X_test)&lt;br&gt;
accuracy_score(y_test, y_pred_xgb_pt_gs)&lt;/p&gt;
&lt;h1&gt;
  
  
  output 0.9824561403508771
&lt;/h1&gt;

&lt;p&gt;As,we are getting the nearly same accuracy after applying these tuning method so we will use grid search in this know comes the part of classification report and types of error.&lt;br&gt;
Confusion matrix&lt;br&gt;
It gives the value of true positive and false negative which will help to predict how much our model is optimized to predict it.&lt;br&gt;
from sklearn.metrics import confusion_matrix, classification_report&lt;br&gt;
cm = confusion_matrix(y_test, y_pred_xgb_pt)&lt;br&gt;
plt.title('Heatmap of Confusion Matrix', fontsize = 15)&lt;br&gt;
sns.heatmap(cm, annot = True)&lt;br&gt;
plt.show()&lt;br&gt;
The model is giving 0 type II error and it is best and for model is gving 2/112 near 0.017 error. it means we have very less chance for the wrong prediction around zero.&lt;br&gt;
Classification report of the&amp;nbsp;model&lt;br&gt;
print(classification_report(y_test, y_pred_xgb_pt))&lt;br&gt;
Output&lt;br&gt;
precision    recall  f1-score   support&lt;br&gt;
     0.0       1.00      0.96      0.98        48&lt;br&gt;
     1.0       0.97      1.00      0.99        66&lt;br&gt;
micro avg       0.98      0.98      0.98       114&lt;br&gt;
macro avg       0.99      0.98      0.98       114&lt;br&gt;
weighted avg       0.98      0.98      0.98       114&lt;br&gt;
Cross-validation of the ML&amp;nbsp;model&lt;/p&gt;
&lt;h1&gt;
  
  
  Cross validation
&lt;/h1&gt;

&lt;p&gt;from sklearn.model_selection import cross_val_score&lt;br&gt;
cross_validation = cross_val_score(estimator = xgb_classifier_pt, X = X_train_sc,y = y_train, cv = 10)&lt;br&gt;
print("Cross validation accuracy of XGBoost model = ", cross_validation)&lt;br&gt;
print("\nCross validation mean accuracy of XGBoost model = ", cross_validation.mean())&lt;br&gt;
Output&lt;br&gt;
Cross validation accuracy of XGBoost model =  [0.9787234  0.97826087 0.97826087 0.97826087 0.93333333 0.91111111&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;        1.         0.97777778 0.88888889]
Cross validation mean accuracy of XGBoost model =  0.9624617124062083
Saving model for deployment
pickle.dump(xgb_classifier_pt, open('breast_cancer_detector.pickle', 'wb'))
# load model
breast_cancer_detector_model = pickle.load(open('breast_cancer_detector.pickle', 'rb'))
# predict the output
y_pred = breast_cancer_detector_model.predict(X_test)
# confusion matrix
print('Confusion matrix of XGBoost model: \n',confusion_matrix(y_test, y_pred),'\n')
# show the accuracy
print('Accuracy of XGBoost model = ',accuracy_score(y_test, y_pred))
############################
#Output
Confusion matrix of XGBoost model: 
[[46  2]
[ 0 66]] 
Accuracy of XGBoost model =  0.9824561403508771
Now are model is dumb into pickle file.now its time for the flask for the model to deploy.
Now we have to switch towards sublime text editor for the deployment.the main aim is to used html,css with flask in it.
The code here depicts the loading of dumb model and then we are accessing the index.html file for the home page which we can discuss further.
then we have the predict function which will be implemented when we will enter the input 30 constraints as an input in the box and then array of size 30 goes to the data frame for the prediction and return will make the after.html file which tell about the output as an tumor malignant and benign according to the value input by user and new webpage open with this classification.
The code tells about the title of the webpage with background of image 144.jpg and then in heading 3 lines as in the center of the webpage with various different size&amp;nbsp;.Then&amp;nbsp;, we make a placeholder which will help us to store the input value and display placeholder name on webpage. Then,we will make the "Click here to predict "button for the prediction. and then header for the name. the code next to it depicts about the displaying the icons of the social media with the font size and the specific color. Each specific icon is hyperlinked to my social media handle and then end of the body.
Now comes the file which will come and depicts output of the inbuild functions.
The after.html file have background to the webapge as image background and then it will have the PREDICTION will be 0 or 1 according to the data entered and image.
Now our model is ready to run command first change directory to the folder where we have the run python app.py
Then&amp;nbsp;,it will be return on local system &lt;a href="http://127.0.0.1:8500/"&gt;http://127.0.0.1:8500/&lt;/a&gt; and it will be going to predict after the &lt;a href="http://127.0.0.1:8500/predict%C2%A0"&gt;http://127.0.0.1:8500/predict&amp;nbsp;&lt;/a&gt;.
We will deploy this on heroku through heroku CLI.
Register on heroku.
Then create new app icon and then write name of app and choose a region.
Download to the system Heroku CLI and then open cmd.
Execute these commands on cmd with folder directory.
cd my-project/
&amp;nbsp;git init
&amp;nbsp;heroku git:remote -a my-project
git add&amp;nbsp;.
git commit -am "make it better"
&amp;nbsp;git push heroku master&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then go to settings your webpage is created.&lt;br&gt;&lt;br&gt;
If you want to implement code from your hand then click the button and implement code end to end with explanation in brief.&lt;br&gt;&lt;br&gt;
If u like to read this article and have common interest in similar projects then we can grow our network and can work for more real time projects.&lt;br&gt;&lt;br&gt;
For more details connect with me on my Linkedin account!&lt;br&gt;&lt;br&gt;
THANKS!!!!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
