python(17)
-
[ML_3] cross_validation
1. Cross validation이란 말 그대로 교차 검증을 뜻한다. 기존에는 dataset을 train과 test로 한 번만 나누고, train 데이터로 학습한 뒤 test 데이터로 평가를 진행했다. 그러나 이 방법은 데이터 분할에 따라 성능 평가가 달라질 수 있고, 모델이 학습 데이터에 과도하게 적합되어(overfitting) 새로운 데이터에 대한 성능이 떨어질 위험이 있다. 이러한 문제를 완화하기 위해, 데이터를 여러 번 분할해 반복적으로 학습과 평가를 수행하는 방식이 필요하게 되었고, 이를 Cross validation이라 부른다. 교차 검증은 전체 데이터를 여러 fold로 나누어 매번 다른 부분을 검증 데이터로 사용하고, 나머지를 학습 데이터로 활용해 평가를 반복하는 방식이다. 이렇게 하면 데..
2025.07.12 -
[Python] Module에대한 이해
Module이란? 하나의 source code file을 그냥 module이라고 한다. 이 source file에는 함수가 들어있거나 프로그램의 일부를 담당할 때 module이라고 부르기도 한다. 어떤 함수를 만들었는데 한 번만 쓰고 버리기 아깝다면?. py 파일을 만들어서 다음에 쓰고 싶을 때 불러오면 된다. 이런 식으로 module을 사용한다. Module을 만들어보자. # module_ex.py def add_two_values(a,b): return a + b def multiple_two_values(a,b): return a * b위의 두 함수를 module_ex.py 파일로 저장해 둔다. 이제 add_two_values, multiple_two_values를 다른 파일에서 불러와 써보자..
2025.07.12 -
[ML_2] Let's convert pd.Dataframe to train_test dataset.
What if our dataset is a pd.DataFrame? In this case, we convert the DataFrame into a training dataset using the following code.from sklearn.datasets import load_iris from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split import pandas as pd iris_df = pd.DataFrame(iris_data.data, columns = iris_data.feature_n..
2025.07.10 -
[ML_1] Let's make iris classification model by Scikitlearn
First, we import the necessary modules:import sklearn from sklearn.datasets import load_iris from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_splitimport pandas as pd We start by importing the scikit-learn library (sklearn) along with the datasets module, the Decision Tree algorithm, and the train_test_split utility. We also import pandas for handlin..
2025.07.09 -
[numpy] np.array, np.zeros, np.ones, np.reshape
1. np. array : numpy를 이용해 array 형태로 바꿔준다. 사용법은 다음과 같다. import numpy as np arr1 = np.array([1,2,3]) 2. np.zeros : numpy를 이용해 array를 만드는데 이때 값들을 0으로 초기화해 준다. import numpy as np arr1 = np.zeros((3,2),dtype='int32') 3. np.ones : numpy를 이용해 array를 만드는데 이때 값들을 1로 초기화해 준다. import numpy as np arr1 = np.ones((3,2),dtype='int32') 4. np.reshape : 기존의 array의 shape을 수정할 때 사용한다. list라는 기존의 array가 있을 때 이 list..
2025.07.09