Machine Learning Introduction

Supervised Machine Learning

Unsupervised Machine Learning

Miscellaneous Topics in ML

Data Pre-Processing

**Logistic Regression** is a Machine Learning classification algorithm that is used to
predict the probability of a categorical dependent variable. In logistic regression,
the dependent variable is a binary variable that contains data coded as 1 (yes, success, etc.)
or 0 (no, failure, etc.). In other words, the logistic regression model predicts P(Y=1) as a
function of X.

Logistic Regression is one of the most simple and commonly used Machine Learning algorithms for two-class classification. It is easy to implement and can be used as the baseline for any binary classification problem. Its basic fundamental concepts are also constructive in deep learning. Logistic regression describes and estimates the relationship between one dependent binary variable and independent variables.

Logistic regression is a statistical method for predicting binary classes. The outcome or target variable is dichotomous in nature. Dichotomous means there are only two possible classes. For example, it can be used for cancer detection problems. It computes the probability of an event occurrence.

The sigmoid function, also called logistic function gives an ‘S’ shaped curve that can take any real-valued number and map it into a value between 0 and 1. If the curve goes to positive infinity, y predicted will become 1, and if the curve goes to negative infinity, y predicted will become 0. If the output of the sigmoid function is more than 0.5, we can classify the outcome as 1 or YES, and if it is less than 0.5, we can classify it as 0 or NO. For example: If the output is 0.75, we can say in terms of probability as: There is a 75 percent chance that patient will suffer from cancer.

The data was collected and made available by “National Institute of Diabetes and Digestive and Kidney Diseases” as part of the Pima Indians Diabetes Database. Several constraints were placed on the selection of these instances from a larger database. In particular, all patients here belong to the Pima Indian heritage (subgroup of Native Americans), and are females of ages 21 and above.

You can get the dataset by click the following link:

**#import libraries**
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
**#Create a dataframe**
data=pd.read_csv("E:\diabetes.csv")
data.head()

data.shape

(768, 9)

data.info()

data.describe()

**#Choose X and y**
X=data.iloc[:,:-1].values
y=data.iloc[:,8].values
#Split dataset into training and testing data
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.25,random_state=0)

**print(X_test)**

**print(y_test)**

**#Create LogisticRegression model**
from sklearn.linear_model import LogisticRegression
model=LogisticRegression()
#Trained the model
model.fit(X_train,y_train)

**#Predict the model**
y_pred=model.predict(X_test)
y_pred

**#Model evalution using confuson matrix**
from sklearn import metrics
cnf_matrix=metrics.confusion_matrix(y_test,y_pred)
cnf_matrix

**#Confusion matrix evalution metrics**
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
print("Precision:",metrics.precision_score(y_test, y_pred))
print("Recall:",metrics.recall_score(y_test, y_pred))

**#Visualization**
class_names=[0,1] # name of classes
fig, ax = plt.subplots()
tick_marks = np.arange(len(class_names))
plt.xticks(tick_marks, class_names)
plt.yticks(tick_marks, class_names)

**# create heatmap**
sns.heatmap(pd.DataFrame(cnf_matrix), annot=True, cmap="YlGnBu" ,fmt='g')
ax.xaxis.set_label_position("top")
plt.tight_layout()
plt.title('Confusion matrix', y=1.1)
plt.ylabel('Actual label')
plt.xlabel('Predicted label')
plt.show()

Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc