본문 바로가기

2/[ Python ]48

[Error] TypeError: __init__() got an unexpected keyword argument 'extra_args' Error entire text --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[14], line 25 21 anim = animation.FuncAnimation(fig, animate, init_func=init, 22 frames=FRAMES, interval=100) 24 # call our new function to display the animation ---> 25 display_animation(anim) Cell In[13], line 3, in display_animation(anim) 1 def displ.. 2023. 5. 16.
[Pandas] DataFrame Row & Column Limitation import pandas as pd pd.set_option("display.max_row", 20) pd.set_optino("display.max_column", 10) 2023. 5. 8.
Handling "inf", "-inf" in Python Supervised Learning Accuracy를 계산하다보면, 종종 아래와 같이 inf 혹은 -inf 값을 볼 수 있다. print("Accuracy:", 100 - (100 * (abs(test_labels - test_predictions) / test_labels)).mean()) infinity의 줄임말로 값이 무한히 크다는 뜻이다. 이를 nan값으로 처리한 다음, dropna로 없애고, 구하고자하는 Accuracy를 아래와 같이 계산할 수 있다. (100 - (100 * (abs(test_labels - test_predictions) / test_labels))).replace([np.inf, -np.inf], np.nan).dropna().describe() 2022. 7. 12.
Layer ModuleWrapper has arguments in `__init__` and therefore must override `get_config` 기존 개발환경 Python 3.7.0 Tensorflow 2.5.0 위 버전에서 PC 포맷 겸, 버전을 아래와 같이 업그레이드했더니 나타난 에러이다. Python 3.9.0 Tensorflow 2.7.0 구글링하며, Stackoverflow를 보면, 모두들 하나 같이 def get_config(self): config = super().get_config().copy() config.update({ 'vocab_size': self.vocab_size, 'num_layers': self.num_layers, 'units': self.units, 'd_model': self.d_model, 'num_heads': self.num_heads, 'dropout': self.dropout, }) return c.. 2022. 7. 5.
ImportError: IProgress not found ipywidgets.readthedocs.io/en/stable/user_install.html Installation — Jupyter Widgets 7.7.1 documentation In most cases, installing the Python ipywidgets package will also automatically configure classic Jupyter Notebook and JupyterLab 3.0 to display ipywidgets. With pip, do: Installing in classic Jupyter Notebook Most of the time, installing ipywidgets automa ipywidgets.readthedocs.io 위 url에 들어가.. 2022. 7. 4.
Remove Negative Values in Numeric columns in DataFrame df = data[data.select_dtypes(include = [np.number]).ge(0).all(1)] df When the DataFrame consists of Obejct, float, and DateTime, we can use "select_dtypes" to handle only numeric columns. 2022. 6. 28.
Generate Time Index using Python import pandas as pd range = pd.date_range(start = "2022-01-01", end = "2022-12-31", freq = "1min") Timeindex = pd.DataFrame(range) Timeindex.rename(columns = {Timeindex.columns[0] : "Description: Timestamp"}, inplace = True) Timeindex 2022. 3. 25.
Get a List of all Column Names in Pandas DataFrame 위와 같은 Pandas DataFrame에서 Column 이름만 쭉 보고싶을 때, 사용할 수 있는 코드가 2가지가 있다. 1. list(dataframe) 2. dataframe.columns.values.tolist() 위 코드를 사용하여 Pandas DataFrame Column들을 조회하고 Feature를 정할 수 있다. 2021. 12. 14.
Kernel Density Estimation Probability Density Functiuon (확률밀도함수, pdf) 확률밀도함수는 확률변수의 분포를 나타내는 함수로 보통 확률변수가 연속형일 때를 지칭한다. 확률밀도함수는 아래 두 가지 조건을 만족해야 한다. 1. 모든 실수값 x에 대해 f(x) ≥ 0 2. ∫f(x)dx = 1 위 조건에서 알 수 있듯이 확률밀도함수는 확률이 아니며, 확률밀도함수를 적분해야 확률을 알 수 있다. Probability Density (확률밀도) 확률밀도는 X = x0일 때 확률밀도함수(f(x0))값을 의미한다. 따라서 확률밀도함수는 분포의 형태를 어떻게 정의하는지에 따라 1 이상의 값이 나올 수 있다. 연속형 확률변수 X를 정의했을 때 P(X = x0)은 연속 구간에서는 취할 수 있는 무수히 많은 경우의 수가 .. 2021. 11. 3.
[matplotlib] 같은 x축 내 서로 다른 y축 2개 그래프 표기하기 위 그림과 같이 x축 시간열은 같지만, y축 범위가 다른 데이터를 표기하는 코드이다. 2021. 10. 22.
Pandas Column 순서 변경 열이 한 두개가 아닌 많은 Column의 순서를 바꾸고 싶을 때 Slice를 사용하여 원하는 순서대로 만들기 가능 위와 같던 열의 순서를 아래 Slice를 이용하여 아래와 같이 순서 변경 가능 2021. 10. 21.
[NumPy] numpy function numpy random module numpy output option setting numpy zeros, ones 2021. 1. 28.
Kernel(커널) 수식에 n차원 행렬이 있을 경우 단순하게 처리하고자할 때 사용하는 방법 Z.β) 수식에 n차원 행렬이 있을경우, (1 x n) (n x 1)로 만들어서 쉽게 수식을 해결하는 방법을 Kernel이라고 한다. 2020. 12. 21.
matplotlib Graph 2020. 12. 8.
%matplotlib inline # 주피터 노트북의 매직 명령 hist() Method는 matplotlib을 사용하고 결국 화면에 그래프를 그리기 위해 사용자 컴퓨터의 그래픽 백엔드를 필요로 한다. 그래서 그래프를 그리기 전에 matplotlib이 사용할 백엔드를 지정해줘야 한다. 주피터의 매직 명령 %matplotlib inline을 사용하면 편리하다. 이 명령은 matplotlib이 주피터 자체의 백엔드를 사용하도록 설정한다. 그러면 그래프는 노트북 안에 그려지게 된다. 주피터 노트북에서 그래프를 그릴 때 show() Method를 호출하는 것은 선택 사항이다. 주피터는 셀이 실행될 때 자동으로 그래프를 그려준다. 2020. 12. 8.