我正在尝试运行随机森林分类器,在 test_train_split 之后,当我运行它时会生成一个错误,即样本数与样本不匹配。我有 960 行和 26 列。
X=pd.read_csv('csv',delimiter=',',sep=",",quotechar='"',header=None,quoting=2,error_bad_lines=False,na_values="")
X=X.drop([0,2,4,5],axis=1)
X= X.fillna('')
X= X[0:961].astype("int")
features= X.columns
Y= X[27] #my labels
Y= Y[0:961].astype("int") # Converting datatype string to int
Y=Y[np.isfinite(X[27])] # Remove NAN values from my label Y
x_train,y_train,x_test,y_test=train_test_split(X,Y,test_size=0.3)
clf = RandomForestClassifier(n_estimators=50,max_depth=3)
clf.fit(x_train,y_train)
相关分类