Exemplo n.º 1
0
logging.info(f"TRAIN_ID {proj_id}")
logging.info(f"TRAIN_PATH {train_path}")

#
# Read dataset
#
#fields = """doc_id,hotel_name,hotel_url,street,city,state,country,zip,class,price,
#num_reviews,CLEANLINESS,ROOM,SERVICE,LOCATION,VALUE,COMFORT,overall_ratingsource""".replace("\n",'').split(",")

read_table_opts = dict(sep="\t", names=fields, index_col=False)
df = pd.read_table(train_path, **read_table_opts)

#split train/test
X_train, X_test, y_train, y_test = train_test_split(df.iloc[:, 2:],
                                                    df.iloc[:, 1],
                                                    test_size=0.2)

#
# Train the model
#
model.fit(X_train, y_train)

#model_score = model.score(X_test, y_test)
model_score = log_loss(y_test, model.predict_proba(X_test)[:, 1])

logging.info(f"model score: {model_score:.3f}")

# save the model
dump(model, "{}.joblib".format(proj_id))
Exemplo n.º 2
0
data_loader = DataLoader()
x_train, y_train, x_test, y_test, classes = data_loader.load_data()

x_train2 = (x_train / 255) - 0.5
x_test2 = (x_test / 255) - 0.5

y_train2 = keras.utils.to_categorical(y_train, NUM_CLASSES)
y_test2 = keras.utils.to_categorical(y_test, NUM_CLASSES)

model = model()

model.load_weights("weights/weights.h5")

# make test predictions

y_pred_test = model.predict_proba(x_test)

y_pred_test_classes = np.argmax(y_pred_test, axis=1)

y_pred_test_max_probas = np.max(y_pred_test, axis=1)

plt.figure(figsize=(7, 6))
plt.title('Confusion matrix', fontsize=16)
plt.imshow(confusion_matrix(y_test, y_pred_test_classes))
plt.xticks(np.arange(10), classes, rotation=45, fontsize=12)
plt.yticks(np.arange(10), classes, fontsize=12)
plt.colorbar()
plt.show()
print("Test accuracy:", accuracy_score(y_test, y_pred_test_classes))

cols = 8
Exemplo n.º 3
0
from model import model

# Calculate predictions
predictions = model.predict_proba({
    #    "rain": "heavy",
    "train": "delayed"
})

# Print predictions for each node
for node, prediction in zip(model.states, predictions):
    if isinstance(prediction, str):
        print("{}: {}".format(node.name, prediction))
    else:
        print("{}".format(node.name))
        for value, probability in prediction.parameters[0].items():
            print("    {}: {}".format(value, probability))
Exemplo n.º 4
0
from model import model

# Insert evidence that train is delayed (Observed evidence)
predictions = model.predict_proba({"train": "delayed"})

# calculate the probability for each event
for node, prediction in zip(model.states, predictions):
    if isinstance(prediction, str):
        print(f"{node.name}: {prediction}")
    else:
        print(f"{node.name}")
        for value, probability in prediction.parameters[0].items():
            print(f"\t{value}: ", end='')
            print("{:.4f}".format(probability))