Python sklearn.svm.predict() Examples
The following are 6
code examples of sklearn.svm.predict().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sklearn.svm
, or try the search function
.
Example #1
Source File: audioTrainTest.py From pyAudioAnalysis with Apache License 2.0 | 6 votes |
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
Example #2
Source File: svm-bagofWords.py From TBBTCorpus with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: dataanalysis.py From aurum-datadiscovery with MIT License | 5 votes |
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
Example #4
Source File: audioTrainTest.py From pyAudioAnalysis with Apache License 2.0 | 5 votes |
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
Example #5
Source File: audioTrainTest.py From pyAudioAnalysis with Apache License 2.0 | 5 votes |
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
Example #6
Source File: audioTrainTest.py From pyAudioAnalysis with Apache License 2.0 | 4 votes |
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