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)
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)
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
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)
def get_feature(self, item): target = np.array([item]) union = helper.load(self.name + "_vec.sav") return union.transform(target)
def __init__(self, name): self.name = name self.model = helper.load(name + "_model.sav")
def predict(set_feature, name="sample04"): model = helper.load(name + "_model.sav") return model.predict(set_feature)
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)