신경망을 사용하여 주택 가격을 예측하려고합니다. 데이터 세트의 상단은 다음과 같습니다.
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
원래 데이터 프레임에서 실행할 때 모든 열이 정수 또는 부동 소수점 이기 때문에 왜 이런 일이 발생하는지 잘 모르겠습니다 .
간단한 수정! 모델 구성에서 하드 브래킷이 누락 된 것 같습니다. 이것을 사용해보십시오 :
model = Sequential([
Dense(32, activation='relu', input_shape=(7,)),
Dense(1, activation='relu'),
])
도움이 되었기를 바랍니다. 더 궁금한 점이 있으면 알려주세요!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다