本文整理匯總了Python中sklearn.ensemble.forest.RandomForestClassifier.pedict方法的典型用法代碼示例。如果您正苦於以下問題:Python RandomForestClassifier.pedict方法的具體用法?Python RandomForestClassifier.pedict怎麽用?Python RandomForestClassifier.pedict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.ensemble.forest.RandomForestClassifier
的用法示例。
在下文中一共展示了RandomForestClassifier.pedict方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: drawfeature
# 需要導入模塊: from sklearn.ensemble.forest import RandomForestClassifier [as 別名]
# 或者: from sklearn.ensemble.forest.RandomForestClassifier import pedict [as 別名]
def drawfeature(train_data_path='./train', train_filename='train_cleaned',test_data_path='./test', test_filename='test_cleaned'):
train_file = os.path.join(train_data_path, train_filename)
train_data = pd.read_csv(train_file)
n_train_data = train_data['text'].size
test_file = os.path.join(test_data_path,test_filename)
test_data = pd.read_csv(test_file)
n_test_data = test_data['text'].size
vectorizer = CountVectorizer(analyzer="word",tokenizer=None, preprocessor=None, stop_words=None, max_features=2000)
transformer = TfidfTransformer()
train_data_words = []
for i in xrange(n_train_data):
train_data_words.append(words_to_features(train_data['text'][i]))
train_data_features = vectorizer.fit_transform(train_data_words)
train_data_features = train_data_features.toarray()
train_data_features = transformer.fit_transform(train_data_features)
train_data_features = train_data_features.toarray()
train_data_pd=pd.Series(train_data_features,name=None)
train_data_pd.to_csv("trainfeature.csv", index=None, header=True)
test_data_words = []
for i in xrange(n_test_data):
test_data_words.append(words_to_features(test_data['text'][i]))
test_data_features = vectorizer.fit_transform(test_data_words)
test_data_features = test_data_features.toarray()
test_data_features = transformer.fit_transform(test_data_features)
test_data_features = test_data_features.toarray()
test_data_pd=pd.Series(test_data_features,name=None)
test_data_pd.to_csv("testfeature.csv", index=None, header=True)
forest = RandomForestClassifier(n_estimators=60)
forest = forest.fit(train_data_features, train_data['lable'])
pred = forest.pedict(test_data_features)
pred = pd.Series(pred,name='Target')
pred.to_csv("bow_tfidf_RF.csv", index=None, header=True)