Beispiel #1
0
def predict(name, target):
    tmp = to_sample(name, target)
    svm: SVC = helper.load(name + "_model.sav")
    result = svm.predict([tmp])
    le: LabelEncoder = helper.load(name + "_label.sav")
    result = le.inverse_transform(result)
    print(result)
Beispiel #2
0
def predict(name, target):
    stopwords = helper.read_stopwords()
    features = to_sample(target, stopwords)
    classifier = helper.load(name + "_model.sav")
    result = classifier.predict([features])
    le: LabelEncoder = helper.load(name + "_label.sav")
    result = le.inverse_transform(result)
    print(result)
Beispiel #3
0
def to_sample(name, target):
    vec = helper.load(name + "_data.sav")
    feature_names = vec.get_feature_names()
    sample_source = [k + "=" + v for k, v in target.items()]
    sample_test = np.zeros(len(feature_names))

    for i in sample_source:
        if i in feature_names:
            sample_test[feature_names.index(i)] = 1.0
    return sample_test
Beispiel #4
0
def get_feature(item, name="sample04"):
    target = np.array([item])
    union: FeatureUnion = helper.load(name + "_vec.sav")
    # dvec: DictVectorizer = helper.load(name + "_dvec.sav")
    # # target = dvec.transform(target)
    # cvec: CountVectorizer = helper.load(name + "_cvec.sav")
    # # content = cvec.transform(content)
    # # TfidfTransformer().fit_transform(content)
    # union = FeatureUnion(
    #     transformer_list=[
    #         ("feature", Pipeline([
    #             ('selector', ItemSelector(1)),
    #             ("dvec", dvec)
    #         ])),
    #         ("content", Pipeline([
    #             ('selector', ItemSelector(0)),
    #             ('cvec', cvec),
    #             ('tfidf', TfidfTransformer())
    #         ]))
    #     ],
    #     transformer_weights={"feature": 1.0, "content": 1.0})
    return union.transform(target)
Beispiel #5
0
 def get_feature(self, item):
     target = np.array([item])
     union = helper.load(self.name + "_vec.sav")
     return union.transform(target)
Beispiel #6
0
 def __init__(self, name):
     self.name = name
     self.model = helper.load(name + "_model.sav")
Beispiel #7
0
def predict(set_feature, name="sample04"):
    model = helper.load(name + "_model.sav")
    return model.predict(set_feature)
Beispiel #8
0
def load_data(name, size):
    feature_list = helper.load(name + "_data.sav")
    label_list = helper.load(name + "_label.sav")
    print("FEATURE:{} / LABEL:{}".format(feature_list.shape, len(label_list)))
    return train_test_split(feature_list, label_list, test_size=size)