Machine-Learning icon indicating copy to clipboard operation
Machine-Learning copied to clipboard

ValueError: X has 2 features per sample; expecting 9

Open jsitha opened this issue 4 years ago • 0 comments

1.Supervised Learning/2.Classification/5.Logistic Regression/Breast Cancer Coimbra Dataset (UCI) prediction.ipynb

Visualising the Test set results

from matplotlib.colors import ListedColormap X_set, y_set = X_test, y_test X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) plt.contourf(X1, X2, LG.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), alpha = 0.75, cmap = ListedColormap(('red', 'green'))) plt.xlim(X1.min(), X1.max()) plt.ylim(X2.min(), X2.max()) for i, j in enumerate(np.unique(y_set)): plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j) plt.title('Logistic Regression (Test set)') plt.xlabel('Distance') plt.ylabel('Cities') plt.legend() plt.show()


ValueError Traceback (most recent call last) in 4 X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 5 np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) ----> 6 plt.contourf(X1, X2, LG.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 7 alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 8 plt.xlim(X1.min(), X1.max())

~\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in predict(self, X) 279 Predicted class label per sample. 280 """ --> 281 scores = self.decision_function(X) 282 if len(scores.shape) == 1: 283 indices = (scores > 0).astype(np.int)

~\Anaconda3\lib\site-packages\sklearn\linear_model\base.py in decision_function(self, X) 260 if X.shape[1] != n_features: 261 raise ValueError("X has %d features per sample; expecting %d" --> 262 % (X.shape[1], n_features)) 263 264 scores = safe_sparse_dot(X, self.coef_.T,

ValueError: X has 2 features per sample; expecting 9

jsitha avatar Sep 23 '19 10:09 jsitha