ageron / ageron/handson-ml

Questions to Chapter 2

Abierto
#470 15 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Jupyter Notebook
Estrellas
25.6k
Forks
12.7k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hi Aurelien,

I have some questions concerning the `GridsearchCV` and `RandomsearchCV`. Firstly, concerning the `RandomsearchCV`. what do the `scipy.stats.reciprocal` and `scipy.stats.expon` do exactly?. Why is important to specify an `n_iter` ? what does `n_jobs` do?
secondly, what could be possible reasons for my `Gridsearch` running for a very long while?
Thirdly, what roles do this backend play because i ran my `Gridsearch` with `C` having values of up to 300,000 and i had an error concerning the backend. How could this be solved?
1)The code below just keeps running :

```python
processed = full_pipeline.fit_transform(practice_set)

#training model
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
svm_reg = SVR(gamma='auto')
predictor = svm_reg.fit(processed,practice_set_labels)
predictions = svm_reg.predict(processed)
mean_squared_error = mean_squared_error(y_true=practice_set_labels,y_pred=predictions)
rmse = np.sqrt(mean_squared_error)

#cross validation
#score = cross_val_score(svm_reg,processed,practice_set_labels,scoring='neg_mean_squared_error',cv=10)
#cv_score = np.sqrt(-score)

def display(score):
print('scores\n',score)
print(score.mean())
print(score.std())
params = [{'kernel':['linear','rbf'],'C':[1.,3.,30.,100.]}]
grid_search = GridSearchCV(svm_reg,param_grid=params,scoring='neg_mean_squared_error',cv=5)
grid_search.fit(processed,practice_set_labels)
print(grid_search.best_score_)
```

2)Running this one which is identical to that of the Jupyter notebook:

```python
processed = full_pipeline.fit_transform(practice_set)

#training model
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
svm_reg = SVR(gamma='auto')
predictor = svm_reg.fit(processed,practice_set_labels)
predictions = svm_reg.predict(processed)
mean_squared_error = mean_squared_error(y_true=practice_set_labels,y_pred=predictions)
rmse = np.sqrt(mean_squared_error)

#cross validation
#score = cross_val_score(svm_reg,processed,practice_set_labels,scoring='neg_mean_squared_error',cv=10)
#cv_score = np.sqrt(-score)

def display(score):
print('scores\n',score)
print(score.mean())
print(score.std())

param_grid = [
{'kernel': ['linear'], 'C': [10., 30., 100., 300., 1000., 3000., 10000., 30000.0]},
{'kernel': ['rbf'], 'C': [1.0, 3.0, 10., 30., 100., 300., 1000.0],
'gamma': [0.01, 0.03, 0.1, 0.3, 1.0, 3.0]},
]

svm_reg = SVR()
grid_search = GridSearchCV(svm_reg, param_grid, cv=5, scoring='neg_mean_squared_error', verbose=2, n_jobs=4)
grid_search.fit(processed, practice_set_labels)
```

ERROR MESSAGE:

```
[Parallel(n_jobs=4)]: Using backend LokyBackend with 4 concurrent workers.
exception calling callback for
joblib.externals.loky.process_executor._RemoteTraceback:
'''
Traceback (most recent call last):
File "C:\Users\fritz\AppData\Local\Programs\Python\Python37\lib\multiprocessing\queues.py", line 109, in get
self._sem.release()
OSError: [WinError 6] Das Handle ist ungültig

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "C:\Users\fritz\AppData\Local\Programs\Python\Python37\lib\multiprocessing\queues.py", line 111, in get
self._rlock.release()
OSError: [WinError 6] Das Handle ist ungültig
'''

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 309, in __call__
self.parallel.dispatch_next()
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 731, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 759, in dispatch_one_batch
self._dispatch(tasks)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 716, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\_parallel_backends.py", line 510, in apply_async
future = self._workers.submit(SafeFunction(func))
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 151, in submit
fn, *args, **kwargs)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\process_executor.py", line 1022, in submit
raise self._flags.broken
joblib.externals.loky.process_executor.BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.
FEHLER: Der Prozess "37772" wurde nicht gefunden.
FEHLER: Der Prozess "32116" wurde nicht gefunden.
FEHLER: Der Prozess "37652" wurde nicht gefunden.
FEHLER: Der Prozess "7540" wurde nicht gefunden.
joblib.externals.loky.process_executor._RemoteTraceback:
'''
Traceback (most recent call last):
File "C:\Users\fritz\AppData\Local\Programs\Python\Python37\lib\multiprocessing\queues.py", line 109, in get
self._sem.release()
OSError: [WinError 6] Das Handle ist ungültig

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "C:\Users\fritz\AppData\Local\Programs\Python\Python37\lib\multiprocessing\queues.py", line 111, in get
self._rlock.release()
OSError: [WinError 6] Das Handle ist ungültig
'''

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:/Users/fritz/PycharmProjects/Hello/Chap-2_Excercise.py", line 110, in
grid_search.fit(processed, practice_set_labels)
File "C:\Users\fritz\Hello\lib\site-packages\sklearn\model_selection\_search.py", line 688, in fit
self._run_search(evaluate_candidates)
File "C:\Users\fritz\Hello\lib\site-packages\sklearn\model_selection\_search.py", line 1149, in _run_search
evaluate_candidates(ParameterGrid(self.param_grid))
File "C:\Users\fritz\Hello\lib\site-packages\sklearn\model_selection\_search.py", line 667, in evaluate_candidates
cv.split(X, y, groups)))
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 934, in __call__
self.retrieve()
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 833, in retrieve
self._output.extend(job.get(timeout=self.timeout))
File "C:\Users\fritz\Hello\lib\site-packages\joblib\_parallel_backends.py", line 521, in wrap_future_result
return future.result(timeout=timeout)
File "C:\Users\fritz\AppData\Local\Programs\Python\Python37\lib\concurrent\futures\_base.py", line 432, in result
return self.__get_result()
File "C:\Users\fritz\AppData\Local\Programs\Python\Python37\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 309, in __call__
self.parallel.dispatch_next()
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 731, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 759, in dispatch_one_batch
self._dispatch(tasks)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\parallel.py", line 716, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\_parallel_backends.py", line 510, in apply_async
future = self._workers.submit(SafeFunction(func))
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 151, in submit
fn, *args, **kwargs)
File "C:\Users\fritz\Hello\lib\site-packages\joblib\externals\loky\process_executor.py", line 1022, in submit
raise self._flags.broken
joblib.externals.loky.process_executor.BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.

Process finished with exit code 1
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.