小编pos*_*res的帖子

如何通过支持向量机中的predict()函数知道类预测的概率?

我如何知道样本的概率属于由支持向量机中的Scikit-Learn的predict()函数预测的类?

>>>print clf.predict([fv])
[5]
Run Code Online (Sandbox Code Playgroud)

有什么功能吗?

svm scikit-learn

24
推荐指数
3
解决办法
4万
查看次数

如何从Python cv2,scikit image和mahotas中读取Internet URL中的图像?

如何从Python cv2中的Internet URL读取图像?

这个Stack Overflow答案,

import cv2.cv as cv
import urllib2
from cStringIO import StringIO
import PIL.Image as pil
url="some_url"

img_file = urllib2.urlopen(url)
im = StringIO(img_file.read())
Run Code Online (Sandbox Code Playgroud)

不好,因为Python向我报告:

TypeError: object.__new__(cStringIO.StringI) is not safe, use cStringIO.StringI.__new__
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing scikit-image mahotas

22
推荐指数
3
解决办法
2万
查看次数

我在每个班级都有超过3个元素,但是我得到了这个错误:在scikit-learn中,class不能小于k = 3

这是我的目标(y):

target = [7,1,2,2,3,5,4,
      1,3,1,4,4,6,6,
      7,5,7,8,8,8,5,
      3,3,6,2,7,7,1,
      10,3,7,10,4,10,
      2,2,2,7]
Run Code Online (Sandbox Code Playgroud)

我不知道为什么在执行时:...#将数据集拆分为两个相等的部分X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.5,random_state = 0)

...
# Split the data set in two equal parts
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.5, random_state=0)

# Set the parameters by cross-validation
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
                 'C': [1, 10, 100, 1000]},
                {'kernel': ['linear'], 'C': [1, 10, 100, 1000]}]

scores = ['precision', 'recall']

for score in scores:
    print("# Tuning hyper-parameters for %s" % score)
    print()

    clf = GridSearchCV(SVC(C=1), …
Run Code Online (Sandbox Code Playgroud)

runtime-error svm scikit-learn cross-validation

15
推荐指数
1
解决办法
8928
查看次数

在scikit中结合网格搜索和交叉验证学习

为了改进支持向量机的结果,我必须使用网格搜索来搜索更好的参数和交叉验证.我不确定如何在scikit-learn中将它们结合起来.网格搜索搜索最佳参数(http://scikit-learn.org/stable/modules/grid_search.html)和交叉验证避免过度拟合(http://scikit-learn.org/dev/modules/cross_validation.html)

#GRID SEARCH
from sklearn import grid_search
parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
svr = svm.SVC()
clf = grid_search.GridSearchCV(svr, parameters)
#print(clf.fit(X, Y))

#CROSS VALIDATION
from sklearn import cross_validation
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, Y, test_size=0.4, random_state=0)
clf = svm.SVC(kernel='linear', C=1).fit(X_train, y_train)

print("crossvalidation")
print(clf.score(X_test, y_test))
clf = svm.SVC(kernel='linear', C=1)
scores = cross_validation.cross_val_score(clf, X, Y, cv=3)
print(scores )
Run Code Online (Sandbox Code Playgroud)

结果:

GridSearchCV(cv=None,
   estimator=SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0,
kernel=rbf, probability=False, shrinking=True, tol=0.001, verbose=False),
   estimator__C=1.0, estimator__cache_size=200,
   estimator__class_weight=None, estimator__coef0=0.0,
   estimator__degree=3, estimator__gamma=0.0, …
Run Code Online (Sandbox Code Playgroud)

python svm scikit-learn cross-validation

11
推荐指数
1
解决办法
1万
查看次数

如何在scikit-learn(计算机视觉)中使用我自己的数据集?

如何在scikit-learn中使用我自己的数据集?Scikit Tutorial总是以加载他的数据集为例(数字数据集,花卉数据集......)

http://scikit-learn.org/stable/datasets/index.html ie:来自sklearn.datasets import load_iris

我有我的图像,我不知道如何创建新的图像.

特别是,为了开始,我使用这个例子我发现(我使用库opencv):

img =cv2.imread('telamone.jpg')

# Convert them to grayscale
imgg =cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# SURF extraction
surf = cv2.SURF()
kp, descritors = surf.detect(imgg,None,useProvidedKeypoints = False)

# Setting up samples and responses for kNN
samples = np.array(descritors)
responses = np.arange(len(kp),dtype = np.float32)
Run Code Online (Sandbox Code Playgroud)

我想以一种有用的方式提取一组图像的特征来实现机器学习算法!

image machine-learning dataset feature-extraction scikit-learn

9
推荐指数
1
解决办法
3712
查看次数

胡时刻比较

我试图比较两个图像并使用Hu时刻来比较从这些图像中提取的轮廓:https://docs.google.com/file/d/0ByS6Z5WRz-h2WHEzNnJucDlRR2s/edithttps://docs.google.com/file/ d/0ByS6Z5WRz-h2VnZyVWRRWEFva0k/edit 第二张图像等于它旋转的第一张图像,我预期结果是相同的Humoments.他们有点不同.

幽默标志在右边(第一张图片):

[[  6.82589151e-01]
[  2.06816713e-01]
[  1.09088295e-01]
[  5.30020870e-03]
[ -5.85888607e-05]
[ -6.85171823e-04]
[ -1.13181280e-04]]
Run Code Online (Sandbox Code Playgroud)

幽默标志在右边(第二张图片):

[[  6.71793060e-01]
[  1.97521128e-01]
[  9.15619847e-02]
[  9.60179567e-03]
[ -2.44655863e-04]
[ -2.68791106e-03]
[ -1.45592441e-04]]
Run Code Online (Sandbox Code Playgroud)

在这个视频:http://www.youtube.com/watch?v=O-hCEXi3ymU 在第四minut我看着他获得完全一样的.哪里错了?

这是我的代码:

nomeimg = "Sassatelli 1984 ruotato.jpg"
#nomeimg = "Sassatelli 1984 n. 165 mod1.jpg"
img = cv2.imread(nomeimg)

gray = cv2.imread(nomeimg,0)
ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV) 
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(4,4))
imgbnbin = thresh
imgbnbin = cv2.dilate(imgbnbin, element)

#find contour
contours,hierarchy=cv2.findContours(imgbnbin,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

#Elimination small contours
Areacontours …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing contour

7
推荐指数
1
解决办法
8057
查看次数

在scikit-learn中实现K Neighbors Classifier,每个对象有3个特征

我想用scikit-learn模块实现一个KNeighborsClassifier(http://scikit-learn.org/dev/modules/generated/sklearn.neighbors.KNeighborsClassifier.html)

我从我的图像中检索坚固性,伸长率和Humoments功能.我如何准备这些数据进行培训和验证?我必须为从我的图像中检索到的每个对象创建一个包含3个特征[Hm,e,s]的列表(从1个图像中有更多对象)?

我读了这个例子(http://scikit-learn.org/dev/modules/generated/sklearn.neighbors.KNeighborsClassifier.html):

X = [[0], [1], [2], [3]]
y = [0, 0, 1, 1]
from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier(n_neighbors=3)
neigh.fit(X, y) 

print(neigh.predict([[1.1]]))
print(neigh.predict_proba([[0.9]]))
Run Code Online (Sandbox Code Playgroud)

X和y是2个特征?

samples = [[0., 0., 0.], [0., .5, 0.], [1., 1., .5]]
from sklearn.neighbors import NearestNeighbors
neigh = NearestNeighbors(n_neighbors=1)
neigh.fit(samples) 

print(neigh.kneighbors([1., 1., 1.])) 
Run Code Online (Sandbox Code Playgroud)

为什么在第一个例子中使用X和y并现在采样?

python classification machine-learning nearest-neighbor scikit-learn

6
推荐指数
1
解决办法
1万
查看次数

我如何在 pycairo 中读取 svg 数据笔划?

我有 JPG 图像和 inputvgdraw,这是一个用于图像注释的 flash 工具(http://www.mainada.net/inputdraw),我可以在其上跟踪生成 svg 数据的线条。

svg 数据示例:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 488 325"><g fill="none"   stroke-miterlimit="6" stroke-linecap="round" stroke-linejoin="round"><path d="M 307 97 l 0 -1 l -2 -1 l -10 -2 l -20 -1 l -25 5 l -22 9 l -10 9 l 0 9 l 2 12 l 16 18 l 25 11 l 25 5 l 17 -1 l 6 -4 l 3 -7 l -1 -12 l -6 -16 l -7 -13 …
Run Code Online (Sandbox Code Playgroud)

svg image-processing pycairo

6
推荐指数
1
解决办法
3596
查看次数

调整Scikit-Learn分类器的HOG功能

我正在尝试执行此代码来处理70个图像并提取直方图梯度(HOG)功能.这些传递给分类器(Scikit-Learn).

但是,会出现错误:

hog_image = hog_image_rescaled.resize((200, 200), Image.ANTIALIAS)
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,因为尝试使用单个图像正常工作.

#Hog Feature

from skimage.feature import hog
from skimage import data, color, exposure
import cv2
import matplotlib.pyplot as plt
from PIL import Image
import os
import glob
import numpy as np
from numpy import array

listagrigie = []

path = 'img/'
for infile in glob.glob( os.path.join(path, '*.jpg') ):
    print("current file is: " + infile )
    colorato = Image.open(infile)
    greyscale = colorato.convert('1')

    #hog feature
    fd, hog_image = hog(greyscale, orientations=8, …
Run Code Online (Sandbox Code Playgroud)

python image image-processing scikit-learn opencv3.0

5
推荐指数
1
解决办法
5996
查看次数

TypeError:__ init __()得到了一个意外的关键字参数'scoring'

当虚拟评分是一个参数时,这个演示代码(取自这里:http:
TypeError: __init__() got an unexpected keyword argument 'scoring'//scikit-learn.org/dev/auto_examples/grid_search_digits.html )的可能性如何(http://scikit-learn.org/dev/modules /generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search.GridSearchCV)?

from __future__ import print_function

from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.grid_search import GridSearchCV  
from sklearn.metrics import classification_report
from sklearn.svm import SVC

print(__doc__)

# Loading the Digits dataset
digits = datasets.load_digits()

# To apply an classifier on this data, we need to flatten the image, to
# turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
X = digits.images.reshape((n_samples, -1)) …
Run Code Online (Sandbox Code Playgroud)

python svm scikit-learn cross-validation

3
推荐指数
1
解决办法
4271
查看次数