LightGBM에서 plot_tree()에서 에러가 나서, 해당 트리 모형을 수기로 그리는 것 이외에는 별다른 방법이 없다.

아래가 찾고 찾아서 만든 트리 모델 정보 가져오는  코드를 설명해주는 사이트이다. 아래 코드에서 clf.booster_trees_to_dataframe() 는 작동하지 않는다.

 

https://stackoverflow.com/questions/71305141/is-there-a-way-to-get-tree-data-as-a-list-with-the-lightgbm-classifier

 

Is there a way to get tree data as a list with the LightGBM Classifier

In random forest type models, there is usually an attribute like "estimators" which returns all the tree split as a list of lists. I can't seem find something similar with lightgbm. The c...

stackoverflow.com

 

반응형

 Python dataframe의 경우, SQL과는 달리 인덱스와 시리즈라는 것이 존재한다. 그래서 특정 조건을 걸어서 스트링을 잘라내는 것은 가능하나 그것을 날짜로 변환하는 것은 별도의 문제가 된다.

 

for col in dt_list:

    if col != 'PROC_YYMM':

        temp[col + '_MCN'] = 99999999

        for i in temp[temp[col] != '17010101'].index:

            print(col, pd.to_datetime(temp.at[i, col], format='%Y%m%d').year)

            temp.at[i, col + '_MCN'] = pd.to_datetime(temp.at[i, col], format='%Y%m%d').year

 

 

https://kongdols-room.tistory.com/117

 

패스트 인덱싱(.at, .iat)-pandas(15)

파이썬 버전 3.7 기준 pandas 버전 0.25.1 기준  패스트 인덱싱(at, iat) 본 포스팅에서는 .at 및 .iat 메서드를 다루도록한다.  .at 및 .iat 메서드 대괄호[ ]를 사용한 인덱싱은 많은 입력을 받을 수 있다.

kongdols-room.tistory.com

 

 

반응형

 메모리 dd1 ~ dd10이라는 객체가 있다고 가정하고 이 객체들을 모두 삭제해야 한다고 하면, loop로 돌리는 것이 가장 간단할 것으로 생각된다. SAS의 경우야 쉽게 매크로를 만들면 되니까.

 

for i in ragnge(1, 11):

    print(i) # loop 체크 용도

    del globals()['del{0}'.format(i)]

 

이렇게 하면 간단하게 객체들을 삭제할 수 있다. 파이썬에서 동적으로 변수를 생성할 수 있는 방법을 알 수 있다면, 참 편리하게 많은 일을 할 수 있다. 

 

 동적 변수 생성을 위한 좋은 글이 있어서 링크를 걸어본다.

 

https://congcoding.tistory.com/55

 

파이썬 동적으로 변수 생성하기 (for문으로 변수 생성, locals(), globals())

1. locals()함수와 globals()함수 파이썬에서 동적으로 변수를 생성하려면 locals()함수나 globals()함수를 사용해야 합니다. locals()함수는 현재 local변수들을 딕셔너리형태로 return합니다. globals()함수는..

congcoding.tistory.com

 

 

반응형

 

 

1. 차트 시각화

https://wikidocs.net/92087

2. 자료 : proc transpoe

 https://stackoverflow.com/questions/45596576/python-pandas-proc-transpose-equivalent

 

Python Pandas Proc Transpose Equivalent

I have a sas proc transpose i'm trying to replicate in pandas. Here is an example: ID = ['ID1', 'ID1', 'ID1', 'ID1', 'ID1'] obs_week = [201701,201701,201701,201701,201701] weeks_id = [1,2,3,4,5] ...

stackoverflow.com

 

3. Seaborn - SNS

https://seaborn.pydata.org/generated/seaborn.lineplot.html

 

seaborn.lineplot — seaborn 0.11.2 documentation

How to draw the legend. If “brief”, numeric hue and size variables will be represented with a sample of evenly spaced values. If “full”, every group will get an entry in the legend. If “auto”, choose between brief or full representation based o

seaborn.pydata.org

 

 

4. seaborn : size 조정

 

https://chunggaeguri.tistory.com/entry/Data-Analysis-seaborn-figure-%EC%82%AC%EC%9D%B4%EC%A6%88-%EC%A1%B0%EC%A0%88%ED%95%98%EB%8A%94-%EB%B2%95

 

 

반응형

filename='C:/Users/haesaekju/OneDrive/Documents/PyData/P00000001-ALL.csv'
chunksize=2 * 10 ** 5
for cnt, chunk in enumerate(pd.read_csv(filename, chunksize=chunksize)):
    #preprocessing(chunk)
    chunk.to_csv('str_' + str(cnt) + '.csv', header=['cmte_id','cand_id','cand_nm','contbr_nm','contbr_city','contbr_st','contbr_zip','contbr_employer','contbr_occupation','contb_receipt_amt','contb_receipt_dt','receipt_desc','memo_cd','memo_text','form_tp','file_num'])
    if cnt >= 10:
        break

 

 

반응형

 Python을 갖고 보고서 작성하고 그러면서 가장 고민했던 것이 바로 밑에 것. SAS보다는 Impala/Hive에서 많이 사용했던 row_number over (partition by order by) 기능을 Python에서 해보려고 고민하다가 아래 기능을 봤다. 최근에는 팀원들 불만 때문에 회사에서는 SAS -> Python Pandas 변환을 멈췄더니, 판다스 기능도 가끔씩 까먹고는 한다. 예전과는 달리 업무로 인해서 코딩을 하지 않는 경우에는 익히는 것도 빠르지만 까먹는 것도 아주 빠르다.

 

 그래도 파이썬이 많이 익숙해져서 다행이라고 생각해야지.

https://stackoverflow.com/questions/17775935/sql-like-window-functions-in-pandas-row-numbering-in-python-pandas-dataframe

반응형

+ Recent posts