udacity / ud120-projects

Starter project code for students taking Udacity ud120
1.62k stars 5.66k forks source link

Different accuracy for 32. Deploy an RBF Kernel on svm mini-project #283

Open digicom1978 opened 4 years ago

digicom1978 commented 4 years ago

Hi, I am getting different accuracy after changing kernel of svc from linear to rbf. With linear kernel, I got the same accuracy with lessons, but after applying rbf kernel, my accuracy is 0.8953356086461889 while the accuracy in lesson is 0.616040955631

Can anyone help me understand why this difference happen? and how I could correct the code?

from sklearn.svm import SVC clf = SVC(kernel='rbf')

// make data set smaller features_train = features_train[:int(len(features_train)/100)] labels_train = labels_train[:int(len(labels_train)/100)]

t0 = time() clf.fit(features_train, labels_train) print("training time:",round(time()-t0, 3), "s")

t0 = time() pred = clf.predict(features_test) print("prediction time:",round(time()-t0, 3), "s") print(sum(pred == 1))

from sklearn.metrics import accuracy_score acc = accuracy_score(pred, labels_test) print(acc)

nC3rtainity commented 4 years ago

try using features_train[:(len(features_train)/100)] instead of features_train[:int(len(features_train)/100)]

aaakashkumar commented 4 years ago

try using features_train[:(len(features_train)/100)] instead of features_train[:int(len(features_train)/100)]

Doing so throws this error: TypeError: slice indices must be integers or None or have an __index__ method

More on it over here: #207

paulgrainger85 commented 4 years ago

Docs show that in 0.22 the default for gamma changed from 'auto' to 'scale'. If you set gamma to auto, you get the lower accuracy expected by the mini quiz https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html

Similarities commented 3 years ago

same trouble here Python 3.7, seems to depend on the choice of gamma I tried different parameter for gamme: 'auto', 'scale', 1, 0.1 - none of it passed all the Quiz

-> gamma = 1, C= 10000 passes Quiz #34, but fails the following tests -> gamma = 'auto', C=10000 passes Quiz#34+ Quiz#35, does not pass Quiz#36 (and yes with respect to 0-indexed array), but passes Quiz#37

omarflight commented 3 years ago

I am running python 3.8 and it works as follow clf = svm.SVC(kernel='rbf', gamma = 'auto') this line for quiz #32 then walk through the following quizzes it will be working easily

Tiamiyu1 commented 11 months ago

I am running python 3.8 and it works as follow clf = svm.SVC(kernel='rbf', gamma = 'auto') this line for quiz #32 then walk through the following quizzes it will be working easily

This worked!