示例#1
0
async def main():
    model = LinearRegressionModel(
        features=Features(
            DefFeature("Years", int, 1),
            DefFeature("Expertise", int, 1),
            DefFeature("Trust", float, 1),
        ),
        predict=DefFeature("Salary", int, 1),
    )

    # Train the model
    await train(
        model,
        {"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},
    )

    # Assess accuracy
    print(
        "Accuracy:",
        await accuracy(
            model,
            {"Years": 4, "Expertise": 9, "Trust": 0.5, "Salary": 50},
            {"Years": 5, "Expertise": 11, "Trust": 0.6, "Salary": 60},
        ),
    )

    # Make prediction
    async for i, features, prediction in predict(
        model,
        {"Years": 6, "Expertise": 13, "Trust": 0.7},
        {"Years": 7, "Expertise": 15, "Trust": 0.8},
    ):
        features["Salary"] = prediction["Salary"]["value"]
        print(features)
示例#2
0
from dffml import Features, DefFeature
from dffml.noasync import train, accuracy, predict
from dffml_model_scikit import LinearRegressionModel

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

# Train the model
train(
    model,
    {
        "Years": 0,
        "Expertise": 1,
        "Trust": 0.1,
        "Salary": 10
    },
    {
        "Years": 1,
        "Expertise": 3,
        "Trust": 0.2,
        "Salary": 20
    },
    {
        "Years": 2,
        "Expertise": 5,
示例#3
0
文件: lr.py 项目: up1512001/dffml
from dffml import CSVSource, Features, Feature
from dffml.noasync import train, accuracy, predict
from dffml_model_scikit import LinearRegressionModel

model = LinearRegressionModel(
    features=Features(
        Feature("Years", int, 1),
        Feature("Expertise", int, 1),
        Feature("Trust", float, 1),
    ),
    predict=Feature("Salary", int, 1),
    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,
    {
        "Years": 6,
        "Expertise": 13,
        "Trust": 0.7
    },
    {
        "Years": 7,
        "Expertise": 15,
示例#4
0
async def main():
    model = LinearRegressionModel(
        features=Features(
            Feature("Years", int, 1),
            Feature("Expertise", int, 1),
            Feature("Trust", float, 1),
        ),
        predict=Feature("Salary", int, 1),
        location="tempdir",
    )

    # Train the model
    await train(
        model,
        {
            "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
        },
    )

    # Assess accuracy
    scorer = MeanSquaredErrorAccuracy()
    print(
        "Accuracy:",
        await score(
            model,
            scorer,
            Feature("Salary", int, 1),
            {
                "Years": 4,
                "Expertise": 9,
                "Trust": 0.5,
                "Salary": 50
            },
            {
                "Years": 5,
                "Expertise": 11,
                "Trust": 0.6,
                "Salary": 60
            },
        ),
    )

    # Make prediction
    async for i, features, prediction in predict(
        model,
        {
            "Years": 6,
            "Expertise": 13,
            "Trust": 0.7
        },
        {
            "Years": 7,
            "Expertise": 15,
            "Trust": 0.8
        },
    ):
        features["Salary"] = prediction["Salary"]["value"]
        print(features)