티스토리 뷰
ERROR/SQL
[pythons]AttributeError: 'NoneType' object has no attribute 'split'
onlyun 2022. 6. 30. 11:22
빅데이터 머신러닝 군집화 과정에서
최적의 K 찾기, 엘보 방법으로 할 때,
for i in range(1, 11):
kmeans_i = KMeans(n_clusters=i, random_state=0) #모델 생성
kmeans_i.fit(X_features_scaled) #모델 훈련
distortions.append(kmeans_i.inertia_)
plt.plot(range(2,11), distortions, marker = 'o')
plt.xlabel('Number of clusters')
plt.ylabel('Distortion')
plt.show()
>> 에러 발생
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [87], in <cell line: 5>()
5 for i in range(1, 11):
6 kmeans_i = KMeans(n_clusters=i, random_state=0) #모델 생성
----> 7 kmeans_i.fit(X_features_scaled) #모델 훈련
8 distortions.append(kmeans_i.inertia_)
10 plt.plot(range(2,11), distortions, marker = 'o')
File ~\anaconda3\lib\site-packages\sklearn\cluster\_kmeans.py:1186, in KMeans.fit(self, X, y, sample_weight)
1183 print("Initialization complete")
1185 # run a k-means once
-> 1186 labels, inertia, centers, n_iter_ = kmeans_single(
1187 X,
1188 sample_weight,
1189 centers_init,
1190 max_iter=self.max_iter,
1191 verbose=self.verbose,
1192 tol=self._tol,
1193 x_squared_norms=x_squared_norms,
1194 n_threads=self._n_threads,
1195 )
1197 # determine if these results are the best so far
1198 # we chose a new run if it has a better inertia and the clustering is
1199 # different from the best so far (it's possible that the inertia is
1200 # slightly better even if the clustering is the same with potentially
1201 # permuted labels, due to rounding errors)
1202 if best_inertia is None or (
1203 inertia < best_inertia
1204 and not _is_same_clustering(labels, best_labels, self.n_clusters)
1205 ):
File ~\anaconda3\lib\site-packages\sklearn\cluster\_kmeans.py:625, in _kmeans_single_lloyd(X, sample_weight, centers_init, max_iter, verbose, x_squared_norms, tol, n_threads)
621 strict_convergence = False
623 # Threadpoolctl context to limit the number of threads in second level of
624 # nested parallelism (i.e. BLAS) to avoid oversubsciption.
--> 625 with threadpool_limits(limits=1, user_api="blas"):
626 for i in range(max_iter):
627 lloyd_iter(
628 X,
629 sample_weight,
(...)
636 n_threads,
637 )
File ~\anaconda3\lib\site-packages\sklearn\utils\fixes.py:314, in threadpool_limits(limits, user_api)
312 return controller.limit(limits=limits, user_api=user_api)
313 else:
--> 314 return threadpoolctl.threadpool_limits(limits=limits, user_api=user_api)
File ~\anaconda3\lib\site-packages\threadpoolctl.py:171, in threadpool_limits.__init__(self, limits, user_api)
167 def __init__(self, limits=None, user_api=None):
168 self._limits, self._user_api, self._prefixes = \
169 self._check_params(limits, user_api)
--> 171 self._original_info = self._set_threadpool_limits()
File ~\anaconda3\lib\site-packages\threadpoolctl.py:268, in threadpool_limits._set_threadpool_limits(self)
265 if self._limits is None:
266 return None
--> 268 modules = _ThreadpoolInfo(prefixes=self._prefixes,
269 user_api=self._user_api)
270 for module in modules:
271 # self._limits is a dict {key: num_threads} where key is either
272 # a prefix or a user_api. If a module matches both, the limit
273 # corresponding to the prefix is chosed.
274 if module.prefix in self._limits:
File ~\anaconda3\lib\site-packages\threadpoolctl.py:340, in _ThreadpoolInfo.__init__(self, user_api, prefixes, modules)
337 self.user_api = [] if user_api is None else user_api
339 self.modules = []
--> 340 self._load_modules()
341 self._warn_if_incompatible_openmp()
342 else:
File ~\anaconda3\lib\site-packages\threadpoolctl.py:373, in _ThreadpoolInfo._load_modules(self)
371 self._find_modules_with_dyld()
372 elif sys.platform == "win32":
--> 373 self._find_modules_with_enum_process_module_ex()
374 else:
375 self._find_modules_with_dl_iterate_phdr()
File ~\anaconda3\lib\site-packages\threadpoolctl.py:485, in _ThreadpoolInfo._find_modules_with_enum_process_module_ex(self)
482 filepath = buf.value
484 # Store the module if it is supported and selected
--> 485 self._make_module_from_path(filepath)
486 finally:
487 kernel_32.CloseHandle(h_process)
File ~\anaconda3\lib\site-packages\threadpoolctl.py:515, in _ThreadpoolInfo._make_module_from_path(self, filepath)
513 if prefix in self.prefixes or user_api in self.user_api:
514 module_class = globals()[module_class]
--> 515 module = module_class(filepath, prefix, user_api, internal_api)
516 self.modules.append(module)
File ~\anaconda3\lib\site-packages\threadpoolctl.py:606, in _Module.__init__(self, filepath, prefix, user_api, internal_api)
604 self.internal_api = internal_api
605 self._dynlib = ctypes.CDLL(filepath, mode=_RTLD_NOLOAD)
--> 606 self.version = self.get_version()
607 self.num_threads = self.get_num_threads()
608 self._get_extra_info()
File ~\anaconda3\lib\site-packages\threadpoolctl.py:646, in _OpenBLASModule.get_version(self)
643 get_config = getattr(self._dynlib, "openblas_get_config",
644 lambda: None)
645 get_config.restype = ctypes.c_char_p
--> 646 config = get_config().split()
647 if config[0] == b"OpenBLAS":
648 return config[1].decode("utf-8")
AttributeError: 'NoneType' object has no attribute 'split'
>> 해결방법
#최적의 K 찾기_1 : 엘보 방법
distortions = []
for i in range(2, 11):
kmeans_i = KMeans(n_clusters=i, random_state=0) #모델 생성
kmeans_i.fit(X_features_scaled) #모델 훈련
distortions.append(kmeans_i.inertia_)
plt.plot(range(2,11), distortions, marker = 'o')
plt.xlabel('Number of clusters')
plt.ylabel('Distortion')
plt.show()
#범위 1부터 하니까 에러 떠서 2부터 시작하니까 됨...왜? 이유는 모르겠지만 해결은 됐음
'ERROR > SQL' 카테고리의 다른 글
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- css
- BAEKJOON
- typeof
- text formatting
- html pre
- 변수
- improt
- JavaScript
- 미디어 태그
- html atrribute
- selcetor
- initialized
- A%B
- 스크립태그
- caption-side
- html layout
- CascadingStyleSheet
- ScriptTag
- empty-cell
- scanner
- html
- html a tag
- border-spacing
- 입력양식
- 외부구성요소
- html input type
- 기본선택자
- Java
- input type 종류
- html base tag
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함