hi, i know there are only 3 lines code to use a existing machine learning model, how are…
- User
hi, i know there are only 3 lines code to use a existing machine learning model, how are them for a cnn in tensorflow?
- Assistant
- User
thank you, but i want to train the model my self, so far i used the mlp model from sklearn, but now i will use my test/train - X/y data for cnn
- Assistant
- User
my y datas are typeIds!
- Assistant
- User
how can i predict?
- Assistant
- User
and score?
- Assistant
- User
ValueError: Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 784)
- Assistant
The error message you're encountering suggests that the model expects input with a minimum of 4 dimensions, but it's receiving input with only 2 dimensions. This situation is common when working with Convolutional Neural Networks (CNNs) in TensorFlow/Keras, as CNNs expect input data in the form of a 4D tensor - .
- User
precision = precision_score(trainTestData['test']['y'], predicted_classes, average='weighted') ValueError: Found input variables with inconsistent numbers of samples: [188, 93]
- Assistant
- User
Step 1 results: [93 28 28 1]
- Assistant
Given the step 1 results you've shared, it looks like your test dataset () consists of 93 samples, where each sample is an image of size 28x28 pixels with 1 channel (likely grayscale images). This confirms the size of your input features for the test set.
- User
(93, 28, 28, 1) (93,) (93, 28, 28, 1) (188,)
- Assistant
- User
Precision: 0.6015, Recall: 0.5914, F1 Score: 0.5962 12: 59.62063
- Assistant
- User
[12, 13, 12, 12, 13, 12, 13, 12, 12, 12, 12, 12, 12, 13, 13, 12, 12, 12, 12, 12, 12, 13, 12, 12, 13, 12, 12, 12, 13, 13, 12, 13, 12, 12, 12, 12, 13, 13, 12, 12, 12, 12, 12, 12, 13, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 12, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 13, 12, 13, 12, 12, 12, 13, 12, 12, 13, 13, 12, 12, 12, 13, 13, 12, 13, 12, 12, 12, 12, 13, 12, 12, 12, 12, 12, 13, 12, 12, 12, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 13, 12, 12, 12, 13, 12, 12, 12, 12, 12, 13, 13, 12, 13, 12, 13, 13, 12, 12, 12, 12, 12, 12, 13, 13, 12, 12, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 13, 12, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 12, 12, 12, 12, 13, 12, 12, 12, 12, 12, 13, 13, 12, 13, 12, 12, 13, 13, 12, 12, 12] )> y_test
- Assistant
Given the list of predicted classes you've posted, along with a reference to
y_test, it seems like you are looking to evaluate the performance of a classification model using these predictions. The list seems to represent predicted class labels for a set of test data, and you're likely comparing these predictions against the actual labels () to calculate metrics like precision, recall, and F1 score. - User
def getBestTrainedMLPModel( self , maxScore ): mlp = None erreicht = False i = 1
highestModel = None highestScore = 0 while not(erreicht): trainTestData = self.getTestTrainData() mlp = MLPClassifier( hidden_layer_sizes=(27), activation='logistic', alpha=1e-4, solver='sgd', tol=1e-4, random_state=1, learning_rate_init=.1, verbose=True ) mlp.fit(trainTestData['train']['X'], trainTestData['train']['y']) score = mlp.score(trainTestData['test']['X'],trainTestData['test']['y']) print(f'{i}: {round(score*100,5)}') if score >= maxScore: erreicht = True i += 1 if score > highestScore: highestScore = score highestModel = mlp if i > 50: break; self.mlp = highestModel print(f'Höchste Score: {highestScore}') return highestModel def predictMLP( self , image, verbose=False): if self.mlp == None: print('Es kann keine Vorhersage getroffen werden, da das MLP nicht init ist!') return None predictedVirtualId = mlp.predict(image.reshape(1,-1)) predictedElement = iEM.getImageElementFromVirtualId( predictedVirtualId ) if verbose: if predictedElement == None: print(f'Vorhergesagtes Element mit VirtualId: {predictedVirtualId} wurde nicht gefunden!') else: print(f'Folgendes wurde vorhergesagt: {predictedElement.name} des Types: {predictedElement.typeName}') return predictedVirtualId - Assistant
- User
Cell In[4], line 304, in ImageElementManager.getBestTrainedKerasModel(self, maxScore) 301 i = 1 303 while True: --> 304 X_train, X_test, y_train, y_test = self.getTestTrainData() 305 model = Sequential([ 306 Dense(27, activation='logistic', input_shape=(X_train.shape[1],)), # Adjust the input shape 307 Dense(1, activation='sigmoid') # Adjust for your problem (e.g., number of classes) 308 ]) 309 model.compile(optimizer=SGD(learning_rate=0.1), loss='binary_crossentropy', metrics=['accuracy'])
ValueError: not enough values to unpack (expected 4, got 2)
- Assistant