본문 바로가기

scikit-learn7

Scikit-Learn(사이킷런) 코드 완벽 분석 - Linear Regression csv 파일 이용하기 Scikit learn의 예시가 대부분 데이터를 만들거나 내장 데이터셋을 이용하기 때문에 실제 csv파일을 가지고 ML 예제를 다뤄보겠습니다. import matplotlib.pyplot as plt import numpy as np import pandas as pd from sklearn import datasets, linear_model from sklearn.metrics import mean_squared_error, r2_score %matplotlib inline 필요한 모듈을 가져옵니다. 내장 데이터셋의 디렉토리를 찾아 csv파일을 찾고 저장을 했는데 처리가 필요할 거 같습니다. 깔끔하게 정리해주고 X_2로 저장했습니다. diabetes_X = pd.read_csv('X_2.csv', e.. 2019. 10. 24.
Scikit-Learn(사이킷런) 코드 완벽 분석 - Tree Regression # Import the necessary modules and libraries import numpy as np from sklearn.tree import DecisionTreeRegressor import matplotlib.pyplot as plt 필요한 모듈을 가져옵니다. DecisionTreeRegressor DecisionTreeRegressor에 대한 설명은 위와 같습니다. 주로 max_depth 즉, 트리 깊이를 제한하여 과대 적합을 막습니다. 또 다른 방법으로 max_leaf_nodes 또는 min_samples_leaf 중 하나만 지정해도 과대 적합을 막을 수 있습니다. # Create a random dataset rng = np.random.RandomState(1) X = np... 2019. 10. 22.
Scikit-Learn(사이킷런) 코드 완벽 분석 - Linear Regression OLS, Ridge Variance 비교 # Code source: Gaël Varoquaux # Modified for documentation by Jaques Grobler # License: BSD 3 clause 코드 소스와 저작권은 위와 같음을 밝힙니다. import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model 필요한 모듈을 가져옵니다. X_train = np.c_[.5, 1].T y_train = [.5, 1] X_test = np.c_[0, 2].T X_train, y_train, X_test에 해당하는 데이터를 만들어줍니다. np.c_[.5, 1] 1 X 2 행렬을 만들고 np.c_[.5, 1].T 2 X 1 행렬로 전치해줍니다. y_t.. 2019. 10. 21.
Scikit-Learn(사이킷런) 코드 완벽 분석 - Linear Regression Lasso import numpy as np import matplotlib.pyplot as plt %matplotlib inline from sklearn.metrics import r2_score 필요한 모듈을 가져옵니다. # ############################################################################# # Generate some sparse data to play with np.random.seed(42) n_samples, n_features = 50, 100 X = np.random.randn(n_samples, n_features) # Decreasing coef w. alternated signs for visualization idx =.. 2019. 10. 18.