Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2021-210
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-210
2021-210
Commits
1b52251e
Commit
1b52251e
authored
Jul 05, 2021
by
Shalitha Deshan Jayasekara
🏘
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT18523256_GunarathnaK.A.G.I.P.T' into 'master'
Adding Comments and dog breeds See merge request
!14
parents
0c71a422
1e2cbf4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
diet_plan/logistic_regression_weight.py
diet_plan/logistic_regression_weight.py
+12
-5
No files found.
diet_plan/logistic_regression_weight.py
View file @
1b52251e
#import pandas
#import pandas
import
pandas
as
pd
import
pandas
as
pd
#creating columns for dataset preview
col_names
=
[
'breed'
,
'age'
,
'weight'
,
'label'
]
col_names
=
[
'breed'
,
'age'
,
'weight'
,
'label'
]
# load dataset
dog_breeds
=
[
"german_sheppard"
,
"labrador"
,
"pomeranian"
,
"husky"
,
"golden_retriever"
,
"poodle"
,
"bulldog"
,
"shiba"
,
"rottweiler"
,
"boxer"
,
"Dobermen"
]
# reading data set
pima
=
pd
.
read_csv
(
"weight_data.csv"
,
header
=
None
,
names
=
col_names
)
pima
=
pd
.
read_csv
(
"weight_data.csv"
,
header
=
None
,
names
=
col_names
)
print
(
"==================="
)
print
(
"==================="
)
print
(
"Dataset head"
)
print
(
"Dataset head"
)
print
(
"==================="
)
print
(
"==================="
)
#previewing the head of data set
print
(
pima
.
head
())
print
(
pima
.
head
())
#split dataset in to features and target variable
#split dataset in features and target variable
feature_cols
=
[
'breed'
,
'age'
,
'weight'
]
feature_cols
=
[
'breed'
,
'age'
,
'weight'
]
X
=
pima
[
feature_cols
]
# Features
X
=
pima
[
feature_cols
]
# Features
y
=
pima
.
label
# Target variable
y
=
pima
.
label
# Target variable
#Use sklearn to train dataset
from
sklearn.model_selection
import
train_test_split
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
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.25
,
random_state
=
0
)
# import the class
# import the class
#use logistic Regression
from
sklearn.linear_model
import
LogisticRegression
from
sklearn.linear_model
import
LogisticRegression
# instantiate the model (using the default parameters)
# instantiate the model (using the default parameters)
...
@@ -26,7 +32,6 @@ logreg = LogisticRegression()
...
@@ -26,7 +32,6 @@ logreg = LogisticRegression()
# fit the model with data
# fit the model with data
logreg
.
fit
(
X_train
,
y_train
)
logreg
.
fit
(
X_train
,
y_train
)
#
y_pred
=
logreg
.
predict
(
X_test
)
y_pred
=
logreg
.
predict
(
X_test
)
# import the metrics class
# import the metrics class
...
@@ -35,16 +40,18 @@ cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
...
@@ -35,16 +40,18 @@ cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
print
(
"==================="
)
print
(
"==================="
)
print
(
"Confusion matrix"
)
print
(
"Confusion matrix"
)
print
(
"==================="
)
print
(
"==================="
)
#printing a confusion matrix
print
(
cnf_matrix
)
print
(
cnf_matrix
)
print
(
"==================="
)
print
(
"==================="
)
print
(
"Accuracy"
)
print
(
"Accuracy"
)
print
(
"==================="
)
print
(
"==================="
)
#printing the accuracy of model
print
(
"Accuracy:"
,
metrics
.
accuracy_score
(
y_test
,
y_pred
))
print
(
"Accuracy:"
,
metrics
.
accuracy_score
(
y_test
,
y_pred
))
# print("Precision:",metrics.precision_score(y_test, y_pred))
# print("Precision:",metrics.precision_score(y_test, y_pred))
# print("Recall:",metrics.recall_score(y_test, y_pred))
# print("Recall:",metrics.recall_score(y_test, y_pred))
# Prediction test
# Prediction test
y_prediction_test
=
logreg
.
predict
([[
12
,
3
,
48
]])
y_prediction_test
=
logreg
.
predict
([[
5
,
4
,
22
]])
y_labels
=
[
"Overweight"
,
"Normal"
,
"Underweight"
]
y_labels
=
[
"Overweight"
,
"Normal"
,
"Underweight"
]
print
(
y_labels
[
y_prediction_test
[
0
]])
print
(
y_labels
[
y_prediction_test
[
0
]])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment