def basic_model(): """ TODO: Initialize a classifier Suggested classifiers: * SVM * K-nn * Decision Tree * Random Forrest Train a model and evaluate it You should use k-fold cross validation Return the accuracy of each fold in the scores variable """ model = None """ labels: a list with a subject-label for each feature-vector targets: the class labels features: the features """ labels, targets, features = data.get_all("features.csv") features = data.normalize(features) scores = None return scores
def basic_model(): model = RandomForestClassifier(n_estimators=100) labels, targets, features = data.get_all("features.csv") features = data.normalize(features) scores = cross_val_score(model, features, targets, cv=5) return scores
def personalized_model(): model = RandomForestClassifier(n_estimators=100) labels, targets, features = data.get_all("features.csv") logo = LeaveOneGroupOut() scores = [] for rest, user in logo.split(features, targets, groups=labels): normalized = data.normalize(features[user]) user_scores = cross_val_score(model, normalized, targets[user], cv=5) scores = scores + user_scores.tolist() return np.array(scores)
def personalized_model(): """ TODO: Initialize a classifier Train a model and evaluate it Here you will train one model per subject in the labels-list Remember to normalize the features for each subject seperately. Evaluate each model using k-fold cross validation Return the accuracy of each fold for every user in the scores variable as a numpy-array """ model = None labels, targets, features = data.get_all("features.csv") scores = None return np.array(scores)
def general_model(): """ TODO: Initialize a classifier Train a model and evaluate it Here you will use leave-one-group-out cross validation to create a general model Remember to normalize the training data set and the test data set seperately. There is a function to do this in data.py Return the accuracy of each fold in the scores variable as a numpy-array """ model = None labels, targets, features = data.get_all("features.csv") scores = None return np.array(scores)
def general_model(): model = RandomForestClassifier(n_estimators=100) labels, targets, features = data.get_all("features.csv") logo = LeaveOneGroupOut() scores = [] for train_index, test_index in logo.split(features, targets, groups=labels): features_copy = np.copy(features) X_train, X_test = data.normalize_train_test(features_copy[train_index], features_copy[test_index]) y_train, y_test = targets[train_index], targets[test_index] model.fit(X_train, y_train) user_score = model.score(X_test, y_test) scores.append(user_score) return np.array(scores)
def ask_basic_info(library): try: info = data.get_all() library_id = request.intent.slots.library.resolutions.resolutionsPerAuthority[ 0]['values'][0]['value']['id'] for library_info in info: if library_info['unit_id'] == int(library_id): email = library_info['contact_email'] answer_msg = render_template("answer-basic-info", library=library, info=library_info) break # No library matching / date matching except (KeyError, AttributeError) as e: answer_msg = render_template("error-no-match") # other errors except: answer_msg = render_template("error-other") return question(answer_msg)
# Cuda use_gpu = torch.cuda.is_available() if use_gpu: print("Using gpu") else: print('Using cpu') # embedding path emb_path = '/p300/TensorFSARNN/data/emb/glove.6B/glove.6B.100d.txt' # load data dir = '/p300/MerryUp_RE2RNN/dataset/ATIS/' train_tokens, train_tags, train_seqlen = data.load_data_ATIS(dir + 'train.json') test_tokens, test_tags, test_seqlen = data.load_data_ATIS(dir + 'test.json') # get all all_tokens, all_tags = data.get_all(train_tokens, test_tokens, train_tags, test_tags) # get max max = data.get_maxlen(all_tokens) # get dict word2idx, idx2word, tag2idx, idx2tag = data.create_dict(all_tokens, all_tags) vocab_size = len(word2idx) # vocab_size = 942 tag_size = len(tag2idx) # C = 27 # add padding train_tokens = data.add_padding(train_tokens, max) test_tokens = data.add_padding(test_tokens, max) # convert2vec train_tokens, train_tags = data.convert2vec(train_tokens, train_tags, word2idx, tag2idx) test_tokens, test_tags = data.convert2vec(test_tokens, test_tags, word2idx=word2idx, tag2idx = tag2idx) # dataset train_dataset = myDataSet(train_tokens, train_tags, train_seqlen) test_dataset = myDataSet(test_tokens, test_tags, test_seqlen)