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
- 개성국밥
- mp4fpsmod
- vfr video
- VARCHAR (1)
- taint
- python
- 티스토리챌린지
- preemption #
- 코루틴 컨텍스트
- 오블완
- 코루틴 빌더
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- JanusWebRTC
- 달인막창
- pytest
- PytestPluginManager
- k8s #kubernetes #쿠버네티스
- JanusGateway
- 자원부족
- table not found
- Spring Batch
- Value too long for column
- 겨울 부산
- kotlin
- PersistenceContext
- 깡돼후
- terminal
- JanusWebRTCServer
- tolerated
- JanusWebRTCGateway
Archives
너와 나의 스토리
VotingClassifier.fit "The estimator KerasClassifier should be a classifier" 문제 해결 본문
Data Analysis/Machine learning
VotingClassifier.fit "The estimator KerasClassifier should be a classifier" 문제 해결
노는게제일좋아! 2020. 5. 3. 16:49반응형
import numpy as np
from keras.models import Sequential
from keras import layers
#from keras.optimizers import SGD
from keras import optimizers
from keras.layers import Activation,BatchNormalization, Dropout, Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.ensemble import VotingClassifier
from mlxtend.classifier import EnsembleVoteClassifier
def make_model(dense):
N = len(white_wine)
n_in=11
n_hiddens=32
n_out=11
p_keep=0.5 # 드롭아웃 확률의 비율
model = Sequential()
model.add(Dense(dense,input_dim=n_in))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dense(dense))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dense(dense))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dense(dense))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(layers.Dense(units=n_out,activation='softmax'))
sgd = optimizers.SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True)
#model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.compile(loss='sparse_categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
return model
epochs = 100
batch_size =150
# 서로 다른 모델을 만들어 합치기 (Model Ensemble)
model1 = KerasClassifier(build_fn=make_model(500),epochs=epochs, verbose=0)
model2 = KerasClassifier(build_fn=make_model(100),epochs=epochs, verbose=0)
model3 = KerasClassifier(build_fn=make_model(50),epochs=epochs, verbose=0)
ensemble_model=VotingClassifier(estimators = [('model1', model1), ('model2', model2), ('model3', model3)], voting = 'soft')
#ensemble_model= EnsembleVoteClassifier(clfs=[model1,model2,model3],weights=[1,1,1],voting='soft')
# Whole Wine Classifier
#y_pred = ensemble_model.predict(x_test)
ensemble_model.fit(x_train, y_train)
test_loss, test_acc = ensemble_model.evaluate(x_test,y_test)
print("Whole Wine Classifier")
print("test loss: ", test_loss)
print("test accuracy: ", test_acc)
해결 방법:
[model1._estimator_type="classifier"] 추가해주면 됨
model1 = KerasClassifier(build_fn=make_model(500),epochs=epochs, verbose=0)
model1._estimator_type="classifier"
model2 = KerasClassifier(build_fn=make_model(100),epochs=epochs, verbose=0)
model2._estimator_type="classifier"
model3 = KerasClassifier(build_fn=make_model(50),epochs=epochs, verbose=0)
model3._estimator_type="classifier"
반응형
'Data Analysis > Machine learning' 카테고리의 다른 글
VotingClassifier.fit "Please change the shape of y to (n_samples, ), for example using ravel()" 문제 해결 (0) | 2020.05.03 |
---|---|
[ML] Bootstrap / Bagging (0) | 2019.09.16 |
[ML] Online bagging (0) | 2019.09.16 |
[ML] 'Robust Random Cut Forest for anomaly detection' 설명 및 library (Online Anomaly Detection) (0) | 2019.09.09 |
Amazon SageMaker / Jupyter 노트북 인스턴스 생성 및 실행 / 커널 설치 / mxnet_p36 (0) | 2019.09.09 |
Comments