Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
49ceea9e
Commit
49ceea9e
authored
Jan 04, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update models
parent
2dc23bc2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
data_preparing.py
alphamind/model/data_preparing.py
+9
-4
linearmodel.py
alphamind/model/linearmodel.py
+4
-4
treemodel.py
alphamind/model/treemodel.py
+4
-0
No files found.
alphamind/model/data_preparing.py
View file @
49ceea9e
...
...
@@ -119,8 +119,10 @@ def batch_processing(x_values,
post_process
):
train_x_buckets
=
{}
train_y_buckets
=
{}
train_risk_buckets
=
{}
predict_x_buckets
=
{}
predict_y_buckets
=
{}
predict_risk_buckets
=
{}
for
i
,
start
in
enumerate
(
groups
[:
-
batch
]):
end
=
groups
[
i
+
batch
]
...
...
@@ -146,6 +148,8 @@ def batch_processing(x_values,
risk_factors
=
this_risk_exp
,
post_process
=
post_process
)
train_risk_buckets
[
end
]
=
this_risk_exp
left_index
=
bisect
.
bisect_right
(
group_label
,
start
)
right_index
=
bisect
.
bisect_right
(
group_label
,
end
)
...
...
@@ -165,6 +169,7 @@ def batch_processing(x_values,
inner_left_index
=
bisect
.
bisect_left
(
sub_dates
,
end
)
inner_right_index
=
bisect
.
bisect_right
(
sub_dates
,
end
)
predict_x_buckets
[
end
]
=
ne_x
[
inner_left_index
:
inner_right_index
]
predict_risk_buckets
[
end
]
=
this_risk_exp
[
inner_left_index
:
inner_right_index
]
this_raw_y
=
y_values
[
left_index
:
right_index
]
if
len
(
this_raw_y
)
>
0
:
...
...
@@ -174,7 +179,7 @@ def batch_processing(x_values,
post_process
=
post_process
)
predict_y_buckets
[
end
]
=
ne_y
[
inner_left_index
:
inner_right_index
]
return
train_x_buckets
,
train_y_buckets
,
predict_x_buckets
,
predict_y
_buckets
return
train_x_buckets
,
train_y_buckets
,
train_risk_buckets
,
predict_x_buckets
,
predict_y_buckets
,
predict_risk
_buckets
def
fetch_data_package
(
engine
:
SqlEngine
,
...
...
@@ -216,7 +221,7 @@ def fetch_data_package(engine: SqlEngine,
alpha_logger
.
info
(
"Loading data is finished"
)
train_x_buckets
,
train_y_buckets
,
predict_x_buckets
,
predict_y
_buckets
=
batch_processing
(
train_x_buckets
,
train_y_buckets
,
train_risk_buckets
,
predict_x_buckets
,
predict_y_buckets
,
predict_risk
_buckets
=
batch_processing
(
x_values
,
y_values
,
dates
,
...
...
@@ -231,8 +236,8 @@ def fetch_data_package(engine: SqlEngine,
ret
=
dict
()
ret
[
'x_names'
]
=
transformer
.
names
ret
[
'settlement'
]
=
return_df
ret
[
'train'
]
=
{
'x'
:
train_x_buckets
,
'y'
:
train_y_buckets
}
ret
[
'predict'
]
=
{
'x'
:
predict_x_buckets
,
'y'
:
predict_y_buckets
}
ret
[
'train'
]
=
{
'x'
:
train_x_buckets
,
'y'
:
train_y_buckets
,
'risk'
:
train_risk_buckets
}
ret
[
'predict'
]
=
{
'x'
:
predict_x_buckets
,
'y'
:
predict_y_buckets
,
'risk'
:
predict_risk_buckets
}
return
ret
...
...
alphamind/model/linearmodel.py
View file @
49ceea9e
...
...
@@ -72,8 +72,8 @@ class LinearRegression(ModelBase):
model_desc
[
'weight'
]
=
self
.
impl
.
coef_
.
tolist
()
return
model_desc
def
score
(
self
)
->
float
:
return
self
.
impl
.
score
()
def
score
(
self
,
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
float
:
return
self
.
impl
.
score
(
x
,
y
)
@
classmethod
def
load
(
cls
,
model_desc
:
dict
):
...
...
@@ -117,8 +117,8 @@ class LassoRegression(ModelBase):
model_desc
[
'weight'
]
=
self
.
impl
.
coef_
.
tolist
()
return
model_desc
def
score
(
self
)
->
float
:
return
self
.
impl
.
score
()
def
score
(
self
,
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
float
:
return
self
.
impl
.
score
(
x
,
y
)
@
classmethod
def
load
(
cls
,
model_desc
:
dict
):
...
...
alphamind/model/treemodel.py
View file @
49ceea9e
...
...
@@ -29,12 +29,16 @@ class RandomForestRegressor(ModelBase):
def
predict
(
self
,
x
:
np
.
ndarray
)
->
np
.
ndarray
:
return
self
.
impl
.
predict
(
x
)
def
score
(
self
,
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
float
:
return
self
.
impl
.
score
(
x
,
y
)
def
save
(
self
)
->
dict
:
model_desc
=
super
()
.
save
()
model_desc
[
'internal_model'
]
=
self
.
impl
.
__class__
.
__module__
+
"."
+
self
.
impl
.
__class__
.
__name__
model_desc
[
'desc'
]
=
encode
(
self
.
impl
)
model_desc
[
'sklearn_version'
]
=
sklearn_version
model_desc
[
'trained_time'
]
=
self
.
trained_time
@
classmethod
def
load
(
cls
,
model_desc
:
dict
):
obj_layout
=
cls
()
...
...
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