데이터 분석을 쉽게 할 수 있는dabl을 사용해 보았습니다.

19302 단어 Pythonkaggletech
카글이 dabl라는 프로그램 라이브러리를 사용했기 때문에 실제로 뭘 할 수 있는지 사용하고 싶습니다.

이른바 dabl


dabl은 교사가 학습 중에 예측 모델을 구축하기 전의 기본적인 임무를 자동으로 완성할 수 있는 프로그램 라이브러리입니다.Dabl이라는 이름은 Data Analysis Baseline Library의 약칭입니다.

할 수 있는 일


주로 할 수 있는 일은 다음과 같은 세 가지가 있다.
  • 데이터의 세척
  • 시각화
  • 모델의 학습
  • 특히 시각화는 여러 개의 도표를 표시할 수 있기 때문에'어쨌든 먼저 시각화하자'고 생각할 때 유용할 것 같다.

    설치하다.


    먼저 설치합니다.
    pip install dabl
    

    시용하다


    여기서부터kaggle 데이터를 사용하면서dabl을 실제적으로 사용합니다.

    데이터 활용


    House Prices 경기의 데이터를 사용했다.
    79개의 특징량에서 주택 가격을 예측하는 회귀 문제가 되었다.
    먼저 데이터를 읽습니다.
    import pandas as pd
    train = pd.read_csv("../input/house-prices-advanced-regression-techniques/train.csv")
    
    읽은 데이터는 다음과 같습니다.
    train.head()
    
    Id
    MSSubClass
    MSZoning
    LotFrontage
    LotArea
    Street
    Alley
    LotShape
    LandContour
    Utilities
    LotConfig
    LandSlope
    Neighborhood
    Condition1
    Condition2
    BldgType
    HouseStyle
    OverallQual
    OverallCond
    YearBuilt
    YearRemodAdd
    RoofStyle
    RoofMatl
    Exterior1st
    Exterior2nd
    MasVnrType
    MasVnrArea
    ExterQual
    ExterCond
    Foundation
    BsmtQual
    BsmtCond
    BsmtExposure
    BsmtFinType1
    BsmtFinSF1
    BsmtFinType2
    BsmtFinSF2
    BsmtUnfSF
    TotalBsmtSF
    Heating
    HeatingQC
    CentralAir
    Electrical
    1stFlrSF
    2ndFlrSF
    LowQualFinSF
    GrLivArea
    BsmtFullBath
    BsmtHalfBath
    FullBath
    HalfBath
    BedroomAbvGr
    KitchenAbvGr
    KitchenQual
    TotRmsAbvGrd
    Functional
    Fireplaces
    FireplaceQu
    GarageType
    GarageYrBlt
    GarageFinish
    GarageCars
    GarageArea
    GarageQual
    GarageCond
    PavedDrive
    WoodDeckSF
    OpenPorchSF
    EnclosedPorch
    3SsnPorch
    ScreenPorch
    PoolArea
    PoolQC
    Fence
    MiscFeature
    MiscVal
    MoSold
    YrSold
    SaleType
    SaleCondition
    SalePrice
    0
    1
    60
    RL
    65.0
    8450
    Pave
    NaN
    Reg
    Lvl
    AllPub
    Inside
    Gtl
    CollgCr
    Norm
    Norm
    1Fam
    2Story
    7
    5
    2003
    2003
    Gable
    CompShg
    VinylSd
    VinylSd
    BrkFace
    196.0
    Gd
    TA
    PConc
    Gd
    TA
    No
    GLQ
    706
    Unf
    0
    150
    856
    GasA
    Ex
    Y
    SBrkr
    856
    854
    0
    1710
    1
    0
    2
    1
    3
    1
    Gd
    8
    Typ
    0
    NaN
    Attchd
    2003.0
    RFn
    2
    548
    TA
    TA
    Y
    0
    61
    0
    0
    0
    0
    NaN
    NaN
    NaN
    0
    2
    2008
    WD
    Normal
    208500
    1
    2
    20
    RL
    80.0
    9600
    Pave
    NaN
    Reg
    Lvl
    AllPub
    FR2
    Gtl
    Veenker
    Feedr
    Norm
    1Fam
    1Story
    6
    8
    1976
    1976
    Gable
    CompShg
    MetalSd
    MetalSd
    None
    0.0
    TA
    TA
    CBlock
    Gd
    TA
    Gd
    ALQ
    978
    Unf
    0
    284
    1262
    GasA
    Ex
    Y
    SBrkr
    1262
    0
    0
    1262
    0
    1
    2
    0
    3
    1
    TA
    6
    Typ
    1
    TA
    Attchd
    1976.0
    RFn
    2
    460
    TA
    TA
    Y
    298
    0
    0
    0
    0
    0
    NaN
    NaN
    NaN
    0
    5
    2007
    WD
    Normal
    181500
    2
    3
    60
    RL
    68.0
    11250
    Pave
    NaN
    IR1
    Lvl
    AllPub
    Inside
    Gtl
    CollgCr
    Norm
    Norm
    1Fam
    2Story
    7
    5
    2001
    2002
    Gable
    CompShg
    VinylSd
    VinylSd
    BrkFace
    162.0
    Gd
    TA
    PConc
    Gd
    TA
    Mn
    GLQ
    486
    Unf
    0
    434
    920
    GasA
    Ex
    Y
    SBrkr
    920
    866
    0
    1786
    1
    0
    2
    1
    3
    1
    Gd
    6
    Typ
    1
    TA
    Attchd
    2001.0
    RFn
    2
    608
    TA
    TA
    Y
    0
    42
    0
    0
    0
    0
    NaN
    NaN
    NaN
    0
    9
    2008
    WD
    Normal
    223500
    3
    4
    70
    RL
    60.0
    9550
    Pave
    NaN
    IR1
    Lvl
    AllPub
    Corner
    Gtl
    Crawfor
    Norm
    Norm
    1Fam
    2Story
    7
    5
    1915
    1970
    Gable
    CompShg
    Wd Sdng
    Wd Shng
    None
    0.0
    TA
    TA
    BrkTil
    TA
    Gd
    No
    ALQ
    216
    Unf
    0
    540
    756
    GasA
    Gd
    Y
    SBrkr
    961
    756
    0
    1717
    1
    0
    1
    0
    3
    1
    Gd
    7
    Typ
    1
    Gd
    Detchd
    1998.0
    Unf
    3
    642
    TA
    TA
    Y
    0
    35
    272
    0
    0
    0
    NaN
    NaN
    NaN
    0
    2
    2006
    WD
    Abnorml
    140000
    4
    5
    60
    RL
    84.0
    14260
    Pave
    NaN
    IR1
    Lvl
    AllPub
    FR2
    Gtl
    NoRidge
    Norm
    Norm
    1Fam
    2Story
    8
    5
    2000
    2000
    Gable
    CompShg
    VinylSd
    VinylSd
    BrkFace
    350.0
    Gd
    TA
    PConc
    Gd
    TA
    Av
    GLQ
    655
    Unf
    0
    490
    1145
    GasA
    Ex
    Y
    SBrkr
    1145
    1053
    0
    2198
    1
    0
    2
    1
    4
    1
    Gd
    9
    Typ
    1
    TA
    Attchd
    2000.0
    RFn
    3
    836
    TA
    TA
    Y
    192
    84
    0
    0
    0
    0
    NaN
    NaN
    NaN
    0
    12
    2008
    WD
    Normal
    250000Id열, 목표 변수SalePrice열, 특징량은 79개로 총 81열이다.
    train.shape
    # (1460, 81)
    

    데이터 정리


    우선,dabl을 사용하여 간단한 데이터 세척을 진행합니다.
    train_clean = dabl.clean(train, verbose=1)
    
    Detected feature types:
    3 float, 35 int, 43 object, 0 date, 0 other
    Interpreted as:
    continuous      19
    dirty_float      0
    low_card_int     6
    categorical     43
    date             0
    free_string      0
    useless         13
    dtype: int64
    
    는 데이터의 유형에서 적당한 전환을 한 것 같다.
    세탁된 데이터 좀 볼게요.
    train_clean.head()
    
    MSSubClass
    MSZoning
    LotFrontage
    LotArea
    Alley
    LotShape
    LandContour
    LotConfig
    LandSlope
    Neighborhood
    Condition1
    BldgType
    HouseStyle
    OverallQual
    OverallCond
    YearBuilt
    YearRemodAdd
    RoofStyle
    Exterior1st
    Exterior2nd
    MasVnrType
    MasVnrArea
    ExterQual
    ExterCond
    Foundation
    BsmtQual
    BsmtCond
    BsmtExposure
    BsmtFinType1
    BsmtFinSF1
    BsmtFinType2
    BsmtFinSF2
    BsmtUnfSF
    TotalBsmtSF
    HeatingQC
    CentralAir
    Electrical
    1stFlrSF
    2ndFlrSF
    GrLivArea
    BsmtFullBath
    BsmtHalfBath
    FullBath
    HalfBath
    BedroomAbvGr
    KitchenQual
    TotRmsAbvGrd
    Functional
    Fireplaces
    FireplaceQu
    GarageType
    GarageYrBlt
    GarageFinish
    GarageCars
    GarageArea
    PavedDrive
    WoodDeckSF
    OpenPorchSF
    EnclosedPorch
    ScreenPorch
    PoolQC
    Fence
    MiscFeature
    MoSold
    YrSold
    SaleType
    SaleCondition
    SalePrice
    0
    60
    RL
    65.0
    8450
    NaN
    Reg
    Lvl
    Inside
    Gtl
    CollgCr
    Norm
    1Fam
    2Story
    7
    5
    2003
    2003
    Gable
    VinylSd
    VinylSd
    BrkFace
    196.0
    Gd
    TA
    PConc
    Gd
    TA
    No
    GLQ
    706
    Unf
    0
    150
    856
    Ex
    Y
    SBrkr
    856
    854
    1710
    1
    0
    2
    1
    3
    Gd
    8
    Typ
    0
    NaN
    Attchd
    2003.0
    RFn
    2
    548
    Y
    0
    61
    0
    0
    NaN
    NaN
    NaN
    2
    2008
    WD
    Normal
    208500
    1
    20
    RL
    80.0
    9600
    NaN
    Reg
    Lvl
    FR2
    Gtl
    Veenker
    Feedr
    1Fam
    1Story
    6
    8
    1976
    1976
    Gable
    MetalSd
    MetalSd
    None
    0.0
    TA
    TA
    CBlock
    Gd
    TA
    Gd
    ALQ
    978
    Unf
    0
    284
    1262
    Ex
    Y
    SBrkr
    1262
    0
    1262
    0
    1
    2
    0
    3
    TA
    6
    Typ
    1
    TA
    Attchd
    1976.0
    RFn
    2
    460
    Y
    298
    0
    0
    0
    NaN
    NaN
    NaN
    5
    2007
    WD
    Normal
    181500
    2
    60
    RL
    68.0
    11250
    NaN
    IR1
    Lvl
    Inside
    Gtl
    CollgCr
    Norm
    1Fam
    2Story
    7
    5
    2001
    2002
    Gable
    VinylSd
    VinylSd
    BrkFace
    162.0
    Gd
    TA
    PConc
    Gd
    TA
    Mn
    GLQ
    486
    Unf
    0
    434
    920
    Ex
    Y
    SBrkr
    920
    866
    1786
    1
    0
    2
    1
    3
    Gd
    6
    Typ
    1
    TA
    Attchd
    2001.0
    RFn
    2
    608
    Y
    0
    42
    0
    0
    NaN
    NaN
    NaN
    9
    2008
    WD
    Normal
    223500
    3
    70
    RL
    60.0
    9550
    NaN
    IR1
    Lvl
    Corner
    Gtl
    Crawfor
    Norm
    1Fam
    2Story
    7
    5
    1915
    1970
    Gable
    Wd Sdng
    Wd Shng
    None
    0.0
    TA
    TA
    BrkTil
    TA
    Gd
    No
    ALQ
    216
    Unf
    0
    540
    756
    Gd
    Y
    SBrkr
    961
    756
    1717
    1
    0
    1
    0
    3
    Gd
    7
    Typ
    1
    Gd
    Detchd
    1998.0
    Unf
    3
    642
    Y
    0
    35
    272
    0
    NaN
    NaN
    NaN
    2
    2006
    WD
    Abnorml
    140000
    4
    60
    RL
    84.0
    14260
    NaN
    IR1
    Lvl
    FR2
    Gtl
    NoRidge
    Norm
    1Fam
    2Story
    8
    5
    2000
    2000
    Gable
    VinylSd
    VinylSd
    BrkFace
    350.0
    Gd
    TA
    PConc
    Gd
    TA
    Av
    GLQ
    655
    Unf
    0
    490
    1145
    Ex
    Y
    SBrkr
    1145
    1053
    2198
    1
    0
    2
    1
    4
    Gd
    9
    Typ
    1
    TA
    Attchd
    2000.0
    RFn
    3
    836
    Y
    192
    84
    0
    0
    NaN
    NaN
    NaN
    12
    2008
    WD
    Normal
    250000
    usels로서의 13열이 삭제되었습니다.
    train_clean.shape
    # (1460, 68)
    
    삭제된 열을 확인합니다.
    set(train.columns) - set(train_clean.columns)
    # {'3SsnPorch', 'Condition2', 'GarageCond', 'GarageQual', 'Heating', 'Id', 'KitchenAbvGr', 'LowQualFinSF', 'MiscVal', 'PoolArea', 'RoofMatl', 'Street', 'Utilities'}
    

    유형의 검측


    dabl도 각 특징량의 유형을 측정할 수 있다.
    dabl.detect_types(train)
    
    continuous
    dirty_float
    low_card_int
    categorical
    date
    free_string
    useless
    Id
    False
    False
    False
    False
    False
    False
    True
    MSSubClass
    False
    False
    True
    False
    False
    False
    False
    MSZoning
    False
    False
    False
    True
    False
    False
    False
    LotFrontage
    True
    False
    False
    False
    False
    False
    False
    LotArea
    True
    False
    False
    False
    False
    False
    False
    Street
    False
    False
    False
    False
    False
    False
    True
    Alley
    False
    False
    False
    True
    False
    False
    False
    LotShape
    False
    False
    False
    True
    False
    False
    False
    LandContour
    False
    False
    False
    True
    False
    False
    False
    Utilities
    False
    False
    False
    False
    False
    False
    True

    시각화


    다음은 다블을 통해 가시화됩니다.
    대상 변수SalePrice를 시각화합니다.
    dabl.plot(train, 'SalePrice')
    

    한 줄에 여러 개의 도표를 출력했다.
    목표 변수의 분포뿐만 아니라 디지털 변수, 유형 변수와 목표 변수의 관계도 가시화된다.

    배우다


    마지막으로 다블로 모형을 배웁니다.
    model = dabl.SimpleRegressor(random_state=0)
    X = train_clean.drop("SalePrice", axis=1)
    y = train_clean.SalePrice
    model.fit(X, y)
    
    Running DummyRegressor()
    r2: -0.013 neg_mean_squared_error: -6332779880.688
    === new best DummyRegressor() (using r2):
    r2: -0.013 neg_mean_squared_error: -6332779880.688
    
    Running DecisionTreeRegressor(max_depth=1)
    r2: 0.450 neg_mean_squared_error: -3448402932.386
    === new best DecisionTreeRegressor(max_depth=1) (using r2):
    r2: 0.450 neg_mean_squared_error: -3448402932.386
    
    Running DecisionTreeRegressor(max_depth=5)
    r2: 0.755 neg_mean_squared_error: -1534411175.119
    === new best DecisionTreeRegressor(max_depth=5) (using r2):
    r2: 0.755 neg_mean_squared_error: -1534411175.119
    
    Running Ridge(alpha=10)
    r2: 0.844 neg_mean_squared_error: -1007546259.414
    === new best Ridge(alpha=10) (using r2):
    r2: 0.844 neg_mean_squared_error: -1007546259.414
    
    Running Lasso(alpha=10)
    r2: 0.714 neg_mean_squared_error: -1926613454.120
    
    Best model:
    Ridge(alpha=10)
    Best Scores:
    r2: 0.844 neg_mean_squared_error: -1007546259.414
    SimpleRegressor(random_state=0)
    
    여러 모델에서 점수를 배우고 비교한 다음에 점수가 가장 좋은 모델을 나에게 돌려준다.

    총결산

  • dabl은 교사로서 학습을 간소화할 수 있는 기본 임무
  • 가시화 용이
  • 참고 자료

  • Welcome to dabl, the Data Analysis Baseline Library — dabl documentation
  • dabl/dabl: Data Analysis Baseline Library
  • Automating Data Science with dabl | Data Science and Machine Learning | Kaggle
  • 데이터 분석을 쉽게 할 수 있는dabl을 사용해 보았습니다.
  • 좋은 웹페이지 즐겨찾기