为什么MLP分类器算法会给我一些极端值?
我正在尝试使用MLP分类器算法,想要分析过去666次从36个不同的 urn(每个 urn 里有10个编号为0到9的球)中抽取一个球的结果。但是,当我让算法给我下次抽球的每个球的期望概率时,它给出的结果却是极端值。以下是我的代码:
import numpy as np
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import StandardScaler
# Assuming your data is stored in the 'results' list
# Each sublist represents the past results for an urn
results = [
[3, 2, 7, ..., 6, 9], # Urn 1
[5, 2, ..., 0], # Urn 2
# ... (other urns)
[4, 2, 7, ..., 1, 1] # Urn 36
]
# Encode the past results as binary vectors
encoder = OneHotEncoder(categories=[range(10)] * 666, sparse=False)
X = np.vstack([encoder.fit_transform([urn]) for urn in results])
# Use the last ball drawn in each urn as the label
labels = np.array([urn[-1] for urn in results])
# Normalize the features
scaler = StandardScaler()
X_normalized = scaler.fit_transform(X)
# Initialize the MLP classifier with increased complexity
mlp = MLPClassifier(hidden_layer_sizes=(100, 100, 100), max_iter=1000, random_state=42)
# Train the model
mlp.fit(X_normalized, labels)
# Predict probabilities for each ball in the next drawing for all urns
for urn_idx, urn_results in enumerate(results):
next_drawing_probs = mlp.predict_proba(scaler.transform(encoder.transform([urn_results])))
print(f"Urn {urn_idx + 1} probabilities:")
for ball, prob in enumerate(next_drawing_probs):
print(f" Ball {ball}: {prob:.4f}")
#And here is the output for the last 2 urns (which are like the output for all the other 34 urns):
Urn 35 probabilities:
Ball 0: 0.0000
Ball 1: 0.0000
Ball 2: 0.0000
Ball 3: 0.0000
Ball 4: 0.0001
Ball 5: 0.9999
Ball 6: 0.0000
Ball 7: 0.0000
Ball 8: 0.0000
Ball 9: 0.0000
Urn 36 probabilities:
Ball 0: 0.0000
Ball 1: 0.0000
Ball 2: 0.0000
Ball 3: 0.0000
Ball 4: 0.0000
Ball 5: 0.0000
Ball 6: 0.0000
Ball 7: 0.0000
Ball 8: 0.0000
Ball 9: 0.9999
Process finished with exit code 0
我尝试增加层数(最多到1000层),但结果还是一样。我希望每个球的概率能接近0.1(最低可能是0.075,最高可能是0.125)。
1 个回答
暂无回答