Ich lerne Cross-Validierung-Grid-Suche und stieß auf diese youtube playlist und das Tutorial wurde auch auf die github als Ipython-Notebook hochgeladen. Ich versuche, die Codes in der Suche nach mehreren Parametern gleichzeitig Abschnitt zu erstellen, aber statt knn benutze ich SVM Regression. Dies ist mein CodeScikit-learn Grid Suche mit SVM Regression
from sklearn.datasets import load_iris
from sklearn import svm
from sklearn.grid_search import GridSearchCV
import matplotlib.pyplot as plt
import numpy as np
iris = load_iris()
X = iris.data
y = iris.target
k=['rbf', 'linear','poly','sigmoid','precomputed']
c= range(1,100)
g=np.arange(1e-4,1e-2,0.0001)
g=g.tolist()
param_grid=dict(kernel=k, C=c, gamma=g)
print param_grid
svr=svm.SVC()
grid = GridSearchCV(svr, param_grid, cv=5,scoring='accuracy')
grid.fit(X, y)
print()
print("Grid scores on development set:")
print()
print grid.grid_scores_
print("Best parameters set found on development set:")
print()
print(grid.best_params_)
print("Grid best score:")
print()
print (grid.best_score_)
# create a list of the mean scores only
grid_mean_scores = [result.mean_validation_score for result in grid.grid_scores_]
print grid_mean_scores
Aber seine diesem Fehler geben
raise ValueError("X should be a square kernel matrix") ValueError: X should be a square kernel matrix
Bei der Meldung eines Python-Fehler, den Sie immer die volle Python Zurückverfolgungs zitieren sollte es gibt Informationen darüber, wo die Ausnahme ausgelöst wurde. – ogrisel