태그 보관물: scikit-learn

사이킷런의 load_boston() 함수가 삭제될 예정입니다.

사이킷런의 load_boston() 함수가 삭제될 예정입니다. 이 데이터셋의 문제는 특성 “B” 때문입니다. 문서에서 볼 수 있듯이 이 특성은 도시의 흑인 비율을 사용합니다. 흑인 비율이 주택 가격에 미치는 요소인 거죠. 시대가 시대인만큼 요즘엔 수용하기 쉽지 않습니다. 오히려 이제야 문제가 제기되었다는 것이 부끄러울 수 있죠.

이 데이터를 삭제할지, 특성만 제거할지 의견이 다양했는데요. 결국 deprecate 경고를 내고 0.26 버전 즈음에서 삭제될 것 같습니다. 문제는 이 데이터셋이 책이나 블로그 등에 예제로 너무 많이 쓰였다는 점입니다. 제가 번역한 책에도 몇 군데 있을 것 같네요. ㅠ.ㅠ

사이킷런에서는 사라지겠지만 fetch_openml 함수를 사용하여 OpenML에서 가져올 수 있습니다.

from sklearn import datasets
X, y = datasets.fetch_openml('boston', return_X_y=True)

더 자세한 내용은 사이킷런 깃허브의 이슈를 참고하세요.

Scikit-Learn 0.23.0 Release!

사이킷런 0.23.0 버전이 릴리스되었습니다! 0.23.0에서는 드디어 일반 선형 모델(GLM)이 추가되었습니다. PoissonRegressor, GammaRegressor, TweedieRegressor 입니다.

주피터 노트북에서set_config(display='diagram')로 지정하면 추정기를 다이어그램으로 시각화해 줍니다! 와우!

K-평균과 히스토그램 기반 그레이디언트 부스팅이 개선되었습니다. 또한 LassoElasticNet 클래스가 sample_weight 매개변수를 지원합니다.

0.23.0 버전의 주요 변경 사항은 릴리스 하이라이트를 참고하세요. 전체 변경 내용은 릴리스 노트를 참고하세요.

사이킷런 0.23.0은 pipconda 명령으로 설치할 수 있습니다(이 글을 쓰는 시점에는 아직 콘다 패키지가 제공되지 않습니다. 코랩도 아직 0.22.0 버전입니다).

$ pip install --upgrade scikit-learn

$ conda install scikit-learn

(업데이트) KMeans 버그를 수정한 0.23.1 버전이 릴리스되었습니다.

“파이썬을 활용한 머신러닝 쿡북”이 출간되었습니다!

x9791162241950크리스 알본의 ‘Machine Learning with Python Cookbook’을 번역한 <파이썬을 활용한 머신러닝 쿡북>이 출간되었습니다. 200개의 레시피에 머신러닝 작업에 필요한 핵심을 잘 담아 놓았습니다.

508페이지 로 뽑아 주신 한빛미디어 출판사에 감사드립니다. 온라인/오프라인 서점(교보문고, Yes24)에서 판매 중입니다. 절판되기 전에 어서 주문하세요! 🙂

Scikit-Learn 0.21.1 Release

사이킷런 0.21.1 버전이 릴리스 되었습니다! 며칠 전에 릴리스된 0.21 버전의 버그를 수정했다고 하네요. 이제 HistGradientBoostingClassifier, HistGradientBoostingRegressor 클래스가 제대로 보입니다. 🙂

0.21.1 버전은 pip로 설치할 수 있습니다. conda 패키지는 아직 입니다.

$ pip install scikit-learn

“머신러닝 교과서”가 출간되었습니다!

x9791160507966세바스찬 라시카Sebastian Raschka와 바히드 미자리리Vahid Mirjalili의 아마존 베스트셀러 “Python Machine Learning” 2판을 번역한 <머신 러닝 교과서 with 파이썬, 사이킷런, 텐서플로>가 출간되었습니다!

원서와 달리 번역서는 사이킷런 0.20 버전과 텐서플로 2.0.0a 버전을 기준으로 쓰여졌습니다. 최신 텐서플로의 변경사항을 가장 빠르게 만나실 수 있는 방법 중 하나입니다!

644페이지를 모두 풀 컬러로 인쇄해 주신 길벗출판사에 감사드립니다! 이 책은 온라인(Yes24, 교보문고)/오프라인 서점에서 판매 중입니다! 🙂

Scikit-Learn 0.21.0 Release

사이킷런 0.21 버전이 릴리스 되었습니다! RC 버전에서 언급되었던 히스토그램 기반 부스팅 알고리즘인 HistGradientBoostingClassifier, OPTICS 클러스터링 알고리즘, 누락된 값을 예측하여 채울 때 사용할 수 있는 IterativeImputer, NeighborhoodComponentsAnalysis 가 추가되었습니다.

0.21 버전은 pip로 설치할 수 있습니다. conda 패키지는 하루 이틀 걸릴 것 같네요.

$ pip install scikit-learn

