[Python] PyCaret Windows 10 아나콘다 설치 방법

Page content

강의 홍보

1줄 요약

  • 관리자 실행해서 아나콘다 가상 환경을 만든 후, 새로운 패키지를 설치한다.

PyCaret 설치 방법 (Windows 10)

  • 윈도우 10 환경에서 PyCaret 패키지를 설치해봅니다.
  • 아나콘다 설치에 관한 내용은 생략합니다. 다만, 이 때, 필요한 것은 환경변수에 추가가 되어 있어야 합니다.

가상환경 설정

  • 새로운 가상환경을 만듭니다. (이게 제일 편합니다.)
  • 명령프롬프트를 관리자로 실행합니다.

  • 현재 경로는 아래와 같습니다.
!echo %cd%
C:\Users\hkit\Desktop\pycaret
  • 이 때, 적정한 경로로 이동한 후, 아래 명령어를 입력합니다.
  • 먼저 가상환경을 만듭니다.
$ conda create --name yourenvname python=3.8
  • 필자는 yourenvname 대신에, pycaret이라고 새로 이름을 지었습니다.
  • 그 후에, 가상환경에 접속합니다. (이게 중요합니다!)
$ conda activate yourenvname
  • 마지막으로 pycaret을 설치합니다.
$ pip install pycaret

  • PyCaret을 설치하기 위해서 Scikit-Learn, Pandas 등을 사전에 먼저 설치할 필요가 없습니다. 만약 설치가 되어 있다면, 버전 충돌이 발생할 수가 있습니다. 즉, 이 때에는 기존에 설치된 패키지를 삭제 후 재 설치를 해야 합니다. 이러한 번거로움을 겪지 않기 위해, 새로운 가상 환경을 아예 만들어 설치하는 것이 훨씬 간편합니다.
  • 만약 패키지 의존성을 확인하고 싶다면, 패키지 Github의 requirements.txt을 확인하시기를 바랍니다.
    • 즉, pip install pycaret과 함께, 자동으로 설치가 됩니다.

주피터 노트북 실행

  • 이제 주피터 노트북을 실행하여 Sample 코드를 작성해봅니다.
  • 아나콘다를 관리자로 실행한 후, 아래 화면처럼 방금전에 만든 가상환경 이름을 찾아서 클릭합니다.

  • 처음 작업하는 것이라면, 대개 아래 그림 처럼 Jupyter Notebook이나 Lab에서 설치를 먼저 해줘야 합니다.
  • 필자는 Jupyter Lab을 좋아하기 때문에, Jupyter Lab을 설치 실행합니다.

Tutorial 확인

from pycaret.datasets import get_data
dataset = get_data('credit')
dataset.shape
LIMIT_BALSEXEDUCATIONMARRIAGEAGEPAY_1PAY_2PAY_3PAY_4PAY_5...BILL_AMT4BILL_AMT5BILL_AMT6PAY_AMT1PAY_AMT2PAY_AMT3PAY_AMT4PAY_AMT5PAY_AMT6default
0200002212422-1-1-2...0.00.00.00.0689.00.00.00.00.01
1900002223400000...14331.014948.015549.01518.01500.01000.01000.01000.05000.00
2500002213700000...28314.028959.029547.02000.02019.01200.01100.01069.01000.00
35000012157-10-100...20940.019146.019131.02000.036681.010000.09000.0689.0679.00
4500001123700000...19394.019619.020024.02500.01815.0657.01000.01000.0800.00

5 rows × 24 columns

