소개
게시글
질문&답변
코드 오류
당뇨병 실습 코드에서도 로지스틱 회귀를 이용하였으나 오류가 생겼습니다. sklearn 버젼은 다음과 같습니다. '0.23.2' X_train 만드는 소스코드는 다음과 같습니다. # 피쳐 데이터 세트 X, 레이블 데이터 세트 y를 추출 # 맨 끝이 outcome column으로, label 값임. 컬럼 위치 -1이용해 추출 X = diabetes_data.iloc[:, :-1] y = diabetes_data.iloc[:, -1] X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.2, random_state = 156, stratify = y) # 로지스틱 회귀로 학습 예측 평가 수행 lr_clf = LogisticRegression() lr_clf.fit(X_train, y_train) pred = lr_clf.predict(X_test)
- 0
- 5
- 830
질문&답변
코드 오류
다른 분류기는 제대로 실행되는데, 로지스틱회귀만 오류가 나타나는 것 같습니다! from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score # 결정틀, 랜덤포레스트, 로지스틱 회귀를 위한 사이킷런 Classifier 클래스 형성 dt_clf = DecisionTreeClassifier(random_state = 11) rf_clf = RandomForestClassifier(random_state = 11) lr_clf = LogisticRegression() # DecisionTreeClassifier 학습/예측/평가 dt_clf.fit(X_train, y_train) dt_pred = dt_clf.predict(X_test) print('DecisionTreeClassifier 정확도: {0:.4f}'.format(accuracy_score(y_test, dt_pred))) # RandomForestClassifier 학습/예측/평가 rf_clf.fit(X_train, y_train) rf_pred = rf_clf.predict(X_test) print('RandomForestClassifier 정확도: {0:.4f}'.format(accuracy_score(y_test, rf_pred))) # LogisticRegression 학습/예측/평가 lr_clf.fit(X_train, y_train) lr_pred = lr_clf.predict(X_test) print('LogisticRegression 정확도: {0:.4f}'.format(accuracy_score(y_test, lr_pred))) -- DecisionTreeClassifier 정확도: 0.7877 RandomForestClassifier 정확도: 0.8547 --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in 22 23 # LogisticRegression 학습/예측/평가 ---> 24 lr_clf.fit(X_train, y_train) 25 lr_pred = lr_clf.predict(X_test) 26 print('LogisticRegression 정확도: {0:.4f}'.format(accuracy_score(y_test, lr_pred))) ~/opt/anaconda3/lib/python3.8/site-packages/sklearn/linear_model/_logistic.py in fit(self, X, y, sample_weight) 1405 else: 1406 prefer = 'processes' -> 1407 fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, 1408 **_joblib_parallel_args(prefer=prefer))( 1409 path_func(X, y, pos_class=class_, Cs=[C_], ~/opt/anaconda3/lib/python3.8/site-packages/joblib/parallel.py in __call__(self, iterable) 1039 # remaining jobs. 1040 self._iterating = False -> 1041 if self.dispatch_one_batch(iterator): 1042 self._iterating = self._original_iterator is not None 1043 ~/opt/anaconda3/lib/python3.8/site-packages/joblib/parallel.py in dispatch_one_batch(self, iterator) 857 return False 858 else: --> 859 self._dispatch(tasks) 860 return True 861 ~/opt/anaconda3/lib/python3.8/site-packages/joblib/parallel.py in _dispatch(self, batch) 775 with self._lock: 776 job_idx = len(self._jobs) --> 777 job = self._backend.apply_async(batch, callback=cb) 778 # A job can complete so quickly than its callback is 779 # called before we get here, causing self._jobs to ~/opt/anaconda3/lib/python3.8/site-packages/joblib/_parallel_backends.py in apply_async(self, func, callback) 206 def apply_async(self, func, callback=None): 207 """Schedule a func to be run""" --> 208 result = ImmediateResult(func) 209 if callback: 210 callback(result) ~/opt/anaconda3/lib/python3.8/site-packages/joblib/_parallel_backends.py in __init__(self, batch) 570 # Don't delay the application, to avoid keeping the input 571 # arguments in memory --> 572 self.results = batch() 573 574 def get(self): ~/opt/anaconda3/lib/python3.8/site-packages/joblib/parallel.py in __call__(self) 260 # change the default number of processes to -1 261 with parallel_backend(self._backend, n_jobs=self._n_jobs): --> 262 return [func(*args, **kwargs) 263 for func, args, kwargs in self.items] 264 ~/opt/anaconda3/lib/python3.8/site-packages/joblib/parallel.py in (.0) 260 # change the default number of processes to -1 261 with parallel_backend(self._backend, n_jobs=self._n_jobs): --> 262 return [func(*args, **kwargs) 263 for func, args, kwargs in self.items] 264 ~/opt/anaconda3/lib/python3.8/site-packages/sklearn/linear_model/_logistic.py in _logistic_regression_path(X, y, pos_class, Cs, fit_intercept, max_iter, tol, verbose, solver, coef, class_weight, dual, penalty, intercept_scaling, multi_class, random_state, check_input, max_squared_sum, sample_weight, l1_ratio) 760 options={"iprint": iprint, "gtol": tol, "maxiter": max_iter} 761 ) --> 762 n_iter_i = _check_optimize_result( 763 solver, opt_res, max_iter, 764 extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG) ~/opt/anaconda3/lib/python3.8/site-packages/sklearn/utils/optimize.py in _check_optimize_result(solver, result, max_iter, extra_warning_msg) 241 " https://scikit-learn.org/stable/modules/" 242 "preprocessing.html" --> 243 ).format(solver, result.status, result.message.decode("latin1")) 244 if extra_warning_msg is not None: 245 warning_msg += "\n" + extra_warning_msg AttributeError: 'str' object has no attribute 'decode'
- 0
- 5
- 830