이 중에 HistGradientBoostingClassifier와 IterativeImputer는 실험적인 기능이라 기본으로 활성화되어 있지 않습니다. 다음처럼 sklearn.experimental 모듈 아래를 참조해 주어야 합니다.

>>> from sklearn.experimental import enable_hist_gradient_boosting
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.experimental import enable_iterative_imputer
>>> from sklearn.impute import IterativeImputer

무슨 일인지 HistGradientBoostingClassifier 문서가 생성되지 않았네요. 급한대로 소스 코드에서 긁어 올립니다. 🙂

"""Histogram-based Gradient Boosting Classification Tree.

This estimator is much faster than
:class:`GradientBoostingClassifier<sklearn.ensemble.GradientBoostingClassifier>`
for big datasets (n_samples >= 10 000). The input data ``X`` is pre-binned
into integer-valued bins, which considerably reduces the number of
splitting points to consider, and allows the algorithm to leverage
integer-based data structures. For small sample sizes,
:class:`GradientBoostingClassifier<sklearn.ensemble.GradientBoostingClassifier>`
might be preferred since binning may lead to split points that are too
approximate in this setting.

This implementation is inspired by
`LightGBM <https://github.com/Microsoft/LightGBM>`_.

.. note::

  This estimator is still **experimental** for now: the predictions
  and the API might change without any deprecation cycle. To use it,
  you need to explicitly import ``enable_hist_gradient_boosting``::

    >>> # explicitly require this experimental feature
    >>> from sklearn.experimental import enable_hist_gradient_boosting  # noqa
    >>> # now you can import normally from ensemble
    >>> from sklearn.ensemble import HistGradientBoostingClassifier

Parameters
----------
loss : {'auto', 'binary_crossentropy', 'categorical_crossentropy'}, \
        optional (default='auto')
    The loss function to use in the boosting process. 'binary_crossentropy'
    (also known as logistic loss) is used for binary classification and
    generalizes to 'categorical_crossentropy' for multiclass
    classification. 'auto' will automatically choose either loss depending
    on the nature of the problem.
learning_rate : float, optional (default=1)
    The learning rate, also known as *shrinkage*. This is used as a
    multiplicative factor for the leaves values. Use ``1`` for no
    shrinkage.
max_iter : int, optional (default=100)
    The maximum number of iterations of the boosting process, i.e. the
    maximum number of trees for binary classification. For multiclass
    classification, `n_classes` trees per iteration are built.
max_leaf_nodes : int or None, optional (default=31)
    The maximum number of leaves for each tree. Must be strictly greater
    than 1. If None, there is no maximum limit.
max_depth : int or None, optional (default=None)
    The maximum depth of each tree. The depth of a tree is the number of
    nodes to go from the root to the deepest leaf. Must be strictly greater
    than 1. Depth isn't constrained by default.
min_samples_leaf : int, optional (default=20)
    The minimum number of samples per leaf. For small datasets with less
    than a few hundred samples, it is recommended to lower this value
    since only very shallow trees would be built.
l2_regularization : float, optional (default=0)
    The L2 regularization parameter. Use 0 for no regularization.
max_bins : int, optional (default=256)
    The maximum number of bins to use. Before training, each feature of
    the input array ``X`` is binned into at most ``max_bins`` bins, which
    allows for a much faster training stage. Features with a small
    number of unique values may use less than ``max_bins`` bins. Must be no
    larger than 256.
scoring : str or callable or None, optional (default=None)
    Scoring parameter to use for early stopping. It can be a single
    string (see :ref:`scoring_parameter`) or a callable (see
    :ref:`scoring`). If None, the estimator's default scorer
    is used. If ``scoring='loss'``, early stopping is checked
    w.r.t the loss value. Only used if ``n_iter_no_change`` is not None.
validation_fraction : int or float or None, optional (default=0.1)
    Proportion (or absolute size) of training data to set aside as
    validation data for early stopping. If None, early stopping is done on
    the training data.
n_iter_no_change : int or None, optional (default=None)
    Used to determine when to "early stop". The fitting process is
    stopped when none of the last ``n_iter_no_change`` scores are better
    than the ``n_iter_no_change - 1``th-to-last one, up to some
    tolerance. If None or 0, no early-stopping is done.
tol : float or None, optional (default=1e-7)
    The absolute tolerance to use when comparing scores. The higher the
    tolerance, the more likely we are to early stop: higher tolerance
    means that it will be harder for subsequent iterations to be
    considered an improvement upon the reference score.
verbose: int, optional (default=0)
    The verbosity level. If not zero, print some information about the
    fitting process.
random_state : int, np.random.RandomStateInstance or None, \
    optional (default=None)
    Pseudo-random number generator to control the subsampling in the
    binning process, and the train/validation data split if early stopping
    is enabled. See :term:`random_state`.

Attributes
----------
n_iter_ : int
    The number of estimators as selected by early stopping (if
    n_iter_no_change is not None). Otherwise it corresponds to max_iter.
n_trees_per_iteration_ : int
    The number of tree that are built at each iteration. This is equal to 1
    for binary classification, and to ``n_classes`` for multiclass
    classification.
train_score_ : ndarray, shape (max_iter + 1,)
    The scores at each iteration on the training data. The first entry
    is the score of the ensemble before the first iteration. Scores are
    computed according to the ``scoring`` parameter. If ``scoring`` is
    not 'loss', scores are computed on a subset of at most 10 000
    samples. Empty if no early stopping.
validation_score_ : ndarray, shape (max_iter + 1,)
    The scores at each iteration on the held-out validation data. The
    first entry is the score of the ensemble before the first iteration.
    Scores are computed according to the ``scoring`` parameter. Empty if
    no early stopping or if ``validation_fraction`` is None.

Examples
--------
>>> # To use this experimental feature, we need to explicitly ask for it:
>>> from sklearn.experimental import enable_hist_gradient_boosting  # noqa
>>> from sklearn.ensemble import HistGradientBoostingRegressor
>>> from sklearn.datasets import load_iris
>>> X, y = load_iris(return_X_y=True)
>>> clf = HistGradientBoostingClassifier().fit(X, y)
>>> clf.score(X, y)
1.0
"""

