Esempio n. 1
0
        # model = models.Word2Vec.load("model6.word2vec")
        # dictionary = load_doc_hashes("temp_mapper.txt")
        # dim = len(model[model.vocab.keys()[0]])
        # d = np.zeros(shape=(10000,100))
        questions = load_thread(16,os.getcwd())
        qs = Questions(questions)
        with open("correct_questions_content.pickle","wb") as f:
            pickle.dump(qs,f)




if __name__ == "__muin__":
    with open("pickle/questions_content.pickle") as f:
            questions = pickle.load(f)
    (M,b) = train(questions.q.values(),[])
    doc_model = Doc_Model(M,b)
    with open("doc_model_content.pickle","wb") as f:
        pickle.dump(doc_model,f)
    # new_questions = merge_dicts(questions.q)
    # qs = Questions(new_questions)
    # with open("new_questions_content.pickle","wb") as f:
    #     pickle.dump(qs,f)

if __name__ == "__main__":
    rel = [line for line in open("rel4.txt")]
    hash = [line for line in open("hashes2.txt")]
    qid = [line for line in open("metadata2.txt")]
    dictionary = load_doc_hashes("doc_mapper.txt")
    model = models.Doc2Vec.load("model1.doc2vec")
    questions = load_questions(model,rel,hash,qid,dictionary)
Esempio n. 2
0
        'Triceps skin fold thickness (mm)',
        '2-Hour serum insulin (mu U/ml)',
        'Body mass index (weight in kg/(height in m)^2)',
        'Diabetes pedigree function',
        'Age (years)',
        'Class variable (0: no diabetes, 1: diabetes)']

    # Load data and perform train test split.
    print('[INFO] Loading data.')
    data = load_data(file_name, columns)
    X_train, X_test, y_train, y_test = train_test_split(data, frac=0.8, seed=5)

    # Logistic Model
    print('\n[INFO] Training logistic regression model.')
    logreg = LogReg(args.lr_logreg, args.epochs, len(X_train[0]))
    bias_logreg, weights_logreg = logreg.train(X_train, y_train)
    y_logistic = [round(logreg.predict(example)) for example in X_test]

    # Perceptron Model
    print('[INFO] Training Perceptron model.')
    perceptron = Perceptron(args.lr_perceptron, args.epochs, len(X_train[0]))
    bias_perceptron, weights_perceptron = perceptron.train(X_train, y_train)
    y_perceptron = [round(perceptron.predict(example)) for example in X_test]

    # Compare accuracies
    accuracy_logistic = get_accuracy(y_logistic, y_test)
    accuracy_perceptron = get_accuracy(y_perceptron, y_test)
    print('\n[INFO] Logistic Regression Accuracy: {:0.3f}'.format(
        accuracy_logistic))
    print('[INFO] Perceptron Accuracy: {:0.3f}'.format(accuracy_perceptron))
Esempio n. 3
0
        'Diastolic blood pressure (mm Hg)', 'Triceps skin fold thickness (mm)',
        '2-Hour serum insulin (mu U/ml)',
        'Body mass index (weight in kg/(height in m)^2)',
        'Diabetes pedigree function', 'Age (years)',
        'Class variable (0: no diabetes, 1: diabetes)'
    ]

    # Load data and perform train test split.
    print('[INFO] Loading data.')
    data = load_data(file_name, columns)
    X_train, X_test, y_train, y_test = train_test_split(data, frac=0.8, seed=5)

    # Logistic Model
    print('\n[INFO] Training logistic regression model.')
    logreg = LogReg(args.lr_logreg, args.epochs, len(X_train[0]))
    bias_logreg, weights_logreg = logreg.train(X_train, y_train, args.decay)
    y_logistic = [round(logreg.predict(example)) for example in X_test]

    # Perceptron Model
    print('[INFO] Training Perceptron model.')
    perceptron = Perceptron(args.lr_perceptron, args.epochs, len(X_train[0]))
    bias_perceptron, weights_perceptron = perceptron.train(
        X_train, y_train, args.decay)
    y_perceptron = [round(perceptron.predict(example)) for example in X_test]

    # Compare accuracies
    accuracy_logistic = get_accuracy(y_logistic, y_test)
    accuracy_perceptron = get_accuracy(y_perceptron, y_test)
    print('\n[INFO] Logistic Regression Accuracy: {:0.3f}'.format(
        accuracy_logistic))
    print('[INFO] Perceptron Accuracy: {:0.3f}'.format(accuracy_perceptron))
Esempio n. 4
0
from model_simple import model
from config_simple import *
import logreg
if __name__ == "__main__":
    logreg.train(model, dim_embed=dim_embed, class_num=class_num, learning_rate=learning_rate)

Esempio n. 5
0
    else:

        # io.mmread("R_new.mtx")
        # model = models.Word2Vec.load("model6.word2vec")
        # dictionary = load_doc_hashes("temp_mapper.txt")
        # dim = len(model[model.vocab.keys()[0]])
        # d = np.zeros(shape=(10000,100))
        questions = load_thread(16, os.getcwd())
        qs = Questions(questions)
        with open("correct_questions_content.pickle", "wb") as f:
            pickle.dump(qs, f)

if __name__ == "__muin__":
    with open("pickle/questions_content.pickle") as f:
        questions = pickle.load(f)
    (M, b) = train(questions.q.values(), [])
    doc_model = Doc_Model(M, b)
    with open("doc_model_content.pickle", "wb") as f:
        pickle.dump(doc_model, f)
    # new_questions = merge_dicts(questions.q)
    # qs = Questions(new_questions)
    # with open("new_questions_content.pickle","wb") as f:
    #     pickle.dump(qs,f)

if __name__ == "__main__":
    rel = [line for line in open("rel4.txt")]
    hash = [line for line in open("hashes2.txt")]
    qid = [line for line in open("metadata2.txt")]
    dictionary = load_doc_hashes("doc_mapper.txt")
    model = models.Doc2Vec.load("model1.doc2vec")
    questions = load_questions(model, rel, hash, qid, dictionary)
Esempio n. 6
0
from sklearn.linear_model import LogisticRegression
import dataset_mnist
import logreg
'''
Apply logistic regression with sklearn
'''


def train_sclearn(X_train, y_train, X_test, y_test):
    clf = LogisticRegression(fit_intercept=True, C=1e15)
    print('Training with sklearn:')
    clf.fit(X_train, y_train)
    print('Train set accuracy: ' + str(clf.score(X_train, y_train)))
    print('Test  set accuracy: ' + str(clf.score(X_test, y_test)))


if __name__ == '__main__':
    X_train, y_train, X_test, y_test = dataset_mnist.load_mnist_bin()

    #train_sclearn(X_train, y_train, X_test, y_test)
    logreg.train(X_train,
                 y_train,
                 X_test,
                 y_test,
                 30,
                 0.001,
                 use_intercept=True,
                 batch_size=-1)