Beispiel #1
0
def sent_class(sentence):
    id = 1  # features needs an ID passing in at moment - maybe redundant?

    f = features.features_dict(str(id), sentence)
    fseries = features.features_series(f)
    width = len(fseries)
    fseries = fseries[
        1:width -
        1]  # All but the first and last item (strip ID and null class off)

    # Get a classification prediction from the Model, based on supplied features
    sentence_class = loaded_model.predict([fseries])[0].strip()

    return sentence_class
Beispiel #2
0
def sentenceForestClass(sentence):
    with open(MODEL_LOC, 'rb') as f:
        rf = pickle.load(f, encoding='latin1')

    id = hashtext(
        sentence
    )  #features needs an ID passing in at moment - maybe redundant?
    fseries = features.features_series(features.features_dict(id, sentence))
    width = len(fseries)
    fseries = fseries[
        1:width -
        1]  #All but the first and last item (strip ID and null class off)

    #Get a classification prediction from the Model, based on supplied features
    sentenceClass = rf.predict([fseries])[0].strip()

    return sentenceClass
Beispiel #3
0
def sentence_rf_class(sentence):
    """
    Pass in a sentence, with unique ID and pass back a classification code
    Use a pre-built Random Forest model to determine classification based on
    features extracted from the sentence.  
    """
    # Load a pre-built Random Forest Model
    with open(RF_MODEL_LOCATION, 'rb') as f:
        rf = pickle.load(f)
    
    id = hashtext(sentence)  #features needs an ID passing in at moment - maybe redundant?
    fseries = features.features_series(features.features_dict(id,sentence))
    width = len(fseries)
    fseries = fseries[1:width-1]  #All but the first and last item (strip ID and null class off)
    
    #Get a classification prediction from the Model, based on supplied features
    sentence_class = rf.predict([fseries])[0].strip()
    
    return sentence_class