(24000, 24)
data = dataset.sample(frac=0.95, random_state=786)
data_unseen = dataset.drop(data.index)
data.reset_index(inplace=True, drop=True)
data_unseen.reset_index(inplace=True, drop=True)
print('Data for Modeling: ' + str(data.shape))
print('Unseen Data For Predictions: ' + str(data_unseen.shape))
Data for Modeling: (22800, 24)
Unseen Data For Predictions: (1200, 24)
from pycaret.classification import *
exp_clf101 = setup(data = data, target = 'default', session_id=123)
DescriptionValue
0session_id123
1Targetdefault
2Target TypeBinary
3Label Encoded0: 0, 1: 1
4Original Data(22800, 24)
5Missing ValuesFalse
6Numeric Features14
7Categorical Features9
8Ordinal FeaturesFalse
9High Cardinality FeaturesFalse
10High Cardinality MethodNone
11Transformed Train Set(15959, 88)
12Transformed Test Set(6841, 88)
13Shuffle Train-TestTrue
14Stratify Train-TestFalse
15Fold GeneratorStratifiedKFold
16Fold Number10
17CPU Jobs-1
18Use GPUFalse
19Log ExperimentFalse
20Experiment Nameclf-default-name
21USI7858
22Imputation Typesimple
23Iterative Imputation IterationNone
24Numeric Imputermean
25Iterative Imputation Numeric ModelNone
26Categorical Imputerconstant
27Iterative Imputation Categorical ModelNone
28Unknown Categoricals Handlingleast_frequent
29NormalizeFalse
30Normalize MethodNone
31TransformationFalse
32Transformation MethodNone
33PCAFalse
34PCA MethodNone
35PCA ComponentsNone
36Ignore Low VarianceFalse
37Combine Rare LevelsFalse
38Rare Level ThresholdNone
39Numeric BinningFalse
40Remove OutliersFalse
41Outliers ThresholdNone
42Remove MulticollinearityFalse
43Multicollinearity ThresholdNone
44ClusteringFalse
45Clustering IterationNone
46Polynomial FeaturesFalse
47Polynomial DegreeNone
48Trignometry FeaturesFalse
49Polynomial ThresholdNone
50Group FeaturesFalse
51Feature SelectionFalse
52Feature Selection Methodclassic
53Features Selection ThresholdNone
54Feature InteractionFalse
55Feature RatioFalse
56Interaction ThresholdNone
57Fix ImbalanceFalse
58Fix Imbalance MethodSMOTE
best_model = compare_models()
ModelAccuracyAUCRecallPrec.F1KappaMCCTT (Sec)
ridgeRidge Classifier0.82540.00000.36370.69130.47640.38360.41220.0300
ldaLinear Discriminant Analysis0.82470.76340.37550.67940.48350.38840.41320.2630
gbcGradient Boosting Classifier0.82250.77900.35480.68000.46610.37210.40050.7580
adaAda Boost Classifier0.82210.76970.35050.68110.46260.36900.39830.1900
lightgbmLight Gradient Boosting Machine0.82100.77500.36090.66790.46830.37210.39770.0890
rfRandom Forest Classifier0.81800.76180.35910.65310.46310.36450.38840.4350
etExtra Trees Classifier0.80820.73810.36690.60100.45530.34710.36290.4750
lrLogistic Regression0.78140.64100.00030.10000.00060.00030.00340.4370
knnK Neighbors Classifier0.75470.59390.17630.37190.23880.11450.12590.2240
svmSVM - Linear Kernel0.72850.00000.10030.14540.09570.00670.00750.1750
dtDecision Tree Classifier0.72620.61340.41270.38320.39700.22040.22080.0680
qdaQuadratic Discriminant Analysis0.47610.52820.62080.23740.33990.03770.04780.1860
nbNaive Bayes0.37600.64420.88450.24410.38260.06080.12070.0280
rf = create_model('rf')
plot_model(rf, plot = 'auc')

png

plot_model(rf, plot = 'confusion_matrix')

png

unseen_predictions = predict_model(rf, data=data_unseen)
unseen_predictions.head()
LIMIT_BALSEXEDUCATIONMARRIAGEAGEPAY_1PAY_2PAY_3PAY_4PAY_5...BILL_AMT6PAY_AMT1PAY_AMT2PAY_AMT3PAY_AMT4PAY_AMT5PAY_AMT6defaultLabelScore
0100000222230-1-100...567.0380.0601.00.0581.01687.01542.0000.74
138000012232-1-1-1-1-1...11873.021540.015138.024677.011851.011875.08251.0000.98
220000022132-1-1-1-12...3151.05818.015.09102.017.03165.01395.0000.87
32000001115322222...149531.06300.05500.05500.05500.05000.05000.0110.67
4240000112411-1-100...1737.02622.03301.00.0360.01737.0924.0000.80

5 rows × 26 columns

from pycaret.utils import check_metric
check_metric(unseen_predictions['default'], unseen_predictions['Label'], metric = 'Accuracy')
0.8142
  • 결론은 가상환경에서 설치를 해야 합니다. 가상환경을 잘 사용합시다.