machine learning - Python : Gaussian Process Regression and GridSearchCV -
i working on gaussian process regression python on nir spectrum data. can results gpr , optimize parameters gpr. trying use gridsearchcv optimize parameters, keep getting error , not find examples people used gridsearchcv gaussian process (from sklearn.gaussian_process). quick question if can use gridsearchcv gpr. if not, recommend use optimize parameters.
this error:
--------------------------------------------------- -# tuning hyper-parameters precision traceback (most recent call last): file "", line 1, in runfile('c:/users/hkim.n04485/desktop/python/untitled14.py', wdir='c:/users/hkim.n04485/desktop/python') file "c:\users\hkim.n04485\anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile execfile(filename, namespace) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) file "c:/users/hkim.n04485/desktop/python/untitled14.py", line 39, in gp.fit(x1, y1_glucose) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\grid_search.py", line 804, in fit return self._fit(x, y, parametergrid(self.param_grid)) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\grid_search.py", line 553, in _fit parameters in parameter_iterable file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 804, in call while self.dispatch_one_batch(iterator): file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 662, in dispatch_one_batch self._dispatch(tasks) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 570, in _dispatch job = immediatecomputebatch(batch) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 183, in init self.results = batch() file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 72, in call return [func(*args, **kwargs) func, args, kwargs in self.items] file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\cross_validation.py", line 1550, in _fit_and_score test_score = _score(estimator, x_test, y_test, scorer) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\cross_validation.py", line 1606, in _score score = scorer(estimator, x_test, y_test) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\metrics\scorer.py", line 90, in call **self._kwargs) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\metrics\classification.py", line 1203, in precision_score sample_weight=sample_weight) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\metrics\classification.py", line 956, in precision_recall_fscore_support y_type, y_true, y_pred = _check_targets(y_true, y_pred) file "c:\users\hkim.n04485\anaconda2\lib\site-packages\sklearn\metrics\classification.py", line 82, in _check_targets "".format(type_true, type_pred)) valueerror: can't handle mix of multiclass , continuous how fix this?
here code.
tuned_parameters = [{'corr':['squared_exponential'], 'theta0': [0.01, 0.2, 0.8, 1.]}, {'corr':['cubic'], 'theta0': [0.01, 0.2, 0.8, 1.]}] scores = ['precision', 'recall'] xy_line=(0,1200) score in scores: print("# tuning hyper-parameters %s" % score) print() gp = gridsearchcv(gaussianprocess(normalize=false), tuned_parameters, cv=5, scoring='%s_weighted' % score) gp.fit(x1, y1_glucose) print("best parameters set found on development set:") print() print(gp.best_params_) print() print("grid scores on development set:") print() params, mean_score, scores in gp.grid_scores_: print("%0.3f (+/-%0.03f) %r" % (mean_score, scores.std() * 2, params)) y_true, y_pred = y2_glucose, gp.predict(x2) # scatter plot (reference vs predicted ) fig, ax = plt.subplots(figsize=(11,13)) ax.scatter(y2_glucose,y_pred) ax.plot(xy_line, xy_line, 'r--') major_ticks = np.arange(-300,2000,100) minor_ticks = np.arange(0,1201,100) ax.set_xticks(minor_ticks) ax.set_yticks(major_ticks) ax.grid() plt.title('1') ax.set_xlabel('reference') ax.set_ylabel('predicted')
Comments
Post a Comment