Home > other >  Adjust the threshold for a specific error, precision and recall rate is not calculated fraction meth
Adjust the threshold for a specific error, precision and recall rate is not calculated fraction meth

Time:09-19

 
The import scipy. IO as the sio
Matfn='./data/mnist - the original mat '
Data=https://bbs.csdn.net/topics/sio.loadmat (matfn)
X=np. Rot90 (data [' data '])
Y=np. Rot90 (data [' label '])
X_train X_test, y_train, y_test=X [: 60000], X [60000:], [: 60000] Y, Y/60000:
(y_train y_train_9===9)
(y_test y_test_9===9)


The from sklearn. Linear_model import SGDClassifier
SGD=SGDClassifier (random_state=315)
SGD. Fit (X_train y_train_9)
Print (SGD. Predict ([X [12814], [1287]] X))


The from sklearn. Model_selection import cross_val_predict
Y_scores=cross_val_predict (SGD, X_train y_train_9, CV=3)
# y_scores=cross_val_predict (SGD, X_train y_train_9, CV=3, method='decision_function')
Print (y_scores)




Run 1:
 y_scores=cross_val_predict (SGD, X_train y_train_9, CV=3) 

Results: [True True False False False True...]

Run 2:
 y_scores=cross_val_predict (SGD, X_train y_train_9, CV=3, method='decision_function') 

Run error:
 ValueError Traceback (most recent call last) 

17 the from sklearn. Model_selection import cross_val_predict
18 # y_scores=cross_val_predict (SGD, X_train y_train_9, CV=3)
---> 19 y_scores=cross_val_predict (SGD, X_train y_train_9, CV=3, method='decision_function')
20 print (y_scores)
21

D: \ anaconda3 \ lib \ site - packages \ sklearn \ model_selection \ _validation py in cross_val_predict (estimator, X, y, groups, CV, n_jobs, verbose, fit_params, pre_dispatch, method)
753 prediction_blocks=the parallel (of (_fit_and_predict) (
754 clone (estimator), X, y, train, test, verbose, fit_params, method)
- & gt; 755 for train and test the in CV. The split (X, y, groups))
756
757 # Concatenate the predictions

D: \ anaconda3 \ lib \ site - packages \ joblib \ parallel py in __call__ (self, iterable)
1002 # remaining jobs.
1003 self. _iterating=False
-> 1004 if self. Dispatch_one_batch (iterator) :
1005 self. _iterating=self. _original_iterator is not None
1006

D: \ anaconda3 \ lib \ site - packages \ joblib \ parallel py in dispatch_one_batch (self, iterator)
833 return False
834 else:
- & gt; 835 self. _dispatch (tasks)
836 return True
837

D: \ anaconda3 \ lib \ site - packages \ joblib \ parallel py in _dispatch (self, batch)
752 with the self. _lock:
753 job_idx=len (self _jobs)
- & gt; 754 job=self. _backend. Apply_async batch, the callback=(cb)
755 # A job can complete so quickly than its callback is
756 # called before we get here, causing the self. The _jobs to

D: \ anaconda3 \ lib \ site - packages \ joblib \ _parallel_backends py in apply_async (self, func, callback)
207 def apply_async (self, func, callback=None) :
208 ", "" the Schedule a func to be run" ""
- & gt; 209 the result=ImmediateResult (func)
If the callback: 210
211 the callback (result)

D: \ anaconda3 \ lib \ site - packages \ joblib \ _parallel_backends py in __init__ (self, batch)
588 # Don 't delay the application, to get keeping the input
589 # the arguments in the memory
- & gt; 590 self. Results=batch ()
591
592 def get (self) :

D: \ anaconda3 \ lib \ site - packages \ joblib \ parallel py in __call__ (self)
254 with parallel_backend (self _backend, n_jobs=self. _n_jobs) :
255 return [func (* args, * * kwargs)
- & gt; 256 for func, args, kwargs in self. Items]
257
258 def __len__ (self) :

D: \ anaconda3 \ lib \ site - packages \ joblib \ parallel py in & lt; Listcomp> (. 0)
254 with parallel_backend (self _backend, n_jobs=self. _n_jobs) :
255 return [func (* args, * * kwargs)
- & gt; 256 for func, args, kwargs in self. Items]
257
258 def __len__ (self) :

D: \ anaconda3 \ lib \ site - packages \ sklearn \ model_selection \ _validation py in _fit_and_predict (estimator, X, y, train, test, verbose, fit_params, method)
852 n_classes=len (set) (y) if both dim==1 y.n else y.s hape [1]
853 predictions=_enforce_prediction_order (
- & gt; 854 estimator. Classes_, predictions, n_classes, method)
The return of 855 predictions, the test
856

D: \ anaconda3 \ lib \ site - packages \ sklearn \ model_selection \ _validation py in _enforce_prediction_order (classes, predictions, n_classes, method)
898 'is not supported for decision_function'
899 'with imbalanced folds. {}'. The format (
- & gt; nullnullnullnullnullnull
  • Related