Notice
Recent Posts
Recent Comments
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 |
Tags
- 지도시각화
- json
- LatentFactorModel
- numpy.bool
- github2FA
- Colab
- TensorflowDeveloperCertificate
- BloombergMarketConcepts
- implicitData
- Visualization
- jsonlines
- Cast
- iterrows
- wordembedding
- gluonnlp
- str.replace
- session-basedRecommendation
- 텐서플로자격증
- Convert
- vscode
- ExplicitData
- jsonl
- VScodeNotResponding
- sshtunnel
- MySQL
- Python
- DIF_SR
- MatrixFactorization
- pandas
- decimal error
Archives
- Today
- Total
garret
[Python, shap] InvalidModelError: Model type not yet supported by TreeExplainer: <class 'sklearn.svm._classes.SVR'> 본문
Error
[Python, shap] InvalidModelError: Model type not yet supported by TreeExplainer: <class 'sklearn.svm._classes.SVR'>
_Sun_ 2023. 7. 4. 13:17
SVR(Support Vector Regressor) 모델에 대해 SHAP(SHapley Additive exPlanations)을 구하려다 발생한 에러.
사용한 SVR 모델은 다음과 같다.
# SVR 모델
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error
sv_reg = SVR(kernel = "linear")
sv_reg.fit(train_x,train_y)
sv_pred = sv_reg.predict(test_x)
찾아보니 SVR은 tree기반 모델이 아니라서 TreeExplainer을 사용하면 안된다고한다.
# shap value
import shap
# SVM은 Tree기반이 아니라서 TreeExplainer 사용 불가
explainer = shap.KernelExplainer(sv_reg.predict, train_x)
shap_values = explainer.shap_values(test_x) # Shap Values 계산
TreeExplainer대신에 KernelExplainer을 사용하여 에러 해결.
KernelExplainer는 TreeExplainer보다 속도가 느려서 이점 염두해 사용해야 할 거 같다.