# python如何对两个矩阵进行拼接_新手求教：怎样把两个列向量合并成一个 n*2 的矩阵？...

import numpy as np

import pandas as pd

from sklearn.ensemble import RandomForestClassifier

from sklearn.dummy import DummyClassifier

from sklearn.svm import SVC

#from sklearn import datasets

train_features = dataframe.iloc[ :, 0:24]

train_lables = dataframe.iloc[:, 24]

test_features = test_data.iloc[ :, 0:24 ]

test_lables = test_data.iloc[ :, 24 ]

dummy = DummyClassifier( strategy = 'uniform', random_state = 1 )

dummy.fit( train_features, train_lables )

print( "dummy_score =", dummy.score( test_features, test_lables ) )

style = 1

if style == 1:

max_features = 19

n_estimators = 400

randomforest = RandomForestClassifier( max_features = max_features, n_estimators = n_estimators, random_state=1, n_jobs=-1 )

model = randomforest.fit( train_features, train_lables )

test_hat = model.predict( test_features )

test_hat1 = np.hstack( ( test_hat, test_lables ) )

test_hat1.reshape( -1, 2 )

print( test_hat1.shape )

print( test_hat1 )

print( "max_features =", max_features, "; n_estimators =", n_estimators,

"; randomforest_score =", randomforest.score( test_features, test_lables ) )

dummy_score = 0.5447976878612717

(1384,)

[0 0 1 ... 0 0 0]

max_features = 19 ; n_estimators = 400 ; randomforest_score = 0.6416184971098265

• 0
点赞
• 0
收藏
• 0
评论
12-05
11-01 528
08-18 1万+
09-22
03-26 756
04-12 2796
06-02 7620
11-14 2374
01-17 8317
06-13 7324

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助