FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
dl_tutorial/examples/class_score_predict_sklearn.py at master · mint-lab/dl_tutorial · GitHub
mint-lab
/
dl_tutorial
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
17
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
dl_tutorial
/
examples
/
class_score_predict_sklearn.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (35 loc) · 1.2 KB
Breadcrumbs
dl_tutorial
/
examples
/
class_score_predict_sklearn.py
Copy path
File metadata and controls
42 lines (35 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
from
sklearn
import
svm
midterm_range
=
np
.
array
([
0
,
125
])
final_range
=
np
.
array
([
0
,
100
])
# Load score data
class_kr
=
np
.
loadtxt
(
'data/class_score_kr.csv'
,
delimiter
=
','
)
class_en
=
np
.
loadtxt
(
'data/class_score_en.csv'
,
delimiter
=
','
)
data
=
np
.
vstack
((
class_kr
,
class_en
))
x
=
data
[:,
0
].
reshape
(
-
1
,
1
)
y
=
data
[:,
1
]
# Instantiate regression models
models
=
[
{
'name'
:
'svm.SVR(poly,1)'
,
'obj'
:
svm
.
SVR
(
kernel
=
'poly'
,
degree
=
1
,
coef0
=
1
),
'color'
:
'g'
},
{
'name'
:
'svm.SVR(poly,5)'
,
'obj'
:
svm
.
SVR
(
kernel
=
'poly'
,
degree
=
5
,
coef0
=
1
),
'color'
:
'b'
},
]
# Prepare for plotting
plt
.
figure
()
plt
.
plot
(
data
[:,
0
],
data
[:,
1
],
'r.'
,
label
=
'The given data'
)
idx_sort
=
np
.
argsort
(
data
[:,
0
])
for
model
in
models
:
# Train a model
model
[
'obj'
].
fit
(
x
,
y
)
# Visualize regression results (the estimated line)
y_pred
=
model
[
'obj'
].
predict
(
x
)
model
[
'mae'
]
=
np
.
mean
(
np
.
abs
(
y_pred
-
y
))
plt
.
plot
(
x
[
idx_sort
,
0
],
y_pred
[
idx_sort
],
label
=
f'
{
model
[
"name"
]
}
(MAE=
{
model
[
"mae"
]:.1f
}
)'
,
color
=
model
[
'color'
])
# Decorate the plot
plt
.
xlabel
(
'Midterm scores'
)
plt
.
ylabel
(
'Final scores'
)
plt
.
xlim
(
midterm_range
)
plt
.
ylim
(
final_range
)
plt
.
grid
()
plt
.
legend
()
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL