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_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)