本文整理汇总了Python中sklearn.svm.predict方法的典型用法代码示例。如果您正苦于以下问题:Python svm.predict方法的具体用法?Python svm.predict怎么用?Python svm.predict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.svm
的用法示例。
在下文中一共展示了svm.predict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: regression_wrapper
# 需要导入模块: from sklearn import svm [as 别名]
# 或者: from sklearn.svm import predict [as 别名]
def regression_wrapper(model, model_type, test_sample):
"""
This function is used as a wrapper to pattern classification.
ARGUMENTS:
- model: regression model
- model_type: "svm" or "knn" (TODO)
- test_sample: a feature vector (np array)
RETURNS:
- R: regression result (estimated value)
EXAMPLE (for some audio signal stored in array x):
TODO
"""
if model_type == "svm" or model_type == "randomforest" or \
model_type == "svm_rbf":
return model.predict(test_sample.reshape(1,-1))[0]
# elif classifier_type == "knn":
# TODO
示例2: predict
# 需要导入模块: from sklearn import svm [as 别名]
# 或者: from sklearn.svm import predict [as 别名]
def predict(self):
vec = TfidfVectorizer(min_df=3,lowercase=True, sublinear_tf=True, use_idf=True,vocabulary=list(set(self.vocab)))
train_vector = vec.fit_transform(self.train_data)
print("Generating model")
self.svm_classifier.fit(train_vector,self.train_labels)
test_vector = vec.transform(self.test_data)
print("Classifying Data")
self.classification = self.svm_classifier.predict(test_vector)
示例3: compare_num_columns_dist_odsvm
# 需要导入模块: from sklearn import svm [as 别名]
# 或者: from sklearn.svm import predict [as 别名]
def compare_num_columns_dist_odsvm(svm, columnBdata):
Xnumpy = np.asarray(columnBdata)
X = Xnumpy.reshape(-1, 1)
prediction_vector = svm.predict(X)
return prediction_vector
示例4: train_svm_regression
# 需要导入模块: from sklearn import svm [as 别名]
# 或者: from sklearn.svm import predict [as 别名]
def train_svm_regression(features, labels, c_param, kernel='linear'):
svm = sklearn.svm.SVR(C=c_param, kernel=kernel)
svm.fit(features, labels)
train_err = np.mean(np.abs(svm.predict(features) - labels))
return svm, train_err
示例5: train_random_forest_regression
# 需要导入模块: from sklearn import svm [as 别名]
# 或者: from sklearn.svm import predict [as 别名]
def train_random_forest_regression(features, labels, n_estimators):
rf = sklearn.ensemble.RandomForestRegressor(n_estimators=n_estimators)
rf.fit(features, labels)
train_err = np.mean(np.abs(rf.predict(features) - labels))
return rf, train_err
示例6: classifier_wrapper
# 需要导入模块: from sklearn import svm [as 别名]
# 或者: from sklearn.svm import predict [as 别名]
def classifier_wrapper(classifier, classifier_type, test_sample):
"""
This function is used as a wrapper to pattern classification.
ARGUMENTS:
- classifier: a classifier object of type sklearn.svm.SVC or
kNN (defined in this library) or sklearn.ensemble.
RandomForestClassifier or sklearn.ensemble.
GradientBoostingClassifier or
sklearn.ensemble.ExtraTreesClassifier
- classifier_type: "svm" or "knn" or "randomforests" or
"gradientboosting" or "extratrees"
- test_sample: a feature vector (np array)
RETURNS:
- R: class ID
- P: probability estimate
EXAMPLE (for some audio signal stored in array x):
import audioFeatureExtraction as aF
import audioTrainTest as aT
# load the classifier (here SVM, for kNN use load_model_knn instead):
[classifier, MEAN, STD, classNames, mt_win, mt_step, st_win, st_step] =
aT.load_model(model_name)
# mid-term feature extraction:
[mt_features, _, _] = aF.mtFeatureExtraction(x, Fs, mt_win * Fs,
mt_step * Fs, round(Fs*st_win), round(Fs*st_step));
# feature normalization:
curFV = (mt_features[:, i] - MEAN) / STD;
# classification
[Result, P] = classifierWrapper(classifier, model_type, curFV)
"""
class_id = -1
probability = -1
if classifier_type == "knn":
class_id, probability = classifier.classify(test_sample)
elif classifier_type == "svm" or \
classifier_type == "randomforest" or \
classifier_type == "gradientboosting" or \
classifier_type == "extratrees" or \
classifier_type == "svm_rbf":
class_id = classifier.predict(test_sample.reshape(1, -1))[0]
probability = classifier.predict_proba(test_sample.reshape(1, -1))[0]
return class_id, probability