def validation(fold_cnt, data, k, distance_func): accuracies = [] for fold in range(fold_cnt): train, test = get_k_fold(fold_cnt, fold, data) train_x, train_y = split(train) test_x, test_y = split(test) accuracy = calculate_accuracy( kNN(train_x, train_y, test_x, k, distance_func), test_y) accuracies.append(accuracy) return accuracies
def train_and_test(learning_rate, epoch_cnt, tao, train, test, cls): train_features, train_answers = split(train) train_answers = answers_for_class(train_answers, cls) test_features, test_answers = split(test) test_answers = answers_for_class(test_answers, cls) feature_cnt = len(train_features[0]) model = Adagrad(learning_rate=learning_rate, epoch_cnt=epoch_cnt, tao=tao, n=feature_cnt) model.train(train_features, train_answers) model_answers = answer(model.predict(test_features)) accuracy = calculate_accuracy(model_answers, test_answers) return accuracy
import reader import sys try: file = open('filename.txt') inputfile = file.readline() file.close() except IOError as e: print("No input file existing!") inputfile = input("Name of inputfile: ") file = open("filename.txt", "w") file.write(inputfile) list = reader.split(inputfile) print(list[0])