def setUpClass(cls): cls.model_dir = tempfile.TemporaryDirectory() cls.feature1 = Feature_1() cls.feature2 = Feature_2() cls.features = Features(cls.feature1, cls.feature2) cls.model = DNNRegressionModel( DNNRegressionModelConfig( directory=cls.model_dir.name, steps=1000, epochs=40, hidden=[50, 20, 10], predict=DefFeature("TARGET", float, 1), features=cls.features, )) # Generating data f(x1,x2) = 2*x1 + 3*x2 _n_data = 2000 _temp_data = np.random.rand(2, _n_data) cls.repos = [ Repo( "x" + str(random.random()), data={ "features": { cls.feature1.NAME: float(_temp_data[0][i]), cls.feature2.NAME: float(_temp_data[1][i]), "TARGET": 2 * _temp_data[0][i] + 3 * _temp_data[1][i], } }, ) for i in range(0, _n_data) ] cls.sources = Sources(MemorySource( MemorySourceConfig(repos=cls.repos)))
from dffml import CSVSource, Features, DefFeature from dffml.noasync import train, accuracy, predict from dffml_model_tensorflow.dnnr import DNNRegressionModel model = DNNRegressionModel( features=Features(DefFeature("Feature1", float, 1), DefFeature("Feature2", float, 1)), predict=DefFeature("TARGET", float, 1), epochs=300, steps=2000, hidden=[8, 16, 8], ) # Train the model train(model, "train.csv") # Assess accuracy (alternate way of specifying data source) print("Accuracy:", accuracy(model, CSVSource(filename="test.csv"))) # Make prediction for i, features, prediction in predict(model, { "Feature1": 0.21, "Feature2": 0.18, "TARGET": 0.84 }): features["TARGET"] = prediction["TARGET"]["value"] print(features)
from dffml import CSVSource, Features, Feature from dffml.noasync import train, accuracy, predict from dffml_model_tensorflow.dnnr import DNNRegressionModel model = DNNRegressionModel( features=Features(Feature("Feature1", float, 1), Feature("Feature2", float, 1)), predict=Feature("TARGET", float, 1), epochs=300, steps=2000, hidden=[8, 16, 8], directory="tempdir", ) # Train the model train(model, "train.csv") # Assess accuracy (alternate way of specifying data source) print("Accuracy:", accuracy(model, CSVSource(filename="test.csv"))) # Make prediction for i, features, prediction in predict(model, { "Feature1": 0.21, "Feature2": 0.18, "TARGET": 0.84 }): features["TARGET"] = prediction["TARGET"]["value"] print(features)
from dffml_model_tensorflow.dnnr import ( DNNRegressionModel, DNNRegressionModelConfig, ) training_data = CSVSource( CSVSourceConfig(filename="training.csv", readonly=True)) test_data = CSVSource(CSVSourceConfig(filename="test.csv", readonly=True)) predict_data = CSVSource(CSVSourceConfig(filename="predict.csv", readonly=True)) model = DNNRegressionModel( DNNRegressionModelConfig( features=Features( DefFeature("Years", int, 1), DefFeature("Expertise", int, 1), DefFeature("Trust", float, 1), ), predict="Salary", )) Train(model=model, sources=[training_data])() accuracy = Accuracy(model=model, sources=[test_data])() row0, row1 = PredictAll(model=model, sources=[predict_data])() print("Accuracy", accuracy) print(row0) print(row1)