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
65cc8040
Commit
65cc8040
authored
2 years ago
by
Chauhan Chauhan
Browse files
Options
Downloads
Patches
Plain Diff
Delete 3217-classification-lr-example4.py
parent
116f766e
No related branches found
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-example4.py
+0
-59
0 additions, 59 deletions
3217-classification-lr-example4.py
with
0 additions
and
59 deletions
3217-classification-lr-example4.py
deleted
100644 → 0
+
0
−
59
View file @
116f766e
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
sklearn
import
datasets
,
linear_model
from
sklearn.metrics
import
mean_squared_error
,
r2_score
# Load the diabetes dataset
diabetes_X
,
diabetes_y
=
datasets
.
load_diabetes
(
return_X_y
=
True
)
print
(
diabetes_X
.
shape
)
# Use only one feature
feature_to_use
=
2
diabetes_X
=
diabetes_X
[:,
np
.
newaxis
,
feature_to_use
]
print
(
diabetes_X
.
shape
)
test_samples
=
20
# Split the data into training/testing sets
diabetes_X_train
=
diabetes_X
[:
-
test_samples
]
diabetes_X_test
=
diabetes_X
[
-
test_samples
:]
# Split the targets into training/testing sets
diabetes_y_train
=
diabetes_y
[:
-
test_samples
]
diabetes_y_test
=
diabetes_y
[
-
test_samples
:]
# Create linear regression object
regr
=
linear_model
.
LinearRegression
()
# Train the model using the training sets
regr
.
fit
(
diabetes_X_train
,
diabetes_y_train
)
# Make prediction using the testing set
diabetes_y_pred
=
regr
.
predict
(
diabetes_X_test
)
print
(
diabetes_y_train
.
shape
)
print
(
diabetes_y_test
.
shape
)
# The coefficients
print
(
"
Coefficients:
\n
"
,
regr
.
coef_
)
# The mean squared error
print
(
"
Mean squared error: %.2f
"
%
mean_squared_error
(
diabetes_y_test
,
diabetes_y_pred
))
# The coefficient of determination: 1 is perfect prediction
print
(
"
Coefficient of determination: %.2f
"
%
r2_score
(
diabetes_y_test
,
diabetes_y_pred
))
# Plot outputs
plt
.
scatter
(
diabetes_X_test
,
diabetes_y_test
,
color
=
"
black
"
)
#grond truth actual test labels
plt
.
scatter
(
diabetes_X_test
,
diabetes_y_pred
,
color
=
"
red
"
)
#predicted test labels
plt
.
plot
(
diabetes_X_test
,
diabetes_y_pred
,
color
=
"
blue
"
,
linewidth
=
3
)
#predicted test labels
plt
.
xticks
(())
plt
.
yticks
(())
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