В настоящее время я работаю над простой системой прогнозирования, где пользователю задают серию вопросов «да / нет» и на основе его ответов предварительно обученная модель (MLPClassifier) предсказывает класс и спрашивает пользователя, действительно ли он или нет. предсказание было верным. Я не уверен, возможно ли это, но я надеялся затем изменить вес предварительно обученной модели (в виде онлайн-обучения), чтобы сеть (в этом сеансе) не предсказывала то же самое класс позже. В настоящее время я просто добавляю неверные ответы в словарь, и если сеть предсказывает, что класс уже находится в черном списке, он игнорируется, однако я считаю, что подход должен быть лучше, чем этот! Мой код для классификатора:
mlp = MLPClassifier(hidden_layer_sizes=(128,), max_iter=500, alpha=1e-4,
solver='sgd', verbose=10, tol=1e-4, random_state=1,
learning_rate_init=.1, )
x_train, x_test, y_train, y_test = train_test_split(df.values[:, 0:8], df.label_idx, test_size=0.33,
random_state=42)
И код для прогнозов:
def receive_input():
responses = []
bad_guesses = []
print("Answer questions (Yes/No) or enter END to make prediction")
count = 0
while count < len(questions):
print(questions[count])
response = input().lower().strip()
if response == 'end':
break
elif response == 'yes':
responses.append(1)
elif response == 'no':
responses.append(0)
else:
print('Invalid Input')
continue
count += 1
padded_responses = np.pad(np.array(responses), (0, 8 - len(responses)), 'constant', constant_values=(0, -1))
prob_pred = mlp.predict_proba(padded_responses.reshape(1, -1)).flatten()
index = np.argmax(prob_pred)
best_score = prob_pred[index]
guess = labels[index]
if best_score > 0.8 and guess not in bad_guesses:
print('Early guess is: ' + labels[index] + ' is this right ? (Yes/No)')
correct = input()
if correct == 'Yes':
break
elif correct == 'No':
bad_guesses.append(labels[index])
pred = mlp.predict(np.array(responses).reshape(1, -1))
print('Prediction is: ' + labels[pred[0]])