Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: X has 2 features per sample; expecting 9 #1

Open
jsitha opened this issue Sep 23, 2019 · 0 comments
Open

ValueError: X has 2 features per sample; expecting 9 #1

jsitha opened this issue Sep 23, 2019 · 0 comments

Comments

@jsitha
Copy link

jsitha commented Sep 23, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant