-
-
Save pdxjohnny/79fcefd5b5b0cb91a3b4e79fa3046e35 to your computer and use it in GitHub Desktop.
DFFML Issue 831. Need to make it so that config properties can be saved / loaded from file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from dffml import * | |
from dffml.noasync import train, accuracy | |
SLRModel = Model.load("slr") | |
LinearRegressionModel = Model.load("scikitlr") | |
model1 = SLRModel( | |
features=Features(Feature("Years", int, 1)), | |
predict=Feature("Salary", int, 1), | |
directory="slr-model", | |
) | |
model2 = LinearRegressionModel( | |
features=Features(Feature("Years", int, 1)), | |
predict=Feature("Salary", int, 1), | |
directory="scikitlr", | |
) | |
from pprint import pprint | |
pprint(export(model1.config)) | |
pprint(export(model2.config)) | |
class ExampleLoadable(Model): | |
async def __aexit__(self, exc_type, exc_value, traceback): | |
await super().__aexit__(exc_type, exc_value, traceback) | |
(self.config.directory / "a.json").write_text( | |
json.dumps(export(self.config)) | |
) | |
@classmethod | |
def a(cls, directory): | |
return cls( | |
**{ | |
**json.loads((directory / "a.json").read_text()), | |
**{"directory": directory}, | |
} | |
) | |
train( | |
model1, | |
{"Years": 0, "Expertise": 1, "Trust": 0.1, "Salary": 10}, | |
{"Years": 1, "Expertise": 3, "Trust": 0.2, "Salary": 20}, | |
{"Years": 2, "Expertise": 5, "Trust": 0.3, "Salary": 30}, | |
{"Years": 3, "Expertise": 7, "Trust": 0.4, "Salary": 40}, | |
) | |
print( | |
"Accuracy:", | |
accuracy( | |
ExampleLoadable.a(model1.config.directory), | |
{"Years": 4, "Expertise": 9, "Trust": 0.5, "Salary": 50}, | |
{"Years": 5, "Expertise": 11, "Trust": 0.6, "Salary": 60}, | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment