Example #1
0
class FakeTestingConfig2:
    name: str = field("Name of FakeTesting2")
    num: float
    features: Features = Features(
        DefFeature("default", int, 1), DefFeature("features", int, 10)
    )
    label: str = "unlabeled"
Example #2
0
 def test_config_set(self):
     config = FakeTesting.config(
         parse_unknown(
             "--test-fake-name",
             "feedface",
             "--test-num",
             "-4.2",
             "--test-fake-label",
             "default-label",
             "--test-fake-readonly",
             "--test-files",
             "a",
             "b",
             "c",
             "--test-fake-source",
             "csv",
             "--test-source-filename",
             "file.csv",
             "--test-features",
             "Year:int:1",
             "Commits:int:10",
         ))
     self.assertEqual(config.num, -4.2)
     self.assertEqual(config.files, ["a", "b", "c"])
     self.assertEqual(config.name, "feedface")
     self.assertEqual(config.label, "default-label")
     self.assertTrue(config.readonly)
     self.assertTrue(isinstance(config.source, CSVSource))
     self.assertEqual(config.source.config.filename, "file.csv")
     self.assertEqual(
         config.features,
         Features(DefFeature("Year", int, 1),
                  DefFeature("Commits", int, 10)),
     )
Example #3
0
    async def test_predict(self):
        self.required_plugins("dffml-model-scikit")
        # Import SciKit modules
        dffml_model_scikit = importlib.import_module("dffml_model_scikit")
        # Instantiate the model
        model = dffml_model_scikit.LinearRegressionModel(
            directory=self.mktempdir(),
            predict=DefFeature("Salary", int, 1),
            features=Features(
                DefFeature("Years", int, 1),
                DefFeature("Expertise", int, 1),
                DefFeature("Trust", float, 1),
            ),
        )

        training_data = CSVSource(filename=self.train_filename)
        test_data = CSVSource(filename=self.test_filename)
        predict_data = CSVSource(filename=self.predict_filename)

        # Train the model
        await train(model, training_data)
        # Assess accuracy
        await accuracy(model, test_data)
        # Make prediction
        predictions = [
            prediction async for prediction in predict(model, predict_data)
        ]
        self.assertEqual(predictions[0][2]["Salary"]["value"], 70)
        self.assertEqual(predictions[1][2]["Salary"]["value"], 80)
Example #4
0
 def test_config_defaults(self):
     config = FakeTesting.config(
         parse_unknown(
             "--test-fake-name",
             "feedface",
             "--test-num",
             "-4.2",
             "--test-files",
             "a",
             "b",
             "c",
             "--test-source-filename",
             "file.json",
             "--test-features",
             "def:Year:int:1",
             "def:Commits:int:10",
         ))
     self.assertEqual(config.num, -4.2)
     self.assertEqual(config.files, ["a", "b", "c"])
     self.assertEqual(config.name, "feedface")
     self.assertEqual(config.label, "unlabeled")
     self.assertFalse(config.readonly)
     self.assertTrue(isinstance(config.source, JSONSource))
     self.assertEqual(config.source.config.filename, "file.json")
     self.assertEqual(
         config.features,
         Features(DefFeature("Year", int, 1),
                  DefFeature("Commits", int, 10)),
     )
Example #5
0
                    default=pathlib.Path(
                        "~", ".cache", "dffml", f"scikit-{entry_point_name}"
                    ),
                ),
            ),
            "features": (Features, field("Features to train on")),
        },
        **config_fields,
    }

    if estimator_type in unsupervised_estimators:
        dffml_config_properties["predict"] = (
            Feature,
            field(
                "Name used as meaning of prediction",
                default=DefFeature(name="cluster", dtype=str, length=1),
            ),
        )

    dffml_config = make_config_numpy(
        name + "ModelConfig", cls, properties=dffml_config_properties
    )

    dffml_cls_ctx = type(
        name + "ModelContext",
        (parentContext,),
        {"applicable_features": applicable_features_function},
    )

    dffml_cls = type(
        name + "Model",
Example #6
0
                        "dffml",
                        f"scikit-{entry_point_name}",
                    ),
                ),
            ),
            "features": (Features, field("Features to train on")),
        },
        **config_fields,
    }

    if estimator_type in unsupervised_estimators:
        dffml_config_properties["predict"] = (
            Feature,
            field(
                "field here for compability with other functions,no need to change",
                default=DefFeature(name="Prediction", dtype="str", length=10),
            ),
        )

    dffml_config = make_config_numpy(name + "ModelConfig",
                                     cls,
                                     properties=dffml_config_properties)

    dffml_cls_ctx = type(
        name + "ModelContext",
        (parentContext, ),
        {"applicable_features": applicable_features_function},
    )

    dffml_cls = type(
        name + "Model",
Example #7
0
from dffml.source.csv import CSVSource, CSVSourceConfig
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)
Example #8
0
from dffml.source.csv import CSVSource, CSVSourceConfig
from dffml_model_tensorflow.dnnr import (
    DNNRegressionModel,
    DNNRegressionModelConfig,
)

training_data = CSVSource(
    CSVSourceConfig(filename="training.csv", readwrite=False))
test_data = CSVSource(CSVSourceConfig(filename="test.csv", readwrite=False))
predict_data = CSVSource(
    CSVSourceConfig(filename="predict.csv", readwrite=False))

model = DNNRegressionModel(
    DNNRegressionModelConfig(
        features=Features(
            DefFeature("Years", int, 1),
            DefFeature("Expertise", int, 1),
            DefFeature("Trust", float, 1),
        ),
        predict=DefFeature("Salary", float, 1),
    ))

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)