신경망에 Python의 Keras를 사용할 때 유형 오류

325

신경망을 사용하여 주택 가격을 예측하려고합니다. 데이터 세트의 상단은 다음과 같습니다.

    Price   Beds    SqFt    Built   Garage  FullBaths   HalfBaths   LotSqFt
    485000  3       2336    2004    2       2.0          1.0        2178.0
    430000  4       2106    2005    2       2.0          1.0        2178.0
    445000  3       1410    1999    1       2.0          0.0        3049.0

...

다음은 신경망을 코딩하는 방법입니다 (Python의 keras 사용).

dataset = df.values
X = dataset[:,1:8]
Y = dataset[:,0]

from sklearn import preprocessing
from sklearn.model_selection import train_test_split
min_max_scaler = preprocessing.MinMaxScaler()
X_scale = min_max_scaler.fit_transform(X)
X_scale

X_train, X_val_and_test, Y_train, Y_val_and_test = train_test_split(X_scale, Y, test_size=0.3)
X_val, X_test, Y_val, Y_test = train_test_split(X_val_and_test, Y_val_and_test, test_size=0.5)
print(X_train.shape, X_val.shape, X_test.shape, Y_train.shape, Y_val.shape, Y_test.shape)

from keras.models import Sequential
from keras.layers import Dense

model = Sequential(
    Dense(32, activation='relu', input_shape=(7,)),
    Dense(1, activation='relu'))

model.compile(optimizer='sgd',
              loss='mse',
              metrics=['mean_squared_error'])

hist = model.fit(X_train, Y_train,
          batch_size=32, epochs=100,
          validation_data=(X_val, Y_val)) #Error here!

model.evaluate(X_test, Y_test)[1] #Same Error here!

hist =라인과 라인을 실행할 때 동일한 오류가 발생 model.evaluate합니다. 다음은 오류 정보입니다.

TypeError                                 Traceback (most recent call last)
<ipython-input-19-522714a352ba> in <module>
----> 1 hist = model.fit(X_train, Y_train,
      2           batch_size=32, epochs=100,
      3           validation_data=(X_val, Y_val))

~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
    106   def _method_wrapper(self, *args, **kwargs):
    107     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
--> 108       return method(self, *args, **kwargs)
    109 
    110     # Running inside `run_distribute_coordinator` already.

...

TypeError: in user code:

...

name_scope += '/'

    TypeError: unsupported operand type(s) for +=: 'Dense' and 'str'

df.dtypes원래 데이터 프레임에서 실행할 때 모든 열이 정수 또는 부동 소수점 이기 때문에 왜 이런 일이 발생하는지 잘 모르겠습니다 .

324

간단한 수정! 모델 구성에서 하드 브래킷이 누락 된 것 같습니다. 이것을 사용해보십시오 :

model = Sequential([
    Dense(32, activation='relu', input_shape=(7,)),
    Dense(1, activation='relu'),
])

도움이 되었기를 바랍니다. 더 궁금한 점이 있으면 알려주세요!

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

도커를 사용할 때 npm 설치 수신 유형 오류

분류에서Dev

mmult를 사용할 때 VBA의 유형 불일치 오류

분류에서Dev

벡터 대신 std :: deque를 사용할 때 "C2027 정의되지 않은 유형 사용"오류

분류에서Dev

유형 경계를 재정의 할 때 호환되지 않는 유형 오류

분류에서Dev

Postgres : 타임 스탬프 유형의 CSV에서 COPY를 사용할 때 오류 발생

분류에서Dev

Xcode를 사용할 때 " '이동'에 대한 유형 충돌"과 같은 오류

분류에서Dev

mode.evaluate의 Keras 신경망에서 여러 메트릭의 값을 반환하려고 할 때 오류가 발생합니다.

분류에서Dev

비교기를 사용할 때 동일한 유형에서 호환되지 않는 유형 오류

분류에서Dev

컴파일 오류를 수정하는 방법 : Outlook에서 Excel VBA를 사용할 때 정의되지 않은 사용자 정의 유형?

분류에서Dev

동일한 유형의 개체에 변수를 할당 할 때 유형 불일치 오류

분류에서Dev

신경망 패키지를 사용하는 R의 오류

분류에서Dev

인증에 AngularFireModule을 사용할 때 유형 오류

분류에서Dev

TypeScript의 'any'필드 유형 변수에 'string'함수를 사용할 때 컴파일 시간 오류가없는 이유는 무엇입니까?

분류에서Dev

SQLAlchemy 쿼리 결과를 반환 할 때 Python Flask 유형 오류

분류에서Dev

TypeError : EarlyStopping keras에서 restore_best_weights = True를 사용할 때 'NoneType'유형의 개체에 len ()이 없습니다.

분류에서Dev

Spring : REST 서비스를 사용하여 새 객체를 게시 할 때 유형 정의 오류

분류에서Dev

Springboot : REST 서비스를 사용하여 새 객체를 게시 할 때 유형 정의 오류

분류에서Dev

확립 된 theano 환경에서 keras를 사용할 때 이상한 오류

분류에서Dev

특정 유형의 사용자가 스크립트를 실행할 때 Oracle pl / sql에서 컴파일 오류를 무시하는 방법

분류에서Dev

Numba에서 클래스를 사용할 때의 서명 오류

분류에서Dev

Python에서 Matplotlib.image를 사용할 때 오류

분류에서Dev

mypy를 사용할 때 Python에서 예외 / 오류의 튜플 입력 수정

분류에서Dev

사용자 정의 icomparer 오류-사용에서 유형 인수를 유추 할 수 없습니다.

분류에서Dev

json.encode를 사용하여 PHP에서 Javascript로 배열을 전달할 때 정의되지 않은 유형 오류

분류에서Dev

Apache flink 및 Spring 부팅을 사용하여 Controller에서 View로 DataStream 유형의 개체를 전달할 때 오류 발생

분류에서Dev

jQuery Ajax를 사용할 때 하나의 div에 모든 라 라벨 유효성 검사 오류 표시

분류에서Dev

.Where in list는 2sxc에서 동적 유형을 사용할 때 오류를 제공합니다.

분류에서Dev

.Where in list는 2sxc에서 동적 유형을 사용할 때 오류를 제공합니다.

분류에서Dev

UpdateExpression 내에서 list_append 함수를 사용할 때 잘못된 피연산자 유형 오류

Related 관련 기사

  1. 1

    도커를 사용할 때 npm 설치 수신 유형 오류

  2. 2

    mmult를 사용할 때 VBA의 유형 불일치 오류

  3. 3

    벡터 대신 std :: deque를 사용할 때 "C2027 정의되지 않은 유형 사용"오류

  4. 4

    유형 경계를 재정의 할 때 호환되지 않는 유형 오류

  5. 5

    Postgres : 타임 스탬프 유형의 CSV에서 COPY를 사용할 때 오류 발생

  6. 6

    Xcode를 사용할 때 " '이동'에 대한 유형 충돌"과 같은 오류

  7. 7

    mode.evaluate의 Keras 신경망에서 여러 메트릭의 값을 반환하려고 할 때 오류가 발생합니다.

  8. 8

    비교기를 사용할 때 동일한 유형에서 호환되지 않는 유형 오류

  9. 9

    컴파일 오류를 수정하는 방법 : Outlook에서 Excel VBA를 사용할 때 정의되지 않은 사용자 정의 유형?

  10. 10

    동일한 유형의 개체에 변수를 할당 할 때 유형 불일치 오류

  11. 11

    신경망 패키지를 사용하는 R의 오류

  12. 12

    인증에 AngularFireModule을 사용할 때 유형 오류

  13. 13

    TypeScript의 'any'필드 유형 변수에 'string'함수를 사용할 때 컴파일 시간 오류가없는 이유는 무엇입니까?

  14. 14

    SQLAlchemy 쿼리 결과를 반환 할 때 Python Flask 유형 오류

  15. 15

    TypeError : EarlyStopping keras에서 restore_best_weights = True를 사용할 때 'NoneType'유형의 개체에 len ()이 없습니다.

  16. 16

    Spring : REST 서비스를 사용하여 새 객체를 게시 할 때 유형 정의 오류

  17. 17

    Springboot : REST 서비스를 사용하여 새 객체를 게시 할 때 유형 정의 오류

  18. 18

    확립 된 theano 환경에서 keras를 사용할 때 이상한 오류

  19. 19

    특정 유형의 사용자가 스크립트를 실행할 때 Oracle pl / sql에서 컴파일 오류를 무시하는 방법

  20. 20

    Numba에서 클래스를 사용할 때의 서명 오류

  21. 21

    Python에서 Matplotlib.image를 사용할 때 오류

  22. 22

    mypy를 사용할 때 Python에서 예외 / 오류의 튜플 입력 수정

  23. 23

    사용자 정의 icomparer 오류-사용에서 유형 인수를 유추 할 수 없습니다.

  24. 24

    json.encode를 사용하여 PHP에서 Javascript로 배열을 전달할 때 정의되지 않은 유형 오류

  25. 25

    Apache flink 및 Spring 부팅을 사용하여 Controller에서 View로 DataStream 유형의 개체를 전달할 때 오류 발생

  26. 26

    jQuery Ajax를 사용할 때 하나의 div에 모든 라 라벨 유효성 검사 오류 표시

  27. 27

    .Where in list는 2sxc에서 동적 유형을 사용할 때 오류를 제공합니다.

  28. 28

    .Where in list는 2sxc에서 동적 유형을 사용할 때 오류를 제공합니다.

  29. 29

    UpdateExpression 내에서 list_append 함수를 사용할 때 잘못된 피연산자 유형 오류

뜨겁다태그

보관