You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
"""Provides continuous real number predictions learned from the training data.
14
-
"""
15
-
def__init__(
16
-
self,
17
-
project_name:str,
18
-
relation_name:str,
19
-
y_column_name:str,
20
-
algorithm:str="sklearn.linear_model",
21
-
test_size:floatorint=0.1,
22
-
test_sampling:str="random"
23
-
)->None:
24
-
"""Create a regression model from a table or view filled with training data.
25
-
26
-
Args:
27
-
project_name (str): a human friendly identifier
28
-
relation_name (str): the table or view that stores the training data
29
-
y_column_name (str): the column in the training data that acts as the label
30
-
algorithm (str, optional): the algorithm used to implement the regression. Defaults to "sklearn.linear_model".
31
-
test_size (float or int, optional): If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the test split. If int, represents the absolute number of test samples. If None, the value is set to the complement of the train size. If train_size is also None, it will be set to 0.25.
32
-
test_sampling: (str, optional): How to sample to create the test data. Defaults to "random". Valid values are ["first", "last", "random"].
33
-
"""
34
-
35
-
plpy.warning("snapshot")
36
-
# Create a snapshot of the relation
37
-
snapshot=plpy.execute(f"INSERT INTO pgml.snapshots (relation, y, test_size, test_sampling, status) VALUES ('{relation_name}', '{y_column_name}',{test_size}, '{test_sampling}', 'new') RETURNING *",1)[0]
38
-
plpy.execute(f"""CREATE TABLE pgml.snapshot_{snapshot['id']} AS SELECT * FROM "{relation_name}";""")
39
-
plpy.execute(f"UPDATE pgml.snapshots SET status = 'created' WHERE id ={snapshot['id']}")
40
-
41
-
plpy.warning("project")
11
+
classProject:
12
+
def__init__(self,name):
42
13
# Find or create the project
43
-
project=plpy.execute(f"SELECT * FROM pgml.projects WHERE name = '{project_name}'",1)
44
-
plpy.warning(f"project{project}")
45
-
if (project.nrows==1):
46
-
plpy.warning("project found")
47
-
project=project[0]
14
+
result=plpy.execute(f"SELECT * FROM pgml.projects WHERE name = '{name}'",1)
15
+
if (result.nrows==1):
16
+
self.__dict__=dict(result[0])
48
17
else:
49
18
try:
50
-
project=plpy.execute(f"INSERT INTO pgml.projects (name) VALUES ('{project_name}') RETURNING *",1)
51
-
plpy.warning(f"project inserted{project}")
52
-
if (project.nrows()==1):
53
-
project=project[0]
54
-
19
+
self.__dict__=dict(plpy.execute(f"INSERT INTO pgml.projects (name) VALUES ('{name}') RETURNING *",1)[0])
55
20
exceptExceptionase:# handle race condition to insert
56
-
plpy.warning(f"project retry: #{e}")
57
-
project=plpy.execute(f"SELECT * FROM pgml.projects WHERE name = '{project_name}'",1)[0]
21
+
self.__dict__=dict(plpy.execute(f"SELECT * FROM pgml.projects WHERE name = '{name}'",1)[0])
"""Provides continuous real number predictions learned from the training data.
112
+
"""
113
+
def__init__(
114
+
self,
115
+
project_name:str,
116
+
relation_name:str,
117
+
y_column_name:str,
118
+
algorithms:str= ["linear","random_forest"],
119
+
test_size:floatorint=0.1,
120
+
test_sampling:str="random"
121
+
)->None:
122
+
"""Create a regression model from a table or view filled with training data.
123
+
124
+
Args:
125
+
project_name (str): a human friendly identifier
126
+
relation_name (str): the table or view that stores the training data
127
+
y_column_name (str): the column in the training data that acts as the label
128
+
algorithm (str, optional): the algorithm used to implement the regression. Defaults to "linear". Valid values are ["linear", "random_forest"].
129
+
test_size (float or int, optional): If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the test split. If int, represents the absolute number of test samples. If None, the value is set to the complement of the train size. If train_size is also None, it will be set to 0.25.
130
+
test_sampling: (str, optional): How to sample to create the test data. Defaults to "random". Valid values are ["first", "last", "random"].