TypeError: __init__() got an unexpected keyword argument 'n_iter'
akashdeepxv opened this issue · comments
working on a speaker recognition code and while training the machine getting this:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\AKASHDEEP\AppData\Local\Programs\Python\Python38\lib\tkinter_init_.py", line 1883, in call
return self.func(*args)
File "C:\Users\AKASHDEEP\AppData\Local\Programs\Python\Python38\Speaker-Recognition\train.py", line 113, in train
traine(v1.get())
File "C:\Users\AKASHDEEP\AppData\Local\Programs\Python\Python38\Speaker-Recognition\GMM1.py", line 40, in traine
gmm = GMM(n_components = 16, n_iter = 200, covariance_type='diag', n_init = 10)
File "C:\Users\AKASHDEEP\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\utils\validation.py", line 73, in inner_f
return f(**kwargs)
TypeError: init() got an unexpected keyword argument 'n_iter'
Can you provide a minimum example of what causes the error?
From your traceback I don't see hyperopt
or hyperopt-sklearn
involved at all.
Faced the same problem, it's coming from SGDRegressor
Here's the example code and traceback;
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from hpsklearn import HyperoptEstimator, any_regressor, any_preprocessing, svr
from hyperopt import tpe, hp
import math as m
X, y = load_boston().data, load_boston().target
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2)
model = HyperoptEstimator(regressor=any_regressor('test1_reg'),
preprocessing=any_preprocessing('test1_preprocessing'),
algo=tpe.suggest,
max_evals=5)
model.fit(X_train, y_train, n_folds=3, cv_shuffle=True)
print(model.score(X_test, y_test))
print(mdoel.best_model())
0%| | 0/1 [00:00<?, ?trial/s, best loss=?]
job exception: __init__() got an unexpected keyword argument 'n_iter'
0%| | 0/1 [00:00<?, ?trial/s, best loss=?]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-452ed9b18bbb> in <module>
13 max_evals=5)
14
---> 15 model.fit(X_train, y_train, n_folds=3, cv_shuffle=True)
16
17 print(model.score(X_test, y_test))
~/anaconda3/lib/python3.7/site-packages/hpsklearn/estimator.py in fit(self, X, y, EX_list, valid_size, n_folds, cv_shuffle, warm_start, random_state, weights)
744 increment = min(self.fit_increment,
745 adjusted_max_evals - len(self.trials.trials))
--> 746 fit_iter.send(increment)
747 if filename is not None:
748 with open(filename, 'wb') as dump_file:
~/anaconda3/lib/python3.7/site-packages/hpsklearn/estimator.py in fit_iter(self, X, y, EX_list, valid_size, n_folds, cv_shuffle, warm_start, random_state, weights, increment)
655 # so we notice them.
656 catch_eval_exceptions=False,
--> 657 return_argmin=False, # -- in case no success so far
658 )
659 else:
~/anaconda3/lib/python3.7/site-packages/hyperopt/fmin.py in fmin(fn, space, algo, max_evals, timeout, loss_threshold, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin, points_to_evaluate, max_queue_len, show_progressbar)
480 catch_eval_exceptions=catch_eval_exceptions,
481 return_argmin=return_argmin,
--> 482 show_progressbar=show_progressbar,
483 )
484
~/anaconda3/lib/python3.7/site-packages/hyperopt/base.py in fmin(self, fn, space, algo, max_evals, timeout, loss_threshold, max_queue_len, rstate, verbose, pass_expr_memo_ctrl, catch_eval_exceptions, return_argmin, show_progressbar)
684 catch_eval_exceptions=catch_eval_exceptions,
685 return_argmin=return_argmin,
--> 686 show_progressbar=show_progressbar,
687 )
688
~/anaconda3/lib/python3.7/site-packages/hyperopt/fmin.py in fmin(fn, space, algo, max_evals, timeout, loss_threshold, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin, points_to_evaluate, max_queue_len, show_progressbar)
507
508 # next line is where the fmin is actually executed
--> 509 rval.exhaust()
510
511 if return_argmin:
~/anaconda3/lib/python3.7/site-packages/hyperopt/fmin.py in exhaust(self)
328 def exhaust(self):
329 n_done = len(self.trials)
--> 330 self.run(self.max_evals - n_done, block_until_done=self.asynchronous)
331 self.trials.refresh()
332 return self
~/anaconda3/lib/python3.7/site-packages/hyperopt/fmin.py in run(self, N, block_until_done)
284 else:
285 # -- loop over trials and do the jobs directly
--> 286 self.serial_evaluate()
287
288 self.trials.refresh()
~/anaconda3/lib/python3.7/site-packages/hyperopt/fmin.py in serial_evaluate(self, N)
163 ctrl = base.Ctrl(self.trials, current_trial=trial)
164 try:
--> 165 result = self.domain.evaluate(spec, ctrl)
166 except Exception as e:
167 logger.error("job exception: %s" % str(e))
~/anaconda3/lib/python3.7/site-packages/hyperopt/base.py in evaluate(self, config, ctrl, attach_attachments)
890 self.expr,
891 memo=memo,
--> 892 print_node_on_error=self.rec_eval_print_node_on_error,
893 )
894 rval = self.fn(pyll_rval)
~/anaconda3/lib/python3.7/site-packages/hyperopt/pyll/base.py in rec_eval(expr, deepcopy_inputs, memo, max_program_len, memo_gc, print_trace, print_node_on_error)
909
910 try:
--> 911 rval = scope._impls[node.name](*args, **kwargs)
912
913 except Exception as e:
~/anaconda3/lib/python3.7/site-packages/hpsklearn/components.py in sklearn_SGDRegressor(*args, **kwargs)
93 @scope.define
94 def sklearn_SGDRegressor(*args, **kwargs):
---> 95 return sklearn.linear_model.SGDRegressor(*args, **kwargs)
96
97 @scope.define
~/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74
TypeError: __init__() got an unexpected keyword argument 'n_iter'
I think it's because, there's not agrument in SGDRegressor, 'n_iter'. Instead it's changed to 'max_iter' in the newer versions, as they added an argument for early stopping.