当前位置: 首页>>代码示例>>Python>>正文


Python svm.predict方法代码示例

本文整理汇总了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 
开发者ID:tyiannak,项目名称:pyAudioAnalysis,代码行数:21,代码来源:audioTrainTest.py

示例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) 
开发者ID:skashyap7,项目名称:TBBTCorpus,代码行数:10,代码来源:svm-bagofWords.py

示例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 
开发者ID:mitdbg,项目名称:aurum-datadiscovery,代码行数:7,代码来源:dataanalysis.py

示例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 
开发者ID:tyiannak,项目名称:pyAudioAnalysis,代码行数:7,代码来源:audioTrainTest.py

示例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 
开发者ID:tyiannak,项目名称:pyAudioAnalysis,代码行数:7,代码来源:audioTrainTest.py

示例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 
开发者ID:tyiannak,项目名称:pyAudioAnalysis,代码行数:44,代码来源:audioTrainTest.py


注:本文中的sklearn.svm.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。