forked from dask-contrib/dask-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ML model improvement : Adding "SHOW MODELS and DESCRIBE MODEL"
Author: rajagurunath <gurunathrajagopal@gmail.com> Date: Mon May 24 02:37:40 2021 +0530
- Loading branch information
1 parent
3e106e3
commit 4a9ee68
Showing
11 changed files
with
312 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import dask.dataframe as dd | ||
import pandas as pd | ||
|
||
from dask_sql.datacontainer import ColumnContainer, DataContainer | ||
from dask_sql.physical.rel.base import BaseRelPlugin | ||
from dask_sql.utils import get_model_from_compound_identifier | ||
|
||
|
||
class ShowModelParamsPlugin(BaseRelPlugin): | ||
""" | ||
Show all Params used to train a given model and training columns. | ||
The SQL is: | ||
DESCRIBE MODEL <model_name> | ||
The result is also a table, although it is created on the fly. | ||
""" | ||
|
||
class_name = "com.dask.sql.parser.SqlShowModelParams" | ||
|
||
def convert( | ||
self, sql: "org.apache.calcite.sql.SqlNode", context: "dask_sql.Context" | ||
) -> DataContainer: | ||
components = list(map(str, sql.getTable().names)) | ||
model, training_columns = get_model_from_compound_identifier( | ||
context, components | ||
) | ||
model_params = model.get_params() | ||
model_params["training_columns"] = training_columns.tolist() | ||
df = pd.DataFrame.from_dict(model_params, orient="index", columns=["Params"]) | ||
cc = ColumnContainer(df.columns) | ||
dc = DataContainer(dd.from_pandas(df, npartitions=1), cc) | ||
return dc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import dask.dataframe as dd | ||
import pandas as pd | ||
|
||
from dask_sql.datacontainer import ColumnContainer, DataContainer | ||
from dask_sql.physical.rel.base import BaseRelPlugin | ||
|
||
|
||
class ShowModelsPlugin(BaseRelPlugin): | ||
""" | ||
Show all MODELS currently registered/trained. | ||
The SQL is: | ||
SHOW MODELS | ||
The result is also a table, although it is created on the fly. | ||
""" | ||
|
||
class_name = "com.dask.sql.parser.SqlShowModels" | ||
|
||
def convert( | ||
self, sql: "org.apache.calcite.sql.SqlNode", context: "dask_sql.Context" | ||
) -> DataContainer: | ||
|
||
df = pd.DataFrame({"Models": list(context.models.keys())}) | ||
|
||
cc = ColumnContainer(df.columns) | ||
dc = DataContainer(dd.from_pandas(df, npartitions=1), cc) | ||
return dc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
planner/src/main/java/com/dask/sql/parser/SqlShowModelParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.dask.sql.parser; | ||
|
||
import org.apache.calcite.sql.SqlDescribeTable; | ||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
|
||
public class SqlShowModelParams extends SqlDescribeTable { | ||
SqlIdentifier modelName; | ||
|
||
public SqlShowModelParams(SqlParserPos pos, SqlIdentifier modelName) { | ||
super(pos, modelName,null); | ||
this.modelName = modelName; | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
writer.keyword("DESCRIBE"); | ||
writer.keyword("MODEL"); | ||
this.modelName.unparse(writer, leftPrec, rightPrec); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
planner/src/main/java/com/dask/sql/parser/SqlShowModels.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.dask.sql.parser; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.SqlOperator; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.SqlNode; | ||
|
||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
|
||
public class SqlShowModels extends SqlCall { | ||
public SqlIdentifier catalog; | ||
public SqlNode like; | ||
|
||
|
||
public SqlShowModels(SqlParserPos pos) { | ||
super(pos); | ||
} | ||
public SqlOperator getOperator() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public List<SqlNode> getOperandList() { | ||
ArrayList<SqlNode> operandList = new ArrayList<SqlNode>(); | ||
return operandList; | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer,int leftPrec, int rightPrec) { | ||
writer.keyword("SHOW"); | ||
writer.keyword("MODELS"); | ||
|
||
} | ||
} |
Oops, something went wrong.