Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp3217-lab2
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chauhan Chauhan
comp3217-lab2
Commits
6446b759
Commit
6446b759
authored
2 years ago
by
Chauhan Chauhan
Browse files
Options
Downloads
Patches
Plain Diff
Delete 3217-classification-lr-example2.py
parent
136a8399
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
3217-classification-lr-example2.py
+0
-44
0 additions, 44 deletions
3217-classification-lr-example2.py
with
0 additions
and
44 deletions
3217-classification-lr-example2.py
deleted
100644 → 0
+
0
−
44
View file @
136a8399
from
sklearn
import
datasets
,
neighbors
,
linear_model
from
sklearn.metrics
import
confusion_matrix
,
ConfusionMatrixDisplay
,
f1_score
import
matplotlib.pyplot
as
plt
X_digits
,
y_digits
=
datasets
.
load_digits
(
return_X_y
=
True
)
X_digits
=
X_digits
/
X_digits
.
max
()
n_samples
=
len
(
X_digits
)
ratio
=
0.9
print
(
n_samples
)
#train data
X_train
=
X_digits
[:
int
(
ratio
*
n_samples
)]
y_train
=
y_digits
[:
int
(
ratio
*
n_samples
)]
print
(
X_train
.
shape
)
#test data
X_test
=
X_digits
[
int
(
ratio
*
n_samples
)
:]
y_test
=
y_digits
[
int
(
ratio
*
n_samples
)
:]
print
(
X_test
.
shape
)
logistic
=
linear_model
.
LogisticRegression
(
max_iter
=
1000
)
print
(
"
LogisticRegression score: %f
"
%
logistic
.
fit
(
X_train
,
y_train
).
score
(
X_test
,
y_test
))
#Get results on actual test labels and predicted labels
predictions
=
logistic
.
predict
(
X_test
)
#print (predictions)
#print (y_test)
#get f1 score
print
(
f1_score
(
y_test
,
predictions
,
average
=
'
macro
'
))
#get confusion matrix
cm
=
confusion_matrix
(
y_test
,
predictions
,
labels
=
logistic
.
classes_
)
disp
=
ConfusionMatrixDisplay
(
confusion_matrix
=
cm
,
display_labels
=
logistic
.
classes_
)
disp
.
plot
()
plt
.
show
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment