Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- vfr video
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- 달인막창
- JanusGateway
- pytest
- terminal
- kotlin
- table not found
- Value too long for column
- JanusWebRTCGateway
- Spring Batch
- VARCHAR (1)
- python
- 코루틴 컨텍스트
- PersistenceContext
- 자원부족
- 티스토리챌린지
- 개성국밥
- PytestPluginManager
- mp4fpsmod
- JanusWebRTCServer
- 코루틴 빌더
- JanusWebRTC
- tolerated
- preemption #
- addhooks
- 오블완
- 깡돼후
- 겨울 부산
- taint
Archives
너와 나의 스토리
Random forest regression 실습 1 본문
반응형
[Dataset]
1. importing
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_csv('./input/Position_Salaries.csv')
2. Asigning the input and output values
X=df.iloc[:,1].values
y=df.iloc[:,2].values
3. Fitting Random Forest Regression to the dataset
from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor(n_estimators = 10, random_state = 0)
regressor.fit(X.reshape(-1,1), y.reshape(-1, 1))
n_estimators: 모형 개수 -> 트리 개수
random_state: If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. (참조)
4. Predicting a new result
y_pred = regressor.predict([[6.5]])
y_pred
출력: array([167000.])
* [[6.5]]가 의미하는게 뭐지.....?
5. Visualising the Random Forest Regression results (higher resolution)
X_grid = np.arange(min(X),max(X),0.01) # X의 최소값부터 X의 최대값까지 0.01 단위로 값 채우기
X_grid=X_grid.reshape((len(X_grid),1)) # n X 1 행렬로 변환
plt.scatter(X,y, color='red')
plt.plot(X_grid, regressor.predict(X_grid),color='blue')
plt.title('Truth or Bluff (Random Forest Regression)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
반응형
'Data Analysis > Machine learning' 카테고리의 다른 글
[ML] Mondrian Forest (0) | 2019.09.02 |
---|---|
[ML] 푸아송 분포(Poisson distribution) (0) | 2019.08.27 |
[ML] Random Forest Regression (0) | 2019.08.19 |
[ML] Expert system vs Machine learning (0) | 2019.08.19 |
[ML] Nonparametric vs Parametric statistics (0) | 2019.08.19 |
Comments