예제 #1
0
from dffml import CSVSource, Features, Feature
from dffml.noasync import train, accuracy, predict
from dffml_model_scratch.logisticregression import LogisticRegression

model = LogisticRegression(
    features=Features(Feature("f1", float, 1)),
    predict=Feature("ans", int, 1),
)

# Train the model
train(model, "dataset.csv")

# Assess accuracy (alternate way of specifying data source)
print("Accuracy:", accuracy(model, CSVSource(filename="dataset.csv")))

# Make prediction
for i, features, prediction in predict(model, {"f1": 0.8, "ans": 0}):
    features["ans"] = prediction["ans"]["value"]
    print(features)
예제 #2
0
파일: ner_model.py 프로젝트: sbs2001/dffml
from dffml import CSVSource, DefFeature
from dffml.noasync import train, accuracy, predict
from dffml_model_transformers.ner.ner_model import NERModel

model = NERModel(
    sid=DefFeature("SentenceId", int, 1),
    words=DefFeature("Words", str, 1),
    predict=DefFeature("Tag", str, 1),
    model_architecture_type="distilbert",
    model_name_or_path="distilbert-base-cased",
    epochs=1,
    no_cuda=True,
)

# Train the model
train(model, "train.csv")

# Assess accuracy (alternate way of specifying data source)
print("Accuracy:", accuracy(model, CSVSource(filename="train.csv")))

# Make prediction
for i, features, prediction in predict(
    model,
    {"SentenceID": 1, "Words": "DFFML models can do NER",},
    {"SentenceID": 2, "Words": "DFFML models can do regression",},
):
    features["Tag"] = prediction["Tag"]["value"]
    print(features)
예제 #3
0
from dffml import CSVSource, Features, Feature
from dffml.noasync import train, score, predict
from dffml.accuracy import MeanSquaredErrorAccuracy
from dffml_model_scratch.logisticregression import LogisticRegression

model = LogisticRegression(
    features=Features(Feature("f1", float, 1)),
    predict=Feature("ans", int, 1),
    location="tempdir",
)

# Train the model
train(model, "dataset.csv")

# Assess accuracy (alternate way of specifying data source)
scorer = MeanSquaredErrorAccuracy()
print(
    "Accuracy:",
    score(
        model,
        scorer,
        Feature("ans", int, 1),
        CSVSource(filename="dataset.csv"),
    ),
)

# Make prediction
for i, features, prediction in predict(model, {"f1": 0.8, "ans": 0}):
    features["ans"] = prediction["ans"]["value"]
    print(features)
예제 #4
0
        DefFeature("SepalWidth", float, 1),
        DefFeature("PetalLength", float, 1),
        DefFeature("PetalWidth", float, 1),
    ),
    predict=DefFeature("classification", int, 1),
    epochs=3000,
    steps=20000,
    classifications=[0, 1, 2],
    clstype=int,
)

# Train the model
train(model, "iris_training.csv")

# Assess accuracy (alternate way of specifying data source)
print("Accuracy:", accuracy(model, CSVSource(filename="iris_test.csv")))

# Make prediction
for i, features, prediction in predict(
        model,
    {
        "PetalLength": 4.2,
        "PetalWidth": 1.5,
        "SepalLength": 5.9,
        "SepalWidth": 3.0,
    },
    {
        "PetalLength": 5.4,
        "PetalWidth": 2.1,
        "SepalLength": 6.9,
        "SepalWidth": 3.1,
예제 #5
0
    predict=Feature("Salary", int, 1),
    location="tempdir",
)

# Train the model
train(model, "train.csv")

# Assess accuracy (alternate way of specifying data source)
scorer = MeanSquaredErrorAccuracy()
print(
    "Accuracy:",
    score(
        model,
        scorer,
        Feature("Salary", int, 1),
        CSVSource(filename="test.csv"),
    ),
)

# Make prediction
for i, features, prediction in predict(
        model,
    {
        "Years": 6,
        "Expertise": 13,
        "Trust": 0.7
    },
    {
        "Years": 7,
        "Expertise": 15,
        "Trust": 0.8
예제 #6
0
    clstype=int,
    location="tempdir",
)

# Train the model
train(model, "iris_training.csv")

# Assess accuracy (alternate way of specifying data source)
scorer = ClassificationAccuracy()
print(
    "Accuracy:",
    score(
        model,
        scorer,
        Feature("classification", int, 1),
        CSVSource(filename="iris_test.csv"),
    ),
)

# Make prediction
for i, features, prediction in predict(
        model,
    {
        "PetalLength": 4.2,
        "PetalWidth": 1.5,
        "SepalLength": 5.9,
        "SepalWidth": 3.0,
    },
    {
        "PetalLength": 5.4,
        "PetalWidth": 2.1,