Beispiel #1
0
def startjob(
        csv_file_path=r'C:\Users\57855\Desktop\2%test.csv',  #训练文件的路径
        model_file=r'C:\Users\57855\Desktop\2%.yaml',  #模型配置文件路径
        test_file=r'C:\Users\57855\Desktop\2%test_data.csv'):  #结果输出路径
    #Lugwig教程上的代码
    with open(model_file, encoding='utf-8', mode='r') as file:
        model_definition = yaml.load(file.read())
        print(model_definition)
        ludwig_model = LudwigModel(model_definition)
        train_stats = ludwig_model.train(csv_file_path,
                                         logging_level=logging_DEBUG)
        print(train_stats)
        predictions = ludwig_model.predict(test_file,
                                           logging_level=logging_DEBUG)
        print(predictions)
        ludwig_model.close()
Beispiel #2
0
        'name': 'oldpeak',
        'type': 'numerical',
        'encoder': 'rnn'
    }, {
        'name': 'slope',
        'type': 'category',
        'encoder': 'rnn'
    }, {
        'name': 'ca',
        'type': 'category',
        'encoder': 'rnn'
    }, {
        'name': 'thal',
        'type': 'category',
        'encoder': 'rnn'
    }],
    'output_features': [{
        'name': 'target',
        'type': 'binary'
    }],
    'training': {
        'epochs': 10
    }
}
model = LudwigModel(model_definition)
train_stats = model.train(data)

# obtain predictions
predictions = model.predict(data)

model.close()
Beispiel #3
0
        },
        {
            'name': 'pe',
            'type': 'category'
        },
        {
            'name': 'ane',
            'type': 'category'
        },
    ],
    'output_features': [{
        'name': 'classification',
        'type': 'binary'
    }]
}

print('creating model')
model = LudwigModel(model_definition)
print('training model')
train_stats = model.train(data_df=train_df)

#Run predictions
predictions = model.predict(data_df=X_test)
predictions["classification_predictions"] = np.where(
    predictions.iloc[:, 0] == True, 1, 0)

print(accuracy_score(Y_test, predictions.iloc[:, 0]))
print(confusion_matrix(Y_test, predictions.iloc[:, 0]))
print(classification_report(Y_test, predictions.iloc[:, 0]))

model.close()