Mar-25-2020, 11:10 AM
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:
Many Thanks any questions please let me know.
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.