【发布时间】:2021-01-20 05:13:13
【问题描述】:
我指的是this Random Forrest Algorithm example来预测不同阶段的拒绝。
我正在从数据库中获取 stages 和 reject_count 的值。并使用stages 值作为x 和reject_count 值作为y。
我的代码是:
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
stages = [102, 103, 104, 106]
reject_count = [1, 3, 1, 2]
li = []
li.append(stages)
l2 = []
l2.append(reject_count)
x = np.array(li)
y = np.array(reject_count)
x.shape
y.shape
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=0)
print("===============")
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
regressor = RandomForestRegressor(n_estimators=100, random_state=0)
print("x train", X_train)
print("y train", y_train)
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)
print(y_pred)
请指导我哪里做错了。
【问题讨论】:
-
请发布完整的错误跟踪
-
@desertnaut。没有完整的错误跟踪。仅获取发现样本数量不一致的输入变量:[1, 4]
-
具体在哪里?总会有痕迹的……
标签: python-3.x machine-learning scikit-learn random-forest