Python Forum
ValueError: Found input variables with inconsistent numbers of sample
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: Found input variables with inconsistent numbers of sample
#1
Dear all,

I am new to Python and I am trying to complete a piece of coursework that involves Support Vector Machines, Principal Component Analysis and Cost-Support Vector Classifiers.

Firstly I have made a scatter plot from two sets of data that were provided.

I have normalised the data and believed i have split the data into smaller datasets using train_test_spilt.

The issue occurs when I am using the C-SVC SVM to achieve the highest classification rate of the data I have collected from the scatter plot, by imputing two values in the parameters C(cost) and γ(gamma).

The code is as follows:
svc1 = SVC(kernel ='rbf', class_weight='balanced', C=50, gamma=0.1)
model1 = svc1.fit(scaled_tester, Sytrain)

"""The fitted model should be validated on the scaled validation set. """
vyfit1 = model1.predict(scaled_valX)

"""Performance measurements"""
from sklearn import metrics 
print('Accuracy:', metrics.accuracy_score(vtest, vyfit1))

from sklearn.metrics import classification_report
print(classification_report(vtest, vyfit1,
                            target_names=faces.target_names))
The error message is as follows:
Error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-82-9a74f54d417b> in <module> 1 svc1 = SVC(kernel ='rbf', class_weight='balanced', C=50, gamma=0.1) ----> 2 model1 = svc1.fit(scaled_tester, Sytrain) 3 4 """The fitted model should be validated on the scaled validation set. """ 5 vyfit1 = model1.predict(scaled_valX) /opt/anaconda3/lib/python3.7/site-packages/sklearn/svm/_base.py in fit(self, X, y, sample_weight) 146 X, y = check_X_y(X, y, dtype=np.float64, 147 order='C', accept_sparse='csr', --> 148 accept_large_sparse=False) 149 y = self._validate_targets(y) 150 /opt/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator) 763 y = y.astype(np.float64) 764 --> 765 check_consistent_length(X, y) 766 767 return X, y /opt/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in check_consistent_length(*arrays) 210 if len(uniques) > 1: 211 raise ValueError("Found input variables with inconsistent numbers of" --> 212 " samples: %r" % [int(l) for l in lengths]) 213 214 ValueError: Found input variables with inconsistent numbers of samples: [100, 300]
Is there anyone who is able to understand this error message and tell me where it is going wrong?

Many Thanks any questions please let me know.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Inconsistent sorting with the .sort_values() function devansing 4 2,745 Jun-28-2022, 06:12 PM
Last Post: deanhystad
  ValueError: Found input variables with inconsistent numbers of samples: [5, 6] bongielondy 6 29,927 Jun-28-2021, 05:23 AM
Last Post: ricslato
  ValueError: X has 231 features per sample; expecting 1228 anhnguyen 4 12,778 Oct-09-2020, 03:13 AM
Last Post: maxalegre
  ValueError: Found array with 0 samples marcellam 1 6,136 Apr-22-2020, 04:12 PM
Last Post: jefsummers
  ValueError: Found input variables AhmadMWaddah 3 4,377 Mar-03-2020, 10:19 PM
Last Post: AhmadMWaddah
  ValueError: Input contains infinity or a value too large for dtype('float64') Rabah_r 1 13,572 Apr-06-2019, 11:08 AM
Last Post: scidam
  ValueError: could not broadcast input array from shape (75) into shape (25) route2sabya 0 6,893 Mar-14-2019, 01:14 PM
Last Post: route2sabya
  ValueError: Found input variables with inconsistent numbers of samples: [0, 3] ayaz786amd 2 10,046 Nov-27-2018, 07:12 AM
Last Post: ayaz786amd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020