python - Identifying a sklearn-model's classes -


the documentation on svms implies, attribute called 'classes_' exists, reveals how model represents classes internally.

i information in order interpret output functions 'predict_proba', generates probabilities of classes number of samples. hopefully, knowing (values chosen @ random, illustration)

model.classes_  >> [1, 2, 4] 

means, can assume that

model.predict_proba([[1.2312, 0.23512, 6.01234], [3.7655, 8.2353, 0.86323]])  >> [[0.032, 0.143, 0.825], [0.325, 0.143, 0.532]] 

means, probabilities translate same order classes, i.e. first set of features:

probability of class 1: 0.032 probability of class 2: 0.143 probability of class 4: 0.825 

but calling 'classes_' on svm results in error. there way information? can't imagine it's not accessible more after model trained.

edit: way build model more or less this:

from sklearn.svm import svc sklearn.grid_search import gridsearchcv sklearn.pipeline import pipeline, featureunion   pipeline = pipeline([    ('features', featureunion(transformer_list[ ... ])),    ('svm', svc(probability=true)) ]) parameters = { ... } grid_search = gridsearchcv(     pipeline,     parameters )  grid_search.fit(get_data(), get_labels()) clf = [elem elem in grid_search.estimator.steps if elem[0] == 'svm'][0][1]  print(clf) >> svc(c=1.0, cache_size=200, class_weight=none, coef0=0.0, degree=3, gamma=0.0,   kernel='rbf', max_iter=-1, probability=true, random_state=none,   shrinking=true, tol=0.001, verbose=false) print(clf.classes_) >> traceback (most recent call last):   file "path/to/script.py", line 284, in <module>   file "path/to/script.py", line 181, in re_train     print(clf.classes_) attributeerror: 'svc' object has no attribute 'classes_' 

the grid_search.estimator looking @ unfitted pipeline. classes_ attribute exists after fitting, classifier needs have seen y.

what want estimator trained using best parameter settings, grid_search.best_estimator_.

the following work:

clf = grid_search.best_estimator_.named_steps['svm'] print(clf.classes_)

[and classes_ think does].


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -