Ejemplo n.º 1
0
__author__ = 'Thong_Le'

from libs.features import extractFeature, randomSample
from libs.models import buildClassifer
from libs.config import *

# 1. Read txt data
tupleData = store.loadTxtData()

# 2. Extract features
featureTuples = extractFeature(feature_func, preprocessing_func, tupleData)
store.saveFeature(featureTuples)

# 3.1 Random Training and Testing Data
x = randomSample()
store.saveTrainingTestingData(x)

# 3.2 Load Training and Testing Data
modelData = store.loadTrainingTestingData()

# 3.3 Train model
print('=> Training model...')
clf_model = buildClassifer()
clf_model.fit(modelData['X_train'], modelData['y_train'])

y_hat = clf_model.predict(modelData['X_test'])
print(
    'Acc = ',
    sum([1 for (y1, y2) in zip(modelData['y_test'], y_hat) if (y1 == y2)]) /
    len(y_hat))
Ejemplo n.º 2
0
__author__ = 'Thong_Le'

from libs.features import extractFeature, randomSample
from libs.models import buildClassifer
from libs.config import *

# 1. Read txt data
tupleData = store.loadTxtData()

# 2. Extract features
featureTuples = extractFeature(feature_func, preprocessing_func, tupleData)
store.saveFeature(featureTuples)

# 3.1 Random Training and Testing Data
x = randomSample()
store.saveTrainingTestingData(x)

# 3.2 Load Training and Testing Data
modelData = store.loadTrainingTestingData()

# 3.3 Train model
print('=> Training model...')
clf_model = buildClassifer()
clf_model.fit(modelData['X_train'], modelData['y_train'])

y_hat = clf_model.predict(modelData['X_test'])
print('Acc = ', sum([1 for (y1, y2) in zip(modelData['y_test'], y_hat) if (y1 == y2)]) / len(y_hat))

store.saveClassifier(clf_model)

# 4. Test
Ejemplo n.º 3
0
__author__ = 'Thong_Le'

import numpy as np

from libs import store
from libs.features import extractFeature, randomSample
from libs.models import buildClassifer
from config import *

# 1. Read txt data
tupleData = store.loadTxtData()

# 2. Extract features
featureTuples = extractFeature(feature_func)
store.saveFeature(featureTuples)

accs = []

if (standard_data):
    X_train, y_train, X_test, y_test = randomSample()
    X_train, y_train, X_test, y_test = np.asarray(X_train), np.asarray(
        y_train), np.asarray(X_test), np.asarray(y_test)

    print('=> Testing model with static data...')
    for i in range(nTesting):
        # 3.3 Train model
        print('==> Training model ' + str(i) + '...')
        clf_model = buildClassifer()
        clf_model.fit(X_train, y_train)

        y_hat = clf_model.predict(X_test)
Ejemplo n.º 4
0
def exc():
    preprocessedData = store.loadPreprocessedDataCSV()

    # 3. Extract features
    featureTuples = extractFeature(preprocessedData)
    store.saveFeatureCSV(featureTuples, getFeatureNames())
def exc():
    preprocessedData = store.loadPreprocessedDataCSV()

    # 3. Extract features
    featureTuples = extractFeature(preprocessedData)
    store.saveFeatureCSV(featureTuples, feature_names)