Professional Documents
Culture Documents
Import As From Import From Import From Import From Import From Import From Import From Import From Import From Import From Import Import As
Import As From Import From Import From Import From Import From Import From Import From Import From Import From Import From Import Import As
data.head()
(768, 9)
pregnant int64
glucose int64
bp int64
skin int64
insulin int64
bmi int64
pedigree int64
age int64
label int64
dtype: object
target_variable = data.label
predictor_variables = data[['pregnant', 'insulin', 'bmi',
'age','glucose','bp','pedigree']]
X = predictor_variables # Features
y =target_variable # Target variable
0 1
1 0
2 1
3 0
4 1
Name: label, dtype: int64
C:\Users\samsung\anaconda3\Lib\site-packages\sklearn\linear_model\
_logistic.py:458: ConvergenceWarning: lbfgs failed to converge
(status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
https://scikit-learn.org/stable/modules/linear_model.html#logistic-
regression
n_iter_i = _check_optimize_result(
LogisticRegression()
576
576
762 0
127 0
564 0
375 1
663 1
..
763 0
192 1
629 0
559 0
684 0
Name: label, Length: 576, dtype: int64
192
192
661 1
122 0
113 0
14 1
529 0
..
366 1
301 1
382 0
140 0
463 0
Name: label, Length: 192, dtype: int64
#make a prediction
y_pred=logreg.predict(X_test)
array([1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1,
0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
1,
1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1,
1,
1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
1,
0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0,
0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0,
1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0,
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0], dtype=int64)
while True:
Pregnancy = raw_input('Enter Num of Pregnancy (or "quit" to quit):
')
if Pregnancy=='quit': break
Insulin = raw_input('Enter insulin value')
Bmi = raw_input('Enter BMI ')
Age = raw_input('Enter Age ')
Glucose = raw_input('Enter Glucose ')
Bp = raw_input('Enter BP value')
Pedigree = raw_input('Enter Pedigree value')
Sdata=logreg.predict([[float(Pregnancy),float(Insulin),float(Bmi),floa
t(Age),float(Glucose),float(Bp),float(Pedigree)]])
print ("The Predicted Diabetes Value is : ",Sdata)
----------------------------------------------------------------------
-----
NameError Traceback (most recent call
last)
Cell In[24], line 2
1 while True:
----> 2 Pregnancy = raw_input('Enter Num of Pregnancy (or "quit"
to quit): ')
3 if Pregnancy=='quit': break
4 Insulin = raw_input('Enter insulin value')
#confusion matrix
confusion_matrix = pd.crosstab(y_test, y_pred, rownames=['Actual
Values'], colnames=['Predicted Values'])
sns.heatmap(confusion_matrix, annot=True)
#accuracy score
accuracy = accuracy_score(y_test, y_pred)
print('Accuracy: %f' % accuracy)
Accuracy: 0.791667
Precision: 0.729167
Recall: 0.564516
F1 score: 0.636364