Scikit-Learn 0.21 RC Release

사이킷런 0.21 RC 버전이 릴리스 되었습니다. 일전에 소개해 드렸던 히스토그램 기반의 부스팅 트리 알고리즘인 HistGradientBoostingClassifierHistGradientBoostingRegressor가 가장 주목을 받고 있습니다. 샘플이 만 개 이상이면 기존의 그래디언트 부스팅보다 훨씬 빠릅니다. 이 클래스들은 마이크로소프트의 LightGBM에 영향을 받아 만들어진 pygbm의 사이킷런 포팅입니다. 히스토그램 기반 부스팅 트리는 캐글에서 가장 많이 사용하는 알고리즘 중 하나입니다.

그외에도 많은 기능이 추가되었습니다. 눈에 띠는 것은 다음과 같습니다.

  • OPTICS 클러스터링 알고리즘이 추가되었습니다. DBSCAN와 유사하지만 매개변수 설정이 쉽고 대용량 데이터셋에도 잘 동작합니다.
  • 데이터셋에서 한 특성을 타깃으로 정하고 나머지 특성을 사용하여 누락된 값을 예측하는 IterativeImputer가 추가되었습니다. 타깃 열을 바꾸어 가며 반복합니다. 모델링에 사용하는 기본 추정기는 BayesianRidge 클래스입니다.
  • 샘플 간의 거리 지표를 학습(metric learning)하여 차원 축소로도 활용할 수 있는 NeighborhoodComponentsAnalysis(NCA)가 추가되었습니다.

0.21 버전의 자세한 변경 사항은 What’s new 페이지를 참고하세요.

0.21 RC 버전은 다음과 같이 설치할 수 있습니다.

pip install scikit-learn==0.21rc2

“[개정판] 파이썬 라이브러리를 활용한 머신러닝”이 출간되었습니다!

x9791162241646안드레아스 뮐러Andreas Mueller와 세라 가이도Sarah Guido의 베스트 셀러 “Introduction to Machine Learning with Python“의 번역서인 “파이썬 라이브러리를 활용한 머신러닝“이 개정판으로 새롭게 출간되었습니다!

지난해 10월 원서 저자들이 최신 사이킷런 버전에서 추가된 내용을 반영하여 새롭게 원서를 릴리스했습니다. 원서에서 바뀐 부분을 번역서에 반영하기에는 변경사항이 너무 많아 난처했습니다.

다행히 출판사와 협의하여 새롭게 개정판을 준비할 수 있었습니다. 그동안 많은 독자들에게 사랑을 받았던 책이라 개정판은 특별히 컬러 인쇄가 되었습니다! 여러가지 배려를 아끼지 않은 한빛미디어에 감사드립니다. 시원한 컬러 그래프를 볼 생각을 하니 너무 기쁘네요. 🙂

개정판에 추가, 변경된 내용은 [개정판] 파이썬 라이브러리를 활용한 머신러닝 페이지를 참고하세요. 이 책은 YES24, 교보문고와 같은 온라인 서점과 오프라인 서점에서 판매 중입니다!

“머신 러닝 교과서” 베타 테스터 모집합니다!

 

“머신 러닝 교과서”의 정오표 페이지는 여기입니다.

 

지난 겨울내내 끙끙맸던 세바스찬 라시카의 “Python Machine Learning” 2nd Ed. 번역을 마쳤습니다. 원서와 달리 번역서는 사이킷런 0.20과 텐서플로 2.0을 기준으로 출간됩니다. 특히 딥러닝을 설명하는 후반 챕터는 텐서플로 2.0에 맞게 많은 부분을 새롭게 작성하였습니다.

길벗 출판사에서 이 책의 베타 테스터를 모집합니다. 페북 글을 참고하시고 관심있으신 분은 신청해 주세요. 감사합니다! 🙂