मैं इस क्षेत्र में एक सापेक्ष नौसिखिया हूं इसलिए मैं आपकी मदद की सराहना करता हूं। मैं mnist डेटासेट के साथ खेल रहा हूँ। मैंने http://g.sweyla.com/blog/2012/mnist-numpy/ से कोड लिया लेकिन "छवियों" को 2 आयामी होने के लिए बदल दिया ताकि प्रत्येक छवि एक फीचर वेक्टर हो। तब मैंने डेटा पर पीसीए चलाया और फिर एसवीएम चलाया और स्कोर की जांच की। सबकुछ ठीक काम करता प्रतीत होता है, लेकिन मुझे निम्नलिखित चेतावनी मिल रही है और मुझे यकीन नहीं है कि क्यों।मुझे डेटा रूपांतरण चेतावनी क्यों मिल रही है?
"DataConversionWarning: A column-vector y was passed when a 1d array was expected.\
Please change the shape of y to (n_samples,), for example using ravel()."
मैंने कई चीजों की कोशिश की है लेकिन इस चेतावनी से छुटकारा पाने के लिए प्रतीत नहीं होता है। कोई सुझाव? यहाँ पूर्ण कोड है (याद आ रही indentations की अनदेखी, लगता है कि वे एक छोटे से यहाँ कोड की प्रतिलिपि में गड़बड़ हो गया):
import os, struct
from array import array as pyarray
from numpy import append, array, int8, uint8, zeros, arange
from sklearn import svm, decomposition
#from pylab import *
#from matplotlib import pyplot as plt
def load_mnist(dataset="training", digits=arange(10), path="."):
"""
Loads MNIST files into 3D numpy arrays
Adapted from: http://abel.ee.ucla.edu/cvxopt/_downloads/mnist.py
"""
if dataset == "training":
fname_img = os.path.join(path, 'train-images.idx3-ubyte')
fname_lbl = os.path.join(path, 'train-labels.idx1-ubyte')
elif dataset == "testing":
fname_img = os.path.join(path, 't10k-images.idx3-ubyte')
fname_lbl = os.path.join(path, 't10k-labels.idx1-ubyte')
else:
raise ValueError("dataset must be 'testing' or 'training'")
flbl = open(fname_lbl, 'rb')
magic_nr, size = struct.unpack(">II", flbl.read(8))
lbl = pyarray("b", flbl.read())
flbl.close()
fimg = open(fname_img, 'rb')
magic_nr, size, rows, cols = struct.unpack(">IIII", fimg.read(16))
img = pyarray("B", fimg.read())
fimg.close()
ind = [ k for k in range(size) if lbl[k] in digits ]
N = len(ind)
images = zeros((N, rows*cols), dtype=uint8)
labels = zeros((N, 1), dtype=int8)
for i in range(len(ind)):
images[i] = array(img[ ind[i]*rows*cols : (ind[i]+1)*rows*cols ])
labels[i] = lbl[ind[i]]
return images, labels
if __name__ == "__main__":
images, labels = load_mnist('training', arange(10),"path...")
pca = decomposition.PCA()
pca.fit(images)
pca.n_components = 200
images_reduced = pca.fit_transform(images)
lin_classifier = svm.LinearSVC()
lin_classifier.fit(images_reduced, labels)
images2, labels2 = load_mnist('testing', arange(10),"path...")
images2_reduced = pca.transform(images2)
score = lin_classifier.score(images2_reduced,labels2)
print score
मदद के लिए धन्यवाद!
धन्यवाद! किसी कारण से मुझे यकीन था कि समस्या "छवियों" सरणी के साथ थी। इसके बारे में भी सोचा नहीं था। मुझे मूर्ख। वैसे भी, कोई और चेतावनी नहीं। फिर से धन्यवाद :) – shmibloo