예제 #1
0
def train():
    classfier_name = request.forms.get('classfier_name')
    classfier_type = request.forms.get('classfier_type')
    classfier_params = request.forms.get('classfier_params')
    cross_validation_type = request.forms.get('cross_validation_type')
    learning_curve_params = request.forms.get('learning_curve_params')
    train_size = request.forms.get('train_size')
    clf = classifier.configure_classifier(classfier_type,classfier_params)
    cv = classifier.configure_cross_validation(cross_validation_type,classfier_params)
    features_train, labels_train = wtf.getArrays()

    clf, train_sizes, train_scores, test_scores = classifier.train(clf,
                        train_sizes = np.linspace(.1, 1.0,train_size),
                        cv = cv,
                        params = " ",
                        features = features_train,
                        labels = labels_train )
    data = classfier_to_send(classfier_name, clf, train_sizes, train_scores, test_scores)
    post.send("http://naos-software.com/dataprocessing/rest-api","/classifiers","",data)

    return data
예제 #2
0
def train():
    callback = request.GET.get('callback')
    classifier_name = request.GET.get('classifier_name')
    classifier_id = request.GET.get('classifier_id')
    user_id = request.GET.get('user_id')
    classifier_type = request.GET.get('classifier_type')
    classifier_params = request.GET.get('classifier_params')
    cross_validation_type = request.GET.get('cross_validation_type')
    cross_validation_params = request.GET.get('cross_validation_params')
    result_test_classifiers_id = request.GET.get('result_test_classifiers_id')
    collection_id = request.GET.get('collection_id')
    vectorized_document_collection_id = request.GET.get(
        'vectorized_document_collection_id')
    train_size = request.GET.get('train_size')
    #data = classifier_to_send(user_id, classifier_name, classifier_params, "", "", 1)
    #post.send("http://localhost:8080/dataprocessing/rest-api/classifiers/",data)
    print("Params :")
    print(classifier_name)
    print(classifier_type)
    print(classifier_params)
    print(cross_validation_type)
    print(cross_validation_params)
    print(collection_id)
    print(train_size)
    clf = classifier.configure_classifier(classifier_type, classifier_params)
    #features_train, labels_train = makeTerrainData(n_points=200)
    features_train, labels_train, features_test, labels_test = makeTerrainData(
    )
    #print(features_train)
    if (cross_validation_type == 'None'):
        cross_validation_type = None

    cv = classifier.configure_cross_validation(cross_validation_type,
                                               cross_validation_params,
                                               n=len(features_train))

    print("features_train :")
    print(len(features_train))
    print("labels_train :")
    print(len(labels_train))
    clf.fit(features_train, labels_train)

    fig = classifier.train(clf,
                           train_sizes=np.linspace(.1, 1.0, train_size),
                           cv=cv,
                           params=" ",
                           features=features_train,
                           labels=labels_train)
    imgdata = StringIO()
    fig.savefig(imgdata, format='svg')
    imgdata.seek(0)  # rewind the data

    svg_dta = imgdata.getvalue()  # this is svg data
    import pickle
    s = pickle.dumps(clf)
    print("classifier dump:")
    #print(s)
    data = classifier_to_send(
        user_id=user_id,
        name=classifier_name,
        vectorizedDocumentCollectionId=vectorized_document_collection_id,
        parameter=classifier_params,
        learningCurve=svg_dta,
        content=s,
        flag=1)
    put.send("http://localhost:8080/dataprocessing/rest-api/classifiers/",
             classifier_id, data)
    pred = clf.predict(features_train)
    from sklearn.metrics import accuracy_score
    acc = accuracy_score(labels_train, pred)
    precision = precision_score(labels_train, pred)
    recall = recall_score(labels_train, pred)

    print("result_test_classifiers_id: " + result_test_classifiers_id)

    data = test_data_to_send(
        id_result_test_classifier=result_test_classifiers_id,
        user_id=user_id,
        classifierId=classifier_id,
        vectorizedDocumentCollectionId=vectorized_document_collection_id,
        parameter=" ",
        precision=precision,
        accuracy=acc,
        recall=recall)
    print(data)
    put.send(
        "http://localhost:8080/dataprocessing/rest-api/resultTestClassifiers/",
        result_test_classifiers_id, data)

    return '{0}({1})'.format(callback, {'a': 1, 'b': 2})
예제 #3
0
def train():
    callback = request.GET.get('callback')
    classifier_name = request.GET.get('classifier_name')
    classifier_id = request.GET.get('classifier_id')
    user_id = request.GET.get('user_id')
    classifier_type = request.GET.get('classifier_type')
    classifier_params = request.GET.get('classifier_params')
    cross_validation_type = request.GET.get('cross_validation_type')
    cross_validation_params = request.GET.get('cross_validation_params')
    result_test_classifiers_id = request.GET.get('result_test_classifiers_id')
    collection_id = request.GET.get('collection_id')
    vectorized_document_collection_id = request.GET.get('vectorized_document_collection_id')
    train_size = request.GET.get('train_size')
    #data = classifier_to_send(user_id, classifier_name, classifier_params, "", "", 1)
    #post.send("http://localhost:8080/dataprocessing/rest-api/classifiers/",data)
    print("Params :")
    print(classifier_name)
    print(classifier_type)
    print(classifier_params)
    print(cross_validation_type)
    print(cross_validation_params)
    print(collection_id)
    print(train_size)
    clf = classifier.configure_classifier(classifier_type,classifier_params)
    #features_train, labels_train = makeTerrainData(n_points=200)
    features_train, labels_train, features_test, labels_test = makeTerrainData()
    #print(features_train)
    if(cross_validation_type == 'None') :
            cross_validation_type = None

    cv = classifier.configure_cross_validation(cross_validation_type,cross_validation_params, n = len(features_train))
	
    print("features_train :")
    print(len(features_train))
    print("labels_train :")
    print(len(labels_train))
    clf.fit(features_train, labels_train)

    fig = classifier.train(clf,
                        train_sizes = np.linspace(.1, 1.0,train_size),
                        cv = cv,
                        params = " ",
                        features = features_train,
                        labels = labels_train )
    imgdata = StringIO()
    fig.savefig(imgdata, format='svg')
    imgdata.seek(0)  # rewind the data

    svg_dta = imgdata.getvalue()  # this is svg data
    import pickle
    s = pickle.dumps(clf)
    print("classifier dump:")
    #print(s)
    data = classifier_to_send(user_id = user_id, name = classifier_name, vectorizedDocumentCollectionId= vectorized_document_collection_id, parameter = classifier_params, learningCurve = svg_dta, content = s, flag = 1)
    put.send("http://localhost:8080/dataprocessing/rest-api/classifiers/",classifier_id, data)
    pred = clf.predict(features_train)
    from sklearn.metrics import accuracy_score
    acc = accuracy_score(labels_train, pred)
    precision = precision_score(labels_train, pred)
    recall = recall_score(labels_train, pred)

    print("result_test_classifiers_id: " + result_test_classifiers_id )
    
    data = test_data_to_send(id_result_test_classifier = result_test_classifiers_id, user_id = user_id, classifierId = classifier_id, vectorizedDocumentCollectionId = vectorized_document_collection_id, parameter = " ", precision = precision, accuracy = acc, recall = recall)
    print(data)
    put.send("http://localhost:8080/dataprocessing/rest-api/resultTestClassifiers/", result_test_classifiers_id,  data)

    return '{0}({1})'.format(callback, {'a':1, 'b':2})