├── .gitignore
├── Example_Notebooks
├── sparkora.html
└── sparkora.ipynb
├── LICENSE
├── README.md
├── Sparkora
├── __init__.py
├── main.py
├── test_data.csv
└── testsparkora.py
├── assets
└── project_cover.gif
├── requirements.txt
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
131 | # added
132 | .idea/
133 |
--------------------------------------------------------------------------------
/Example_Notebooks/sparkora.ipynb:
--------------------------------------------------------------------------------
1 | {"cells":[{"cell_type":"markdown","source":["## Getting imports which are required"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"38c54c98-7f33-4a79-9a1c-69da4fa614a8"}}},{"cell_type":"code","source":["import pyspark.sql.functions as F\nimport pyspark.sql.types as T\nimport pandas as pd"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"4fddbe8e-231a-4ca8-a331-dc5a6e35006f"}},"outputs":[],"execution_count":0},{"cell_type":"markdown","source":["## Sparkora initialization"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"afabae15-20c5-4f6b-ab95-86b360d64913"}}},{"cell_type":"code","source":["from Sparkora import Sparkora"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5bb9ef2b-c022-4b7b-b6ec-68426f94927e"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"Welcome to\n ____ __\n / __/__ ___ _____/ /__\n _\\ \\/ _ \\/ _ `/ __/ '_/\n /__ / .__/\\_,_/_/ /_/\\_\\ version 3.2.0\n /_/\n\nUsing Python version 3.8.10 (default, Sep 28 2021 16:10:42)\nSpark context Web UI available at http://10.172.203.167:48830\nSpark context available as 'sc' (master = local[8], app id = local-1636888245786).\nSparkSession available as 'spark'.\n","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"ansi","arguments":{}}},"output_type":"display_data","data":{"text/plain":["Welcome to\n ____ __\n / __/__ ___ _____/ /__\n _\\ \\/ _ \\/ _ `/ __/ '_/\n /__ / .__/\\_,_/_/ /_/\\_\\ version 3.2.0\n /_/\n\nUsing Python version 3.8.10 (default, Sep 28 2021 16:10:42)\nSpark context Web UI available at http://10.172.203.167:48830\nSpark context available as 'sc' (master = local[8], app id = local-1636888245786).\nSparkSession available as 'spark'.\n"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["## Creating the spark sample dataframe"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"934976d6-d755-43d1-883c-2fefe918ee20"}}},{"cell_type":"code","source":["df = pd.read_csv(\"https://raw.githubusercontent.com/Spratiher9/Sparkora/0.0.1/Sparkora/test_data.csv?token=AQWZISDC747WWFPLVRUCLXDBSDZIS\")\ndf = spark.createDataFrame(df)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"b700afd7-1346-4175-b238-a2a127612866"}},"outputs":[],"execution_count":0},{"cell_type":"code","source":["df.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"79c0b732-480d-44fb-8de1-0be497b0559e"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["
A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["# Demos from README"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"f3b23fbc-27ec-4fc8-a0b6-043affb55d9a"}}},{"cell_type":"markdown","source":["## Configuring `Sparkora` with the sample data"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"3d2fe9e3-b56c-4387-bf82-edf2749d5337"}}},{"cell_type":"code","source":["sparkora = Sparkora()\nsparkora.configure(output = 'A', data = df)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"0f7ff72a-89e5-40df-b781-252d41f4d0a5"}},"outputs":[],"execution_count":0},{"cell_type":"code","source":["display(sparkora.data)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"accec793-5388-4a17-81c8-bc5dd0202bfb"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["## Cleaning"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"7572e2bc-11e2-4212-9724-c542471c17e8"}}},{"cell_type":"code","source":["d = [\n (1, 2, 100),\n (2, None, 200),\n (1, 6, None)\n]\ndf = spark.createDataFrame(d, \"_c0 int, _c1 int, _c2 int\")"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"dcfe8879-a60e-40d6-bca9-81c17e12afcf"}},"outputs":[],"execution_count":0},{"cell_type":"code","source":["sparkora = Sparkora(output = '_c0', data = df)\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d1ded092-8d80-4e86-bff5-91ab78bb916d"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2,100],[2,null,200],[1,6,null]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"_c0","type":"\"integer\"","metadata":"{}"},{"name":"_c1","type":"\"integer\"","metadata":"{}"},{"name":"_c2","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["_c0 | _c1 | _c2 |
---|
1 | 2 | 100 |
2 | null | 200 |
1 | 6 | null |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["### Imputation"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5b1e3134-aed9-43d5-9b55-8d85a4ecf22b"}}},{"cell_type":"code","source":["sparkora.impute_missing_values() # Imputation strategy can be passed here: mean, median, mode\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"7ac5793a-bc21-4bee-acac-dc25d6362f09"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2,100],[2,4,200],[1,6,150]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"_c0","type":"\"integer\"","metadata":"{}"},{"name":"_c1","type":"\"integer\"","metadata":"{}"},{"name":"_c2","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":[""]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["### Scaling the dataset"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"4a4bec8f-0718-4f58-8198-feac5ea2f28b"}}},{"cell_type":"code","source":["sparkora.scale_input_values()\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d59fc887-ad54-4c96-85ef-6ffcab52a1f6"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,0.0,0.0],[2,0.5,1.0],[1,1.0,0.5]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"_c0","type":"\"integer\"","metadata":"{}"},{"name":"_c1","type":"\"double\"","metadata":"{}"},{"name":"_c2","type":"\"double\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["_c0 | _c1 | _c2 |
---|
1 | 0.0 | 0.0 |
2 | 0.5 | 1.0 |
1 | 1.0 | 0.5 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["## Feature Selection & Extraction"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"756a85bb-c5ea-4243-88f2-ddae355bbbef"}}},{"cell_type":"code","source":["df = pd.read_csv(\"https://raw.githubusercontent.com/Spratiher9/Sparkora/0.0.1/Sparkora/test_data.csv?token=AQWZISDC747WWFPLVRUCLXDBSDZIS\")\ndf = spark.createDataFrame(df)\ndf.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"f45f1c5f-faa8-44dc-833a-aa3c33662fb4"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora = Sparkora()\nsparkora.configure(output = 'A', data = df)\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"db6dd860-cfae-4558-b086-84b9cf4b6abc"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["### Removing feature"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"681d417d-def9-4f0b-a4d2-b41141018b78"}}},{"cell_type":"code","source":["sparkora.remove_feature('useless_feature')\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5c808ad9-b185-4b3c-9b1a-9b11e237c751"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left"],[4,null,1,"right"],[7,8.0,2,"left"]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D |
---|
1 | 2.0 | 0 | left |
4 | null | 1 | right |
7 | 8.0 | 2 | left |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["### Extracting an ordinal feature through one-hot encoding"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"28e1eaf3-68b9-4012-b925-6b6f1ed943a2"}}},{"cell_type":"code","source":["sparkora.extract_ordinal_feature('D')\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"617d022a-946f-4c3d-a58a-7dd54bada07c"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,1,0],[4,null,1,0,1],[7,8.0,2,1,0]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"integer\"","metadata":"{}"},{"name":"D=right","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D=left | D=right |
---|
1 | 2.0 | 0 | 1 | 0 |
4 | null | 1 | 0 | 1 |
7 | 8.0 | 2 | 1 | 0 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["### Feature creation from existing feature(s)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"9b6bb34d-b541-4d54-8093-d2892a2518bc"}}},{"cell_type":"markdown","source":["#### single feature input"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"0c1eb3d8-37f8-42cc-b1f3-2bbe4620fd39"}}},{"cell_type":"code","source":["f_udf = F.udf(lambda x: x * 2, T.IntegerType())\nsparkora.extract_feature('C', 'twoC', f_udf)\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"31c28c1e-f3dd-4e3a-97cc-05f4713a06e2"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,1,0,0],[4,null,1,0,1,2],[7,8.0,2,1,0,4]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"integer\"","metadata":"{}"},{"name":"D=right","type":"\"integer\"","metadata":"{}"},{"name":"twoC","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D=left | D=right | twoC |
---|
1 | 2.0 | 0 | 1 | 0 | 0 |
4 | null | 1 | 0 | 1 | 2 |
7 | 8.0 | 2 | 1 | 0 | 4 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["#### multi feature input"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d59ec4f7-da2c-4d9c-99d1-ff9e7b88ae56"}}},{"cell_type":"code","source":["f_udf = F.udf(lambda x,y: x * y, T.IntegerType())\nsparkora.extract_feature(['C','A'], 'newC', f_udf)\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"3fc36b40-6a66-4095-8acf-83d8a4e70c5d"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,1,0,0,0],[4,null,1,0,1,2,4],[7,8.0,2,1,0,4,14]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"integer\"","metadata":"{}"},{"name":"D=right","type":"\"integer\"","metadata":"{}"},{"name":"twoC","type":"\"integer\"","metadata":"{}"},{"name":"newC","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D=left | D=right | twoC | newC |
---|
1 | 2.0 | 0 | 1 | 0 | 0 | 0 |
4 | null | 1 | 0 | 1 | 2 | 4 |
7 | 8.0 | 2 | 1 | 0 | 4 | 14 |
"]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["## Visualizing feature against output feature"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d6766c6a-6ae4-4819-b076-1572ac8b288a"}}},{"cell_type":"code","source":["sparkora.plot_feature('newC')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"c6c575fb-3d1e-401e-87a2-cfcc204f2ba5"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[0,1],[4,4],[14,7]],"plotOptions":{"displayType":"plotlyLine","customPlotOptions":{"plotlyBar":[{"key":"grouped","value":true},{"key":"stacked","value":false},{"key":"100_stacked","value":false}]},"pivotColumns":[],"pivotAggregation":"sum","xColumns":["newC"],"yColumns":["A"]},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"newC","type":"\"integer\"","metadata":"{}"},{"name":"A","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":[""]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["## Model Validation"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"55d89233-4c20-4787-85e1-3ecf294c2140"}}},{"cell_type":"code","source":["sparkora.set_training_and_validation(0.8)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"4bbf37f0-4e66-454c-861f-d81b9913fae0"}},"outputs":[],"execution_count":0},{"cell_type":"code","source":["X = sparkora.training_data.select(sparkora.input_columns())\ny = sparkora.training_data.select(sparkora.output)\nX.display()\ny.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"9d232a97-b25e-425b-abf1-e5212f2536c5"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[2.0,0,1,0,0,0],[null,1,0,1,2,4],[8.0,2,1,0,4,14]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"integer\"","metadata":"{}"},{"name":"D=right","type":"\"integer\"","metadata":"{}"},{"name":"twoC","type":"\"integer\"","metadata":"{}"},{"name":"newC","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["B | C | D=left | D=right | twoC | newC |
---|
2.0 | 0 | 1 | 0 | 0 | 0 |
null | 1 | 0 | 1 | 2 | 4 |
8.0 | 2 | 1 | 0 | 4 | 14 |
"]},"transient":null},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1],[4],[7]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":[""]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["X = sparkora.validating_data.select(sparkora.input_columns())\ny = sparkora.validating_data.select(sparkora.output)\nX.display()\ny.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"72df96ff-4d21-4cf7-b237-2235bff5d712"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"integer\"","metadata":"{}"},{"name":"D=right","type":"\"integer\"","metadata":"{}"},{"name":"twoC","type":"\"integer\"","metadata":"{}"},{"name":"newC","type":"\"integer\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":[""]},"transient":null},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":[""]},"transient":null}],"execution_count":0},{"cell_type":"markdown","source":["## Versioning tranformations and states and logging the steps in each state"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"cb8d1de1-c6e0-4b9b-9892-d01a46b05bc9"}}},{"cell_type":"code","source":["df = pd.read_csv(\"https://raw.githubusercontent.com/Spratiher9/Sparkora/0.0.1/Sparkora/test_data.csv?token=AQWZISCH3QUFGHB653KPVBTBSD2XO\")\ndf = spark.createDataFrame(df)\ndf.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"8e3856c0-71be-46f9-a49b-0ef838ecfd4f"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora = Sparkora()\nsparkora.configure(output = 'A', data = df)\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"311041ab-498a-4ce2-bfec-26b0b205a776"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora.snapshot('initial_data')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"a364772e-18c0-4ec1-a068-acb22458d12b"}},"outputs":[],"execution_count":0},{"cell_type":"code","source":["sparkora.remove_feature('useless_feature')\nsparkora.extract_ordinal_feature('D')\nsparkora.impute_missing_values()\nsparkora.scale_input_values()\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"6f867853-0738-4aec-bf73-390250e66552"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,0.0,0,1.0,0.0],[4,0.5,1,0.0,1.0],[7,1.0,2,1.0,0.0]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"double\"","metadata":"{}"},{"name":"D=right","type":"\"double\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D=left | D=right |
---|
1 | 0.0 | 0 | 1.0 | 0.0 |
4 | 0.5 | 1 | 0.0 | 1.0 |
7 | 1.0 | 2 | 1.0 | 0.0 |
"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora.logs"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"fd07fff8-1657-4d9a-b12c-b46937b9095d"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"Out[39]: [\"self.remove_feature('useless_feature')\",\n \"self.extract_ordinal_feature('D')\",\n 'self.impute_missing_values(mean)',\n 'self.scale_input_values()']","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"ansi","arguments":{}}},"output_type":"display_data","data":{"text/plain":["Out[39]: [\"self.remove_feature('useless_feature')\",\n \"self.extract_ordinal_feature('D')\",\n 'self.impute_missing_values(mean)',\n 'self.scale_input_values()']"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora.snapshot('transform1')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"6c7fe2ef-92e4-4766-9dc7-c3f83c9b8221"}},"outputs":[],"execution_count":0},{"cell_type":"code","source":["sparkora.use_snapshot('initial_data')\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"f19660f7-1f6c-464d-abc2-64f202471fbb"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,2.0,0,"left",1],[4,null,1,"right",1],[7,8.0,2,"left",1]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D","type":"\"string\"","metadata":"{}"},{"name":"useless_feature","type":"\"long\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D | useless_feature |
---|
1 | 2.0 | 0 | left | 1 |
4 | null | 1 | right | 1 |
7 | 8.0 | 2 | left | 1 |
"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora.logs"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"8dace337-93ab-4143-b451-a0f003218eab"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"Out[42]: [\"self.snapshot('initial_data')\"]","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"ansi","arguments":{}}},"output_type":"display_data","data":{"text/plain":["Out[42]: [\"self.snapshot('initial_data')\"]"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora.use_snapshot('transform1')\nsparkora.data.display()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5b3ba8a5-491f-42cb-844e-1c0ac27a4829"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"overflow":false,"datasetInfos":[],"data":[[1,0.0,0,1.0,0.0],[4,0.5,1,0.0,1.0],[7,1.0,2,1.0,0.0]],"plotOptions":{"displayType":"table","customPlotOptions":{},"pivotColumns":null,"pivotAggregation":null,"xColumns":null,"yColumns":null},"columnCustomDisplayInfos":{},"aggType":"","isJsonSchema":true,"removedWidgets":[],"aggSchema":[],"schema":[{"name":"A","type":"\"long\"","metadata":"{}"},{"name":"B","type":"\"double\"","metadata":"{}"},{"name":"C","type":"\"long\"","metadata":"{}"},{"name":"D=left","type":"\"double\"","metadata":"{}"},{"name":"D=right","type":"\"double\"","metadata":"{}"}],"aggError":"","aggData":[],"addedWidgets":{},"metadata":{},"dbfsResultPath":null,"type":"table","aggOverflow":false,"aggSeriesLimitReached":false,"arguments":{}}},"output_type":"display_data","data":{"text/html":["A | B | C | D=left | D=right |
---|
1 | 0.0 | 0 | 1.0 | 0.0 |
4 | 0.5 | 1 | 0.0 | 1.0 |
7 | 1.0 | 2 | 1.0 | 0.0 |
"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":["sparkora.logs"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5206d6ca-6b1c-43ba-aa1c-9075c121472e"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"Out[44]: [\"self.remove_feature('useless_feature')\",\n \"self.extract_ordinal_feature('D')\",\n 'self.impute_missing_values(mean)',\n 'self.scale_input_values()',\n \"self.snapshot('transform1')\"]","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"ansi","arguments":{}}},"output_type":"display_data","data":{"text/plain":["Out[44]: [\"self.remove_feature('useless_feature')\",\n \"self.extract_ordinal_feature('D')\",\n 'self.impute_missing_values(mean)',\n 'self.scale_input_values()',\n \"self.snapshot('transform1')\"]"]},"transient":null}],"execution_count":0},{"cell_type":"code","source":[""],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"0b4d933b-01f8-4ae8-ab05-13c41048f9a6"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"data":"","errorSummary":"","metadata":{},"errorTraceType":null,"type":"ipynbError","arguments":{}}},"output_type":"display_data","data":{"text/html":[""]},"transient":null}],"execution_count":0}],"metadata":{"application/vnd.databricks.v1+notebook":{"notebookName":"sparkora","dashboards":[],"notebookMetadata":{"pythonIndentUnit":2},"language":"python","widgets":{},"notebookOrigID":2550983048353969}},"nbformat":4,"nbformat_minor":0}
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C) 2021 Souvik Pratiher
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C) 2021 Souvik Pratiher
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # Sparkora [](https://badge.fury.io/py/Sparkora) [](https://GitHub.com/Spratiher9/Sparkora/graphs/commit-activity) [](https://pepy.tech/project/sparkora)
3 | Exploratory data analysis toolkit for Pyspark.
4 |
5 | Dont forget to hit the star ⭐ button if you like this project and would love to see more such utilities.
6 |
7 | ## Contents
8 | - [Summary](#summary)
9 | - [Setup](#setup)
10 | - [Examples](#examples)
11 | - [Usage](#use)
12 | - [Reading Data & Configuration](#config)
13 | - [Cleaning](#clean)
14 | - [Feature Selection & Extraction](#feature)
15 | - [Visualization](#visual)
16 | - [Model Validation](#model)
17 | - [Data Versioning](#version)
18 | - [Testing](#test)
19 | - [Contribute](#contribute)
20 | - [License](#license)
21 |
22 |
23 | ## Summary
24 |
25 | Sparkora is a Python library designed to automate the painful parts of exploratory data analysis in Apache Spark.
26 |
27 | The library contains convenient functions for data cleaning, feature selection & extraction, visualization
28 | (databricks native), partitioning data for model validation, and versioning transformations of data.
29 |
30 | The library uses the following modules:
31 | * pyspark
32 | * ipython
33 | * os
34 | * copy
35 |
36 | It is intended to be a helpful addition to common Pyspark data analysis tools.
37 |
38 |
39 | ## Setup
40 |
41 | ```
42 | $ pip install Sparkora
43 | $ python
44 | >>> from Sparkora import Sparkora
45 | ```
46 |
47 |
48 | ## Examples
49 | Go to this jupyter [notebook](Example_Notebooks/sparkora.ipynb) or import [this](Example_Notebooks/sparkora.html) in databricks workspace
50 |
51 |
52 | ## Usage
53 |
54 |
55 | #### Reading Data & Configuration
56 |
57 | ```python
58 | # without initial config
59 | >>> sparkora = Sparkora()
60 | >>> sparkora.configure(output = 'A', data = 'path/to/data.csv')
61 |
62 | # is the same as
63 | >>> from pyspark.shell import spark
64 | >>> dataframe = spark.read.csv('path/to/data.csv', header=True)
65 | >>> sparkora = Sparkora(output = 'A', data = dataframe)
66 |
67 | >>> sparkora.data
68 | A B C D useless_feature
69 | 0 1 2 0 left 1
70 | 1 4 NaN 1 right 1
71 | 2 7 8 2 left 1
72 | ```
73 |
74 |
75 | #### Cleaning
76 |
77 | ```python
78 | # read data with missing and poorly scaled values
79 | >>> from pyspark.shell import spark
80 | >>> d = [
81 | ... (1, 2, 100),
82 | ... (2, None, 200),
83 | ... (1, 6, None)
84 | ... ]
85 | >>> df = spark.createDataFrame(d, "_c0 int, _c1 int, _c2 int")
86 | >>> sparkora = Sparkora(output = '_c0', data = df)
87 | >>> sparkora.data
88 | _c0 _c1 _c2
89 | 0 1 2 100
90 | 1 2 NaN 200
91 | 2 1 6 NaN
92 |
93 | # impute the missing values (by default, using 'mean' other options are 'median', 'mode')
94 | # sparkora.impute_missing_values(strategy = 'mean')
95 | >>> sparkora.impute_missing_values()
96 | >>> sparkora.data
97 | _c0 _c1 _c2
98 | 0 1 2 100
99 | 1 2 4 200
100 | 2 1 6 150
101 |
102 | # scale the values of the input variables (center to mean and scale to unit variance)
103 | >>> sparkora.scale_input_values()
104 | >>> sparkora.data
105 | _c0 _c1 _c2
106 | 0 1 -1.224745 -1.224745
107 | 1 2 0.000000 1.224745
108 | 2 1 1.224745 0.000000
109 | ```
110 |
111 |
112 | #### Feature Selection & Extraction
113 |
114 | ```python
115 | # feature selection / removing a feature
116 | >>> sparkora.data
117 | A B C D useless_feature
118 | 0 1 2 0 left 1
119 | 1 4 NaN 1 right 1
120 | 2 7 8 2 left 1
121 |
122 | >>> sparkora.remove_feature('useless_feature')
123 | >>> sparkora.data
124 | A B C D
125 | 0 1 2 0 left
126 | 1 4 NaN 1 right
127 | 2 7 8 2 left
128 |
129 | # extract an ordinal feature through one-hot encoding
130 | >>> sparkora.extract_ordinal_feature('D')
131 | >>> sparkora.data
132 | A B C D=left D=right
133 | 0 1 2 0 1 0
134 | 1 4 NaN 1 0 1
135 | 2 7 8 2 1 0
136 |
137 | # extract a transformation of another feature
138 | >>> f_udf = F.udf(lambda x: x * 2, T.IntegerType())
139 | >>> sparkora.extract_feature('C', 'twoC', f_udf)
140 | >>> sparkora.data
141 | A B C D=left D=right twoC
142 | 0 1 2 0 1 0 0
143 | 1 4 NaN 1 0 1 2
144 | 2 7 8 2 1 0 4
145 |
146 | # extract a transformation of multiple other features
147 | >>> f_udf = F.udf(lambda x,y: x * y, T.IntegerType())
148 | >>> sparkora.extract_feature(['C','A'], 'newC', f_udf)
149 | A B C D=left D=right newC
150 | 0 1 2 0 1 0 0
151 | 1 4 NaN 1 0 1 4
152 | 2 7 8 2 1 0 14
153 | ```
154 |
155 |
156 | #### Visualization
157 |
158 | ```python
159 | # Visualization features are only available if the platform is Databricks
160 |
161 | # plot a single feature against the output variable
162 | sparkora.plot_feature('column-name')
163 |
164 | # render plots of each feature against the output variable
165 | sparkora.explore()
166 | ```
167 |
168 |
169 | #### Model Validation
170 |
171 | ```python
172 | # create random partition of training / validation data (~ 80/20 split)
173 | sparkora.set_training_and_validation(0.8)
174 | # pass train size only, the validation size is calculated automatically
175 |
176 | # train a model on the data
177 | X = sparkora.training_data.select(sparkora.input_columns())
178 | y = sparkora.training_data.select(sparkora.output)
179 |
180 | some_model.fit(X, y)
181 |
182 | # validate the model
183 | X = sparkora.validating_data.select(sparkora.input_columns())
184 | y = sparkora.validating_data.select(sparkora.output)
185 |
186 | some_model.score(X, y)
187 | ```
188 |
189 |
190 | #### Data Versioning
191 |
192 | ```python
193 | # save a version of your data
194 | >>> sparkora.data
195 | A B C D useless_feature
196 | 0 1 2 0 left 1
197 | 1 4 NaN 1 right 1
198 | 2 7 8 2 left 1
199 | >>> sparkora.snapshot('initial_data')
200 |
201 | # keep track of changes to data
202 | >>> sparkora.remove_feature('useless_feature')
203 | >>> sparkora.extract_ordinal_feature('D')
204 | >>> sparkora.impute_missing_values()
205 | >>> sparkora.scale_input_values()
206 | >>> sparkora.data
207 | A B C D=left D=right
208 | 0 1 -1.224745 -1.224745 0.707107 -0.707107
209 | 1 4 0.000000 0.000000 -1.414214 1.414214
210 | 2 7 1.224745 1.224745 0.707107 -0.707107
211 |
212 | >>> sparkora.logs
213 | ["self.remove_feature('useless_feature')", "self.extract_ordinal_feature('D')", 'self.impute_missing_values()', 'self.scale_input_values()']
214 |
215 | # use a previous version of the data
216 | >>> sparkora.snapshot('transform1')
217 | >>> sparkora.use_snapshot('initial_data')
218 | >>> sparkora.data
219 | A B C D useless_feature
220 | 0 1 2 0 left 1
221 | 1 4 NaN 1 right 1
222 | 2 7 8 2 left 1
223 | >>> sparkora.logs
224 | ["sparkora.snapshot('initial_data')"]
225 |
226 | # switch back to your transformation
227 | >>> sparkora.use_snapshot('transform1')
228 | >>> sparkora.data
229 | A B C D=left D=right
230 | 0 1 -1.224745 -1.224745 0.707107 -0.707107
231 | 1 4 0.000000 0.000000 -1.414214 1.414214
232 | 2 7 1.224745 1.224745 0.707107 -0.707107
233 | >>> sparkora.logs
234 | ["self.remove_feature('useless_feature')", "self.extract_ordinal_feature('D')", 'self.impute_missing_values()', 'self.scale_input_values()']
235 | ```
236 |
237 |
238 | ## Testing
239 |
240 | To run the test suite, simply run `python testsparkora.py` from the `Sparkora` directory.
241 |
242 |
243 | ## Contribute
244 |
245 | Pull requests welcome! Feature requests / bugs will be addressed through issues on this repository. While not every feature request will necessarily be handled by me, maintaining a record for interested contributors is useful.
246 |
247 | Additionally, feel free to submit pull requests which add features or address bugs yourself.
248 |
249 |
250 |
251 | ## License
252 |
253 | GNU GENERAL PUBLIC LICENSE
254 | Version 3, 29 June 2007
255 |
256 | Copyright (C) 2007 Free Software Foundation, Inc.
257 | Everyone is permitted to copy and distribute verbatim copies
258 | of this license document, but changing it is not allowed.
259 |
260 | Preamble
261 |
262 | The GNU General Public License is a free, copyleft license for
263 | software and other kinds of works.
264 |
265 | The licenses for most software and other practical works are designed
266 | to take away your freedom to share and change the works. By contrast,
267 | the GNU General Public License is intended to guarantee your freedom to
268 | share and change all versions of a program--to make sure it remains free
269 | software for all its users. We, the Free Software Foundation, use the
270 | GNU General Public License for most of our software; it applies also to
271 | any other work released this way by its authors. You can apply it to
272 | your programs, too.
273 |
274 | When we speak of free software, we are referring to freedom, not
275 | price. Our General Public Licenses are designed to make sure that you
276 | have the freedom to distribute copies of free software (and charge for
277 | them if you wish), that you receive source code or can get it if you
278 | want it, that you can change the software or use pieces of it in new
279 | free programs, and that you know you can do these things.
280 |
281 | To protect your rights, we need to prevent others from denying you
282 | these rights or asking you to surrender the rights. Therefore, you have
283 | certain responsibilities if you distribute copies of the software, or if
284 | you modify it: responsibilities to respect the freedom of others.
285 |
286 | For example, if you distribute copies of such a program, whether
287 | gratis or for a fee, you must pass on to the recipients the same
288 | freedoms that you received. You must make sure that they, too, receive
289 | or can get the source code. And you must show them these terms so they
290 | know their rights.
291 |
292 | Developers that use the GNU GPL protect your rights with two steps:
293 | (1) assert copyright on the software, and (2) offer you this License
294 | giving you legal permission to copy, distribute and/or modify it.
295 |
296 | For the developers' and authors' protection, the GPL clearly explains
297 | that there is no warranty for this free software. For both users' and
298 | authors' sake, the GPL requires that modified versions be marked as
299 | changed, so that their problems will not be attributed erroneously to
300 | authors of previous versions.
301 |
302 | Some devices are designed to deny users access to install or run
303 | modified versions of the software inside them, although the manufacturer
304 | can do so. This is fundamentally incompatible with the aim of
305 | protecting users' freedom to change the software. The systematic
306 | pattern of such abuse occurs in the area of products for individuals to
307 | use, which is precisely where it is most unacceptable. Therefore, we
308 | have designed this version of the GPL to prohibit the practice for those
309 | products. If such problems arise substantially in other domains, we
310 | stand ready to extend this provision to those domains in future versions
311 | of the GPL, as needed to protect the freedom of users.
312 |
313 | Finally, every program is threatened constantly by software patents.
314 | States should not allow patents to restrict development and use of
315 | software on general-purpose computers, but in those that do, we wish to
316 | avoid the special danger that patents applied to a free program could
317 | make it effectively proprietary. To prevent this, the GPL assures that
318 | patents cannot be used to render the program non-free.
319 |
320 | The precise terms and conditions for copying, distribution and
321 | modification follow.
322 |
323 | TERMS AND CONDITIONS
324 |
325 | 0. Definitions.
326 |
327 | "This License" refers to version 3 of the GNU General Public License.
328 |
329 | "Copyright" also means copyright-like laws that apply to other kinds of
330 | works, such as semiconductor masks.
331 |
332 | "The Program" refers to any copyrightable work licensed under this
333 | License. Each licensee is addressed as "you". "Licensees" and
334 | "recipients" may be individuals or organizations.
335 |
336 | To "modify" a work means to copy from or adapt all or part of the work
337 | in a fashion requiring copyright permission, other than the making of an
338 | exact copy. The resulting work is called a "modified version" of the
339 | earlier work or a work "based on" the earlier work.
340 |
341 | A "covered work" means either the unmodified Program or a work based
342 | on the Program.
343 |
344 | To "propagate" a work means to do anything with it that, without
345 | permission, would make you directly or secondarily liable for
346 | infringement under applicable copyright law, except executing it on a
347 | computer or modifying a private copy. Propagation includes copying,
348 | distribution (with or without modification), making available to the
349 | public, and in some countries other activities as well.
350 |
351 | To "convey" a work means any kind of propagation that enables other
352 | parties to make or receive copies. Mere interaction with a user through
353 | a computer network, with no transfer of a copy, is not conveying.
354 |
355 | An interactive user interface displays "Appropriate Legal Notices"
356 | to the extent that it includes a convenient and prominently visible
357 | feature that (1) displays an appropriate copyright notice, and (2)
358 | tells the user that there is no warranty for the work (except to the
359 | extent that warranties are provided), that licensees may convey the
360 | work under this License, and how to view a copy of this License. If
361 | the interface presents a list of user commands or options, such as a
362 | menu, a prominent item in the list meets this criterion.
363 |
364 | 1. Source Code.
365 |
366 | The "source code" for a work means the preferred form of the work
367 | for making modifications to it. "Object code" means any non-source
368 | form of a work.
369 |
370 | A "Standard Interface" means an interface that either is an official
371 | standard defined by a recognized standards body, or, in the case of
372 | interfaces specified for a particular programming language, one that
373 | is widely used among developers working in that language.
374 |
375 | The "System Libraries" of an executable work include anything, other
376 | than the work as a whole, that (a) is included in the normal form of
377 | packaging a Major Component, but which is not part of that Major
378 | Component, and (b) serves only to enable use of the work with that
379 | Major Component, or to implement a Standard Interface for which an
380 | implementation is available to the public in source code form. A
381 | "Major Component", in this context, means a major essential component
382 | (kernel, window system, and so on) of the specific operating system
383 | (if any) on which the executable work runs, or a compiler used to
384 | produce the work, or an object code interpreter used to run it.
385 |
386 | The "Corresponding Source" for a work in object code form means all
387 | the source code needed to generate, install, and (for an executable
388 | work) run the object code and to modify the work, including scripts to
389 | control those activities. However, it does not include the work's
390 | System Libraries, or general-purpose tools or generally available free
391 | programs which are used unmodified in performing those activities but
392 | which are not part of the work. For example, Corresponding Source
393 | includes interface definition files associated with source files for
394 | the work, and the source code for shared libraries and dynamically
395 | linked subprograms that the work is specifically designed to require,
396 | such as by intimate data communication or control flow between those
397 | subprograms and other parts of the work.
398 |
399 | The Corresponding Source need not include anything that users
400 | can regenerate automatically from other parts of the Corresponding
401 | Source.
402 |
403 | The Corresponding Source for a work in source code form is that
404 | same work.
405 |
406 | 2. Basic Permissions.
407 |
408 | All rights granted under this License are granted for the term of
409 | copyright on the Program, and are irrevocable provided the stated
410 | conditions are met. This License explicitly affirms your unlimited
411 | permission to run the unmodified Program. The output from running a
412 | covered work is covered by this License only if the output, given its
413 | content, constitutes a covered work. This License acknowledges your
414 | rights of fair use or other equivalent, as provided by copyright law.
415 |
416 | You may make, run and propagate covered works that you do not
417 | convey, without conditions so long as your license otherwise remains
418 | in force. You may convey covered works to others for the sole purpose
419 | of having them make modifications exclusively for you, or provide you
420 | with facilities for running those works, provided that you comply with
421 | the terms of this License in conveying all material for which you do
422 | not control copyright. Those thus making or running the covered works
423 | for you must do so exclusively on your behalf, under your direction
424 | and control, on terms that prohibit them from making any copies of
425 | your copyrighted material outside their relationship with you.
426 |
427 | Conveying under any other circumstances is permitted solely under
428 | the conditions stated below. Sublicensing is not allowed; section 10
429 | makes it unnecessary.
430 |
431 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
432 |
433 | No covered work shall be deemed part of an effective technological
434 | measure under any applicable law fulfilling obligations under article
435 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
436 | similar laws prohibiting or restricting circumvention of such
437 | measures.
438 |
439 | When you convey a covered work, you waive any legal power to forbid
440 | circumvention of technological measures to the extent such circumvention
441 | is effected by exercising rights under this License with respect to
442 | the covered work, and you disclaim any intention to limit operation or
443 | modification of the work as a means of enforcing, against the work's
444 | users, your or third parties' legal rights to forbid circumvention of
445 | technological measures.
446 |
447 | 4. Conveying Verbatim Copies.
448 |
449 | You may convey verbatim copies of the Program's source code as you
450 | receive it, in any medium, provided that you conspicuously and
451 | appropriately publish on each copy an appropriate copyright notice;
452 | keep intact all notices stating that this License and any
453 | non-permissive terms added in accord with section 7 apply to the code;
454 | keep intact all notices of the absence of any warranty; and give all
455 | recipients a copy of this License along with the Program.
456 |
457 | You may charge any price or no price for each copy that you convey,
458 | and you may offer support or warranty protection for a fee.
459 |
460 | 5. Conveying Modified Source Versions.
461 |
462 | You may convey a work based on the Program, or the modifications to
463 | produce it from the Program, in the form of source code under the
464 | terms of section 4, provided that you also meet all of these conditions:
465 |
466 | a) The work must carry prominent notices stating that you modified
467 | it, and giving a relevant date.
468 |
469 | b) The work must carry prominent notices stating that it is
470 | released under this License and any conditions added under section
471 | 7. This requirement modifies the requirement in section 4 to
472 | "keep intact all notices".
473 |
474 | c) You must license the entire work, as a whole, under this
475 | License to anyone who comes into possession of a copy. This
476 | License will therefore apply, along with any applicable section 7
477 | additional terms, to the whole of the work, and all its parts,
478 | regardless of how they are packaged. This License gives no
479 | permission to license the work in any other way, but it does not
480 | invalidate such permission if you have separately received it.
481 |
482 | d) If the work has interactive user interfaces, each must display
483 | Appropriate Legal Notices; however, if the Program has interactive
484 | interfaces that do not display Appropriate Legal Notices, your
485 | work need not make them do so.
486 |
487 | A compilation of a covered work with other separate and independent
488 | works, which are not by their nature extensions of the covered work,
489 | and which are not combined with it such as to form a larger program,
490 | in or on a volume of a storage or distribution medium, is called an
491 | "aggregate" if the compilation and its resulting copyright are not
492 | used to limit the access or legal rights of the compilation's users
493 | beyond what the individual works permit. Inclusion of a covered work
494 | in an aggregate does not cause this License to apply to the other
495 | parts of the aggregate.
496 |
497 | 6. Conveying Non-Source Forms.
498 |
499 | You may convey a covered work in object code form under the terms
500 | of sections 4 and 5, provided that you also convey the
501 | machine-readable Corresponding Source under the terms of this License,
502 | in one of these ways:
503 |
504 | a) Convey the object code in, or embodied in, a physical product
505 | (including a physical distribution medium), accompanied by the
506 | Corresponding Source fixed on a durable physical medium
507 | customarily used for software interchange.
508 |
509 | b) Convey the object code in, or embodied in, a physical product
510 | (including a physical distribution medium), accompanied by a
511 | written offer, valid for at least three years and valid for as
512 | long as you offer spare parts or customer support for that product
513 | model, to give anyone who possesses the object code either (1) a
514 | copy of the Corresponding Source for all the software in the
515 | product that is covered by this License, on a durable physical
516 | medium customarily used for software interchange, for a price no
517 | more than your reasonable cost of physically performing this
518 | conveying of source, or (2) access to copy the
519 | Corresponding Source from a network server at no charge.
520 |
521 | c) Convey individual copies of the object code with a copy of the
522 | written offer to provide the Corresponding Source. This
523 | alternative is allowed only occasionally and noncommercially, and
524 | only if you received the object code with such an offer, in accord
525 | with subsection 6b.
526 |
527 | d) Convey the object code by offering access from a designated
528 | place (gratis or for a charge), and offer equivalent access to the
529 | Corresponding Source in the same way through the same place at no
530 | further charge. You need not require recipients to copy the
531 | Corresponding Source along with the object code. If the place to
532 | copy the object code is a network server, the Corresponding Source
533 | may be on a different server (operated by you or a third party)
534 | that supports equivalent copying facilities, provided you maintain
535 | clear directions next to the object code saying where to find the
536 | Corresponding Source. Regardless of what server hosts the
537 | Corresponding Source, you remain obligated to ensure that it is
538 | available for as long as needed to satisfy these requirements.
539 |
540 | e) Convey the object code using peer-to-peer transmission, provided
541 | you inform other peers where the object code and Corresponding
542 | Source of the work are being offered to the general public at no
543 | charge under subsection 6d.
544 |
545 | A separable portion of the object code, whose source code is excluded
546 | from the Corresponding Source as a System Library, need not be
547 | included in conveying the object code work.
548 |
549 | A "User Product" is either (1) a "consumer product", which means any
550 | tangible personal property which is normally used for personal, family,
551 | or household purposes, or (2) anything designed or sold for incorporation
552 | into a dwelling. In determining whether a product is a consumer product,
553 | doubtful cases shall be resolved in favor of coverage. For a particular
554 | product received by a particular user, "normally used" refers to a
555 | typical or common use of that class of product, regardless of the status
556 | of the particular user or of the way in which the particular user
557 | actually uses, or expects or is expected to use, the product. A product
558 | is a consumer product regardless of whether the product has substantial
559 | commercial, industrial or non-consumer uses, unless such uses represent
560 | the only significant mode of use of the product.
561 |
562 | "Installation Information" for a User Product means any methods,
563 | procedures, authorization keys, or other information required to install
564 | and execute modified versions of a covered work in that User Product from
565 | a modified version of its Corresponding Source. The information must
566 | suffice to ensure that the continued functioning of the modified object
567 | code is in no case prevented or interfered with solely because
568 | modification has been made.
569 |
570 | If you convey an object code work under this section in, or with, or
571 | specifically for use in, a User Product, and the conveying occurs as
572 | part of a transaction in which the right of possession and use of the
573 | User Product is transferred to the recipient in perpetuity or for a
574 | fixed term (regardless of how the transaction is characterized), the
575 | Corresponding Source conveyed under this section must be accompanied
576 | by the Installation Information. But this requirement does not apply
577 | if neither you nor any third party retains the ability to install
578 | modified object code on the User Product (for example, the work has
579 | been installed in ROM).
580 |
581 | The requirement to provide Installation Information does not include a
582 | requirement to continue to provide support service, warranty, or updates
583 | for a work that has been modified or installed by the recipient, or for
584 | the User Product in which it has been modified or installed. Access to a
585 | network may be denied when the modification itself materially and
586 | adversely affects the operation of the network or violates the rules and
587 | protocols for communication across the network.
588 |
589 | Corresponding Source conveyed, and Installation Information provided,
590 | in accord with this section must be in a format that is publicly
591 | documented (and with an implementation available to the public in
592 | source code form), and must require no special password or key for
593 | unpacking, reading or copying.
594 |
595 | 7. Additional Terms.
596 |
597 | "Additional permissions" are terms that supplement the terms of this
598 | License by making exceptions from one or more of its conditions.
599 | Additional permissions that are applicable to the entire Program shall
600 | be treated as though they were included in this License, to the extent
601 | that they are valid under applicable law. If additional permissions
602 | apply only to part of the Program, that part may be used separately
603 | under those permissions, but the entire Program remains governed by
604 | this License without regard to the additional permissions.
605 |
606 | When you convey a copy of a covered work, you may at your option
607 | remove any additional permissions from that copy, or from any part of
608 | it. (Additional permissions may be written to require their own
609 | removal in certain cases when you modify the work.) You may place
610 | additional permissions on material, added by you to a covered work,
611 | for which you have or can give appropriate copyright permission.
612 |
613 | Notwithstanding any other provision of this License, for material you
614 | add to a covered work, you may (if authorized by the copyright holders of
615 | that material) supplement the terms of this License with terms:
616 |
617 | a) Disclaiming warranty or limiting liability differently from the
618 | terms of sections 15 and 16 of this License; or
619 |
620 | b) Requiring preservation of specified reasonable legal notices or
621 | author attributions in that material or in the Appropriate Legal
622 | Notices displayed by works containing it; or
623 |
624 | c) Prohibiting misrepresentation of the origin of that material, or
625 | requiring that modified versions of such material be marked in
626 | reasonable ways as different from the original version; or
627 |
628 | d) Limiting the use for publicity purposes of names of licensors or
629 | authors of the material; or
630 |
631 | e) Declining to grant rights under trademark law for use of some
632 | trade names, trademarks, or service marks; or
633 |
634 | f) Requiring indemnification of licensors and authors of that
635 | material by anyone who conveys the material (or modified versions of
636 | it) with contractual assumptions of liability to the recipient, for
637 | any liability that these contractual assumptions directly impose on
638 | those licensors and authors.
639 |
640 | All other non-permissive additional terms are considered "further
641 | restrictions" within the meaning of section 10. If the Program as you
642 | received it, or any part of it, contains a notice stating that it is
643 | governed by this License along with a term that is a further
644 | restriction, you may remove that term. If a license document contains
645 | a further restriction but permits relicensing or conveying under this
646 | License, you may add to a covered work material governed by the terms
647 | of that license document, provided that the further restriction does
648 | not survive such relicensing or conveying.
649 |
650 | If you add terms to a covered work in accord with this section, you
651 | must place, in the relevant source files, a statement of the
652 | additional terms that apply to those files, or a notice indicating
653 | where to find the applicable terms.
654 |
655 | Additional terms, permissive or non-permissive, may be stated in the
656 | form of a separately written license, or stated as exceptions;
657 | the above requirements apply either way.
658 |
659 | 8. Termination.
660 |
661 | You may not propagate or modify a covered work except as expressly
662 | provided under this License. Any attempt otherwise to propagate or
663 | modify it is void, and will automatically terminate your rights under
664 | this License (including any patent licenses granted under the third
665 | paragraph of section 11).
666 |
667 | However, if you cease all violation of this License, then your
668 | license from a particular copyright holder is reinstated (a)
669 | provisionally, unless and until the copyright holder explicitly and
670 | finally terminates your license, and (b) permanently, if the copyright
671 | holder fails to notify you of the violation by some reasonable means
672 | prior to 60 days after the cessation.
673 |
674 | Moreover, your license from a particular copyright holder is
675 | reinstated permanently if the copyright holder notifies you of the
676 | violation by some reasonable means, this is the first time you have
677 | received notice of violation of this License (for any work) from that
678 | copyright holder, and you cure the violation prior to 30 days after
679 | your receipt of the notice.
680 |
681 | Termination of your rights under this section does not terminate the
682 | licenses of parties who have received copies or rights from you under
683 | this License. If your rights have been terminated and not permanently
684 | reinstated, you do not qualify to receive new licenses for the same
685 | material under section 10.
686 |
687 | 9. Acceptance Not Required for Having Copies.
688 |
689 | You are not required to accept this License in order to receive or
690 | run a copy of the Program. Ancillary propagation of a covered work
691 | occurring solely as a consequence of using peer-to-peer transmission
692 | to receive a copy likewise does not require acceptance. However,
693 | nothing other than this License grants you permission to propagate or
694 | modify any covered work. These actions infringe copyright if you do
695 | not accept this License. Therefore, by modifying or propagating a
696 | covered work, you indicate your acceptance of this License to do so.
697 |
698 | 10. Automatic Licensing of Downstream Recipients.
699 |
700 | Each time you convey a covered work, the recipient automatically
701 | receives a license from the original licensors, to run, modify and
702 | propagate that work, subject to this License. You are not responsible
703 | for enforcing compliance by third parties with this License.
704 |
705 | An "entity transaction" is a transaction transferring control of an
706 | organization, or substantially all assets of one, or subdividing an
707 | organization, or merging organizations. If propagation of a covered
708 | work results from an entity transaction, each party to that
709 | transaction who receives a copy of the work also receives whatever
710 | licenses to the work the party's predecessor in interest had or could
711 | give under the previous paragraph, plus a right to possession of the
712 | Corresponding Source of the work from the predecessor in interest, if
713 | the predecessor has it or can get it with reasonable efforts.
714 |
715 | You may not impose any further restrictions on the exercise of the
716 | rights granted or affirmed under this License. For example, you may
717 | not impose a license fee, royalty, or other charge for exercise of
718 | rights granted under this License, and you may not initiate litigation
719 | (including a cross-claim or counterclaim in a lawsuit) alleging that
720 | any patent claim is infringed by making, using, selling, offering for
721 | sale, or importing the Program or any portion of it.
722 |
723 | 11. Patents.
724 |
725 | A "contributor" is a copyright holder who authorizes use under this
726 | License of the Program or a work on which the Program is based. The
727 | work thus licensed is called the contributor's "contributor version".
728 |
729 | A contributor's "essential patent claims" are all patent claims
730 | owned or controlled by the contributor, whether already acquired or
731 | hereafter acquired, that would be infringed by some manner, permitted
732 | by this License, of making, using, or selling its contributor version,
733 | but do not include claims that would be infringed only as a
734 | consequence of further modification of the contributor version. For
735 | purposes of this definition, "control" includes the right to grant
736 | patent sublicenses in a manner consistent with the requirements of
737 | this License.
738 |
739 | Each contributor grants you a non-exclusive, worldwide, royalty-free
740 | patent license under the contributor's essential patent claims, to
741 | make, use, sell, offer for sale, import and otherwise run, modify and
742 | propagate the contents of its contributor version.
743 |
744 | In the following three paragraphs, a "patent license" is any express
745 | agreement or commitment, however denominated, not to enforce a patent
746 | (such as an express permission to practice a patent or covenant not to
747 | sue for patent infringement). To "grant" such a patent license to a
748 | party means to make such an agreement or commitment not to enforce a
749 | patent against the party.
750 |
751 | If you convey a covered work, knowingly relying on a patent license,
752 | and the Corresponding Source of the work is not available for anyone
753 | to copy, free of charge and under the terms of this License, through a
754 | publicly available network server or other readily accessible means,
755 | then you must either (1) cause the Corresponding Source to be so
756 | available, or (2) arrange to deprive yourself of the benefit of the
757 | patent license for this particular work, or (3) arrange, in a manner
758 | consistent with the requirements of this License, to extend the patent
759 | license to downstream recipients. "Knowingly relying" means you have
760 | actual knowledge that, but for the patent license, your conveying the
761 | covered work in a country, or your recipient's use of the covered work
762 | in a country, would infringe one or more identifiable patents in that
763 | country that you have reason to believe are valid.
764 |
765 | If, pursuant to or in connection with a single transaction or
766 | arrangement, you convey, or propagate by procuring conveyance of, a
767 | covered work, and grant a patent license to some of the parties
768 | receiving the covered work authorizing them to use, propagate, modify
769 | or convey a specific copy of the covered work, then the patent license
770 | you grant is automatically extended to all recipients of the covered
771 | work and works based on it.
772 |
773 | A patent license is "discriminatory" if it does not include within
774 | the scope of its coverage, prohibits the exercise of, or is
775 | conditioned on the non-exercise of one or more of the rights that are
776 | specifically granted under this License. You may not convey a covered
777 | work if you are a party to an arrangement with a third party that is
778 | in the business of distributing software, under which you make payment
779 | to the third party based on the extent of your activity of conveying
780 | the work, and under which the third party grants, to any of the
781 | parties who would receive the covered work from you, a discriminatory
782 | patent license (a) in connection with copies of the covered work
783 | conveyed by you (or copies made from those copies), or (b) primarily
784 | for and in connection with specific products or compilations that
785 | contain the covered work, unless you entered into that arrangement,
786 | or that patent license was granted, prior to 28 March 2007.
787 |
788 | Nothing in this License shall be construed as excluding or limiting
789 | any implied license or other defenses to infringement that may
790 | otherwise be available to you under applicable patent law.
791 |
792 | 12. No Surrender of Others' Freedom.
793 |
794 | If conditions are imposed on you (whether by court order, agreement or
795 | otherwise) that contradict the conditions of this License, they do not
796 | excuse you from the conditions of this License. If you cannot convey a
797 | covered work so as to satisfy simultaneously your obligations under this
798 | License and any other pertinent obligations, then as a consequence you may
799 | not convey it at all. For example, if you agree to terms that obligate you
800 | to collect a royalty for further conveying from those to whom you convey
801 | the Program, the only way you could satisfy both those terms and this
802 | License would be to refrain entirely from conveying the Program.
803 |
804 | 13. Use with the GNU Affero General Public License.
805 |
806 | Notwithstanding any other provision of this License, you have
807 | permission to link or combine any covered work with a work licensed
808 | under version 3 of the GNU Affero General Public License into a single
809 | combined work, and to convey the resulting work. The terms of this
810 | License will continue to apply to the part which is the covered work,
811 | but the special requirements of the GNU Affero General Public License,
812 | section 13, concerning interaction through a network will apply to the
813 | combination as such.
814 |
815 | 14. Revised Versions of this License.
816 |
817 | The Free Software Foundation may publish revised and/or new versions of
818 | the GNU General Public License from time to time. Such new versions will
819 | be similar in spirit to the present version, but may differ in detail to
820 | address new problems or concerns.
821 |
822 | Each version is given a distinguishing version number. If the
823 | Program specifies that a certain numbered version of the GNU General
824 | Public License "or any later version" applies to it, you have the
825 | option of following the terms and conditions either of that numbered
826 | version or of any later version published by the Free Software
827 | Foundation. If the Program does not specify a version number of the
828 | GNU General Public License, you may choose any version ever published
829 | by the Free Software Foundation.
830 |
831 | If the Program specifies that a proxy can decide which future
832 | versions of the GNU General Public License can be used, that proxy's
833 | public statement of acceptance of a version permanently authorizes you
834 | to choose that version for the Program.
835 |
836 | Later license versions may give you additional or different
837 | permissions. However, no additional obligations are imposed on any
838 | author or copyright holder as a result of your choosing to follow a
839 | later version.
840 |
841 | 15. Disclaimer of Warranty.
842 |
843 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
844 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
845 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
846 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
847 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
848 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
849 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
850 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
851 |
852 | 16. Limitation of Liability.
853 |
854 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
855 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
856 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
857 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
858 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
859 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
860 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
861 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
862 | SUCH DAMAGES.
863 |
864 | 17. Interpretation of Sections 15 and 16.
865 |
866 | If the disclaimer of warranty and limitation of liability provided
867 | above cannot be given local legal effect according to their terms,
868 | reviewing courts shall apply local law that most closely approximates
869 | an absolute waiver of all civil liability in connection with the
870 | Program, unless a warranty or assumption of liability accompanies a
871 | copy of the Program in return for a fee.
872 |
873 | END OF TERMS AND CONDITIONS
874 |
875 | How to Apply These Terms to Your New Programs
876 |
877 | If you develop a new program, and you want it to be of the greatest
878 | possible use to the public, the best way to achieve this is to make it
879 | free software which everyone can redistribute and change under these terms.
880 |
881 | To do so, attach the following notices to the program. It is safest
882 | to attach them to the start of each source file to most effectively
883 | state the exclusion of warranty; and each file should have at least
884 | the "copyright" line and a pointer to where the full notice is found.
885 |
886 |
887 | Copyright (C) 2021 Souvik Pratiher
888 |
889 | This program is free software: you can redistribute it and/or modify
890 | it under the terms of the GNU General Public License as published by
891 | the Free Software Foundation, either version 3 of the License, or
892 | (at your option) any later version.
893 |
894 | This program is distributed in the hope that it will be useful,
895 | but WITHOUT ANY WARRANTY; without even the implied warranty of
896 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
897 | GNU General Public License for more details.
898 |
899 | You should have received a copy of the GNU General Public License
900 | along with this program. If not, see .
901 |
902 | Also add information on how to contact you by electronic and paper mail.
903 |
904 | If the program does terminal interaction, make it output a short
905 | notice like this when it starts in an interactive mode:
906 |
907 | Copyright (C) 2021 Souvik Pratiher
908 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
909 | This is free software, and you are welcome to redistribute it
910 | under certain conditions; type `show c' for details.
911 |
912 | The hypothetical commands `show w' and `show c' should show the appropriate
913 | parts of the General Public License. Of course, your program's commands
914 | might be different; for a GUI interface, you would use an "about box".
915 |
916 | You should also get your employer (if you work as a programmer) or school,
917 | if any, to sign a "copyright disclaimer" for the program, if necessary.
918 | For more information on this, and how to apply and follow the GNU GPL, see
919 | .
920 |
921 | The GNU General Public License does not permit incorporating your program
922 | into proprietary programs. If your program is a subroutine library, you
923 | may consider it more useful to permit linking proprietary applications with
924 | the library. If this is what you want to do, use the GNU Lesser General
925 | Public License instead of this License. But first, please read
926 | .
927 |
--------------------------------------------------------------------------------
/Sparkora/__init__.py:
--------------------------------------------------------------------------------
1 | from .main import Sparkora
--------------------------------------------------------------------------------
/Sparkora/main.py:
--------------------------------------------------------------------------------
1 | from pyspark.shell import spark
2 | from pyspark.sql.dataframe import DataFrame
3 | from pyspark.sql import functions as F
4 | from pyspark.sql import types as T
5 | import os
6 | from copy import deepcopy
7 | from pyspark.ml.feature import Imputer
8 | from IPython import get_ipython
9 |
10 |
11 | class Sparkora:
12 | def __init__(self, data=None, output=None):
13 | """
14 | Sparkora core class. Entry point to the Sparkora functionality.
15 |
16 | :param data: can be dataframe or path to csv.
17 | :param output: output data column(s).
18 | """
19 | self.snapshots = {}
20 | self.logs = []
21 | self.data = None
22 | self.output = None
23 | self.training_data = None
24 | self.validating_data = None
25 | self.initial_data = None
26 | self.configure(data=data, output=output)
27 |
28 | def configure(self, data=None, output=None):
29 | """
30 | Method for configuring the Sparkora object.
31 |
32 | :param data: dataset on which Sparkora object will be wrapped.
33 | :param output: output column name.
34 | :return: None
35 | """
36 | if type(output) is str:
37 | self.output = output
38 | if type(data) is str:
39 | self.initial_data = spark.read.csv(data, header=True)
40 | self.data = self.initial_data
41 | self.logs = []
42 | if type(data) is DataFrame:
43 | self.initial_data = data
44 | self.data = data
45 | self.logs = []
46 |
47 | def remove_feature(self, feature_name):
48 | """
49 | Method for removing a feature.
50 |
51 | :param feature_name: name of the feature to be dropped.
52 | :return: None
53 | """
54 | self.data = self.data.drop(feature_name)
55 | self._log("self.remove_feature('{0}')".format(feature_name))
56 |
57 | def extract_feature(self, old_feat, new_feat, mapper):
58 | """
59 | Method for extracting new feature from existing feature(s).
60 |
61 | :param old_feat: feature(s) which will be used to build the new feature.
62 | :param new_feat: new feature's name.
63 | :param mapper: the logic to be applied for the creation of the new feature.
64 | :return: None
65 | """
66 | if type(old_feat) is str:
67 | self.data = self.data.withColumn(new_feat, mapper(self.data[old_feat]))
68 | else:
69 | self.data = self.data.withColumn(new_feat, mapper(*old_feat))
70 | self._log("self.extract_feature({0}, {1}, {2})".format(old_feat, new_feat, mapper))
71 |
72 | def impute_missing_values(self, strategy="mean"):
73 | """
74 | Method for imputing missing values with a chosen strategy of imputation.
75 | There are 3 strategies for imputation:
76 |
77 | 1. mean
78 | 2. median
79 | 3. mode
80 |
81 | :param strategy: type of strategy to be used for imputation, by default mean is used.
82 | :return: None
83 | """
84 | column_names = self.input_columns()
85 | dtype_ls = self.data.select(column_names).dtypes
86 | column_names = [i[0] for i in dtype_ls if i[1] in ('int','float','double','long','short','decimal')]
87 | imp = Imputer(inputCols=column_names, outputCols=column_names).setStrategy(strategy)
88 | self.data = imp.fit(self.data).transform(self.data)
89 | self._log("self.impute_missing_values({0})".format(strategy))
90 |
91 | def scale_input_values(self):
92 | """
93 | Method for normalizing the data with Max-Min Scaler.
94 |
95 | :return: None
96 | """
97 | column_names = self.input_columns()
98 | dtype_ls = self.data.select(column_names).dtypes
99 | column_names = [i[0] for i in dtype_ls if i[1] in ('int', 'float', 'double', 'long', 'short', 'decimal')]
100 | for col in column_names:
101 | values = self.data.agg(F.max(col).alias("max_value"), F.min(col).alias("min_value")).collect()[0]
102 | max_value = values["max_value"]
103 | min_value = values["min_value"]
104 | denom = max_value - min_value
105 | scaler_udf = F.udf(lambda x: (x - min_value) / denom, T.DoubleType())
106 | self.data = self.data.withColumn(col, scaler_udf(self.data[col]))
107 | self._log("self.scale_input_values()")
108 |
109 | def extract_ordinal_feature(self, feature_name):
110 | """
111 | Method for one hot encoding and extracting the encoded features for a given feature.
112 |
113 | :param feature_name: feature to be parsed and extracted from.
114 | :return: None
115 | """
116 | categories = self.data.select(feature_name).distinct().rdd.flatMap(lambda x: x).collect()
117 | for category in categories:
118 | self.data = self.data.withColumn("{}={}".format(feature_name, category),
119 | F.when(F.col(feature_name) == category, F.lit(1)).otherwise(0))
120 | self.data = self.data.drop(feature_name)
121 | self._log("self.extract_ordinal_feature('{0}')".format(feature_name))
122 |
123 | def set_training_and_validation(self, train_size=0.8):
124 | """
125 | Method for splitting the data into training and validation sets.
126 |
127 | :param train_size: floating point value indicating the amount of data to be kept in training set (remaining
128 | in validation set).
129 | :return: None
130 | """
131 | validation_size = 1 - train_size
132 | self.training_data, self.validating_data = self.data.randomSplit(weights=[train_size, validation_size],
133 | seed=200)
134 | self._log("self.set_training_and_validation({})".format(train_size))
135 |
136 | def plot_feature(self, feature_name):
137 | """
138 | Method for plotting feature against the output column. (Available only for Databricks)
139 |
140 | :param feature_name: feature to be plotted against output.
141 | :return: None
142 | """
143 | if "DATABRICKS_RUNTIME_VERSION" in os.environ.keys():
144 | display = get_ipython().user_ns['display']
145 | display(self.data.select(feature_name, self.output))
146 | self._log("self.plot_feature('{}')".format(feature_name))
147 | else:
148 | raise Exception("plotting feature's only available in Databricks 💀")
149 |
150 | def input_columns(self):
151 | """
152 | Method for setting the input columns in the dataset.
153 |
154 | :return: list of input column names
155 | """
156 | column_names = self.data.columns
157 | column_names.remove(self.output)
158 | return column_names
159 |
160 | def explore(self):
161 | """
162 | Method for plotting the features of the dataset against the output(s) of the dataset.
163 | Best viewed in databricks runtime 10.0.0 and above.
164 |
165 | :return: None
166 | """
167 | if "DATABRICKS_RUNTIME_VERSION" in os.environ.keys():
168 | features = self.input_columns()
169 | self._log("self.explore() begins")
170 | for feature in features:
171 | self.plot_feature(feature)
172 | self._log("self.explore() ends")
173 | else:
174 | raise Exception("explore only available in Databricks 💀")
175 |
176 | def snapshot(self, name):
177 | """
178 | Method for taking a snapshot of the current state of the data in the Sparkora object.
179 |
180 | :param name: name of the snapshot by which we can refer later if required.
181 | :return: None
182 | """
183 | self._log("self.snapshot('{}')".format(name))
184 | snapshot = {
185 | "data": self.data,
186 | "logs": deepcopy(self.logs)
187 | }
188 | self.snapshots[name] = snapshot
189 | self.logs = []
190 |
191 | def use_snapshot(self, name):
192 | """
193 | Method for restoring back to a particular state.
194 |
195 | :param name: name of the snapshot to which the state has to be restored to
196 | :return: None
197 | """
198 | self.data = self.snapshots[name]["data"]
199 | self.logs = self.snapshots[name]["logs"]
200 |
201 | def _log(self, string):
202 | """
203 | Method for storing operation statements as part of logging.
204 |
205 | :param string: the statement to be logged
206 | :return:
207 | """
208 | self.logs.append(string)
209 |
--------------------------------------------------------------------------------
/Sparkora/test_data.csv:
--------------------------------------------------------------------------------
1 | "A","B","C","D","useless_feature"
2 | 1,2,0,"left",1
3 | 4,,1,"right",1
4 | 7,8,2,"left",1
--------------------------------------------------------------------------------
/Sparkora/testsparkora.py:
--------------------------------------------------------------------------------
1 | import unittest
2 | from main import Sparkora
3 | from pyspark.shell import spark
4 | import pandas as pd
5 |
6 | class TestSparkora(unittest.TestCase):
7 | def setUp(self):
8 | self.sparkora = Sparkora()
9 | self.sparkora.configure(output = 'A', data = './test_data.csv')
10 |
11 | def test_configure(self):
12 | data = spark.read.csv('./test_data.csv',header=True)
13 | self.assertEqual(self.sparkora.output, 'A')
14 | self.assertEqual(self.sparkora.data,data)
15 |
16 | def test_remove_feature(self):
17 | self.sparkora.remove_feature('useless_feature')
18 | self.assertFalse('useless_feature' in self.sparkora.data.columns)
19 |
20 | def test_extract_feature(self):
21 | self.sparkora.extract_feature(
22 | 'useless_feature',
23 | 'another_useless_feature',
24 | lambda x: x * 2
25 | )
26 | actual_column = self.sparkora.data.select("another_useless_feature").rdd.flatMap(lambda x: x).collect()
27 | expected_column = [2, 2, 2]
28 | self.assertEqual(actual_column, expected_column)
29 |
30 | def test_impute_missing_values(self):
31 | self.sparkora.impute_missing_values()
32 | actual_column = self.sparkora.data.select("B").rdd.flatMap(lambda x: x).collect()
33 | expected_column = [2.0, 5.0, 8.0]
34 | self.assertEqual(actual_column, expected_column)
35 |
36 | def test_scale_input_values(self):
37 | self.sparkora.scale_input_values()
38 | actual_column = self.sparkora.data.select("C").rdd.flatMap(lambda x: x).collect()
39 | expected_column = [-1.224745, 0.0, 1.224745]
40 | pairwise_diffs = map(
41 | lambda actual, expected: abs(actual - expected),
42 | actual_column,
43 | expected_column
44 | )
45 | total_diff = sum(pairwise_diffs)
46 | self.assertAlmostEqual(total_diff, 0, places = 6)
47 |
48 | def test_extract_ordinal_feature(self):
49 | self.sparkora.extract_ordinal_feature('D')
50 | features = self.sparkora.data.columns
51 | self.assertTrue('D=left' in features and 'D=right' in features)
52 |
53 | def test_input_columns(self):
54 | actual_input_columns = self.sparkora.input_columns()
55 | expected_input_columns = self.sparkora.data.columns
56 | expected_input_columns.remove(self.sparkora.output)
57 | self.assertEqual(actual_input_columns, expected_input_columns)
58 |
59 | def test_logs(self):
60 | self.sparkora.extract_ordinal_feature('D')
61 | self.sparkora.impute_missing_values()
62 | self.sparkora.scale_input_values()
63 |
64 | actual_logs = self.sparkora.logs
65 | expected_logs = [
66 | "self.extract_ordinal_feature('D')",
67 | 'self.impute_missing_values()',
68 | 'self.scale_input_values()'
69 | ]
70 | self.assertEqual(actual_logs, expected_logs)
71 |
72 | def test_snapshots(self):
73 | self.sparkora.snapshot('start')
74 | self.sparkora.extract_ordinal_feature('D')
75 | self.sparkora.use_snapshot('start')
76 |
77 | self.assertEqual(self.sparkora.logs, [])
78 | self.assertTrue(self.sparkora.data.equals(self.sparkora.initial_data))
79 |
80 | if __name__ == '__main__':
81 | unittest.main()
--------------------------------------------------------------------------------
/assets/project_cover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Spratiher9/Sparkora/27dd981a9ae0272732ae4f16e4bd435f68e6ad04/assets/project_cover.gif
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Spratiher9/Sparkora/27dd981a9ae0272732ae4f16e4bd435f68e6ad04/requirements.txt
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # Author: Souvik Pratiher
2 | # Project: Sparkora v0.0.1
3 |
4 |
5 | import os
6 | from setuptools import setup
7 |
8 | if os.path.isfile('README.md'):
9 | with open('README.md', encoding='utf-8') as readme:
10 | bdescription = readme.read()
11 | else:
12 | bdescription = "EDA Toolkit for Apache Spark based workflows"
13 |
14 | setup(
15 | name="Sparkora",
16 | version="0.0.1",
17 | author="Souvik Pratiher",
18 | author_email="spratiher9@gmail.com",
19 | description="Exploratory data analysis toolkit for Pyspark",
20 | license="GPL-3.0 License",
21 | download_url='https://github.com/Spratiher9/Sparkora/archive/refs/tags/0.0.1.tar.gz',
22 | keywords=["exploratory data analysis", "EDA", "pyspark", "preprocessing"],
23 | long_description=bdescription,
24 | long_description_content_type='text/markdown',
25 | install_requires=[
26 | "pyspark>=3.1.0",
27 | "IPython",
28 | ],
29 | classifiers=[
30 | 'Development Status :: 5 - Production/Stable',
31 | 'Intended Audience :: Developers',
32 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
33 | 'Topic :: Software Development :: Build Tools',
34 | 'Programming Language :: Python :: 3.7',
35 | 'Programming Language :: Python :: 3.8',
36 | 'Programming Language :: Python :: 3.9',
37 | 'Programming Language :: Python :: 3.10',
38 | ],
39 | packages=['Sparkora']
40 | )
41 |
--------------------------------------------------------------------------------