Unit5 - Logistic Regression
Unit5 - Logistic Regression
Logistic Regression
Steps of Development of ML in Python
1 1 85 66 29 0 26.6 0.351
3 1 89 66 23 94 28.1 0.167
In [8]:
print(dataset.columns)
print(dataset.shape)
print(dataset.info())
print(dataset.isnull().sum())
C:\Users\chinu\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py:763: Co
nvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Increase the number of iterations (max_iter) or scale the data as shown in:
https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
n_iter_i = _check_optimize_result(
LogisticRegression()
Out[12]:
Teting model
In [13]:
predictions = model.predict(X_test)
print(predictions)
[0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0
1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1
0 1 0 0 0 0]
Evaluation of model
In [25]:
from sklearn.metrics import confusion_matrix, accuracy_score , recall_score , precis
print(accuracy_score(Y_test,predictions))
print(recall_score(Y_test,predictions))
print(precision_score(Y_test,predictions))
print(confusion_matrix(Y_test,predictions))
0.7662337662337663
0.4807692307692308
0.7352941176470589
[[93 9]
[27 25]]
In [29]:
sns.distplot(predictions,hist=False, color = 'r', label = 'Predicted Values')
sns.distplot(Y_test, hist=False, color = 'b', label = 'Actual Values')
plt.legend(loc = "upper left")
plt.show()
C:\Users\chinu\anaconda3\lib\site-packages\seaborn\distributions.py:2619: FutureWarn
ing: `distplot` is a deprecated function and will be removed in a future version. Pl
ease adapt your code to use either `displot` (a figure-level function with similar f
lexibility) or `kdeplot` (an axes-level function for kernel density plots).
warnings.warn(msg, FutureWarning)
C:\Users\chinu\anaconda3\lib\site-packages\seaborn\distributions.py:2619: FutureWarn
ing: `distplot` is a deprecated function and will be removed in a future version. Pl
ease adapt your code to use either `displot` (a figure-level function with similar f
lexibility) or `kdeplot` (an axes-level function for kernel density plots).
warnings.warn(msg, FutureWarning)
Predictions
In [51]:
Pregnancies = 8
Glucose = 183
BloodPressure = 64
SkinThickness = 0
Insulin = 0
BMI =23.3
DiabetesPedigreeFunction=0.672
Age = 32
new_data = [[Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,
DiabetesPedigreeFunction,Age]]
prediction = model.predict(new_data)
print(prediction)
[1]
In [ ]: