Bottom Page

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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  ValueError: Found input variables AhmadMWaddah 3 347 Mar-03-2020, 10:19 PM
Last Post: AhmadMWaddah
  ValueError: X has 231 features per sample; expecting 1228 anhnguyen 3 391 Feb-06-2020, 06:08 PM
Last Post: anhnguyen
  ValueError: Found input variables with inconsistent numbers of samples: [5, 6] bongielondy 4 3,592 Nov-09-2019, 10:57 AM
Last Post: bongielondy
  ValueError: Input contains infinity or a value too large for dtype('float64') Rabah_r 1 5,113 Apr-06-2019, 11:08 AM
Last Post: scidam
  ValueError: could not broadcast input array from shape (75) into shape (25) route2sabya 0 2,746 Mar-14-2019, 01:14 PM
Last Post: route2sabya
  ValueError: Found input variables with inconsistent numbers of samples: [0, 3] ayaz786amd 2 5,572 Nov-27-2018, 07:12 AM
Last Post: ayaz786amd

Forum Jump:


Users browsing this thread: 1 Guest(s)