Esempio n. 1
0
def grow_decision_tree(df_train, df_test, var_list, output_var):
    trees, accuracies = [], []
    alpha = 0

    root_node_unpruned = grow_unpruned_tree(df_train, var_list, output_var)

    cond = True
    while cond:
        root_node = copy.deepcopy(root_node_unpruned)
        prune(root_node, df_train, var_list, output_var, df_test, root_node,
              alpha)
        acc = test_accuracy(root_node, df_train, var_list, output_var, df_test)
        trees.append(root_node)
        accuracies.append(acc)
        if root_node.left == None and root_node.right == None:
            break
        alpha += 0.02

    final_model = trees[accuracies.index(max(accuracies))]

    return final_model
test_result_11_400 = functions.extract_values(
    shp=file_test11_shp,
    raster='/Volumes/ga87rif/Study Project/Result/New/A_result_09_100.tif')
np.save('/Volumes/ga87rif/Study Project/Samples/A_test_result_11_400.npy',
        test_result_11_400)
test_result_11_500 = functions.extract_values(
    shp=file_test11_shp,
    raster='/Volumes/ga87rif/Study Project/Result/New/A_result_09_100.tif')
np.save('/Volumes/ga87rif/Study Project/Samples/A_test_result_11_500.npy',
        test_result_11_500)

#-----------------------------------------------------------------------------------------------
# calculate accuracy

functions.test_accuracy(year=2009,
                        trees=100,
                        test_array=test_result_09_100,
                        gt_test_array=test09)
functions.test_accuracy(year=2009,
                        trees=200,
                        test_array=test_result_09_100,
                        gt_test_array=test09)
functions.test_accuracy(year=2009,
                        trees=300,
                        test_array=test_result_09_100,
                        gt_test_array=test09)
functions.test_accuracy(year=2009,
                        trees=400,
                        test_array=test_result_09_100,
                        gt_test_array=test09)
functions.test_accuracy(year=2009,
                        trees=500,
Esempio n. 3
0
model = models.vgg11()

# 5. Build Custom Classifier

from collections import OrderedDict

classifier = nn.Sequential(
    OrderedDict([('fc1', nn.Linear(25088, 5000)), ('relu', nn.ReLU()),
                 ('drop', nn.Dropout(p=0.5)), ('fc2', nn.Linear(5000, 3)),
                 ('output', nn.LogSoftmax(dim=1))]))
model.classifier = classifier

# 6. Loss function and gradient descent

criterion = nn.NLLLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)

# 7. model training

model = functions.train_classifier(model, train_loader, validate_loader,
                                   optimizer, criterion)

# 8. test accuracy

functions.test_accuracy(model, test_loader)

# 9. model save

model_save_path = r"C:/Users/LG/Desktop/ksb/3. CODE/model/"
filename = 'sepa_image_classifier2.pth'
functions.save_checkpoint(model, training_dataset, model_save_path, filename)
Esempio n. 4
0
from functions import test_accuracy, convert_csv_to_Q

# load a.i.
file_path = 'pickled_brain3.csv'
Q = convert_csv_to_Q(file_path)

# test
print("Begin testing.")
number_of_games_per_unit_test = 10000
test_accuracy(number_of_games_per_unit_test, Q)
print("Done testing.\n")