本文整理汇总了Python中sklearn.ensemble.forest.RandomForestClassifier类的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier类的具体用法?Python RandomForestClassifier怎么用?Python RandomForestClassifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RandomForestClassifier类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: Random_Forest
def Random_Forest(x_train, Y_train,n_estimators=10, criterion='gini', max_depth=None, min_samples_split=2,
min_samples_leaf=1, max_features='auto', bootstrap=True, oob_score=False, n_jobs=1,
random_state=None, verbose=0, min_density=None, compute_importances=None, *args):
clf = RandomForestClassifier()
clf.fit(x_train,Y_train)
return clf
开发者ID:setman85,项目名称:GA_homework,代码行数:7,代码来源:randforest.py
示例2: enemy_detection_clf
def enemy_detection_clf():
chars = np.array(['warrior', 'warlock', 'mage', 'druid', 'rogue', 'shaman', 'paladin', 'priest', 'hunter'])
data = []
target = []
for c in chars:
p = path('images/character/new/black')
for f in os.listdir(p+'/'+c):
img = Image.open(p+'/'+c+'/'+f)
w, h = img.size
pixel = img.load()
tmp = []
for y in range(h):
for x in range(w):
tmp.append(np.float(pixel[x,y] / 255))
target.append(np.str(c))
data.append(np.array(tmp))
data = np.array(data)
#image = data.view()
#image.shape = (-1, 22, 30)
#clf = svm.SVC(gamma = 0.001)
clf = RandomForestClassifier()
clf.fit(data, target)
return clf
开发者ID:Emsibil,项目名称:Bachelor,代码行数:25,代码来源:Ba.py
示例3: test_RandomForest
def test_RandomForest(self):
X = [[0, 1], [1, 1]]
Y = [0, 1]
regression = RandomForestClassifier(n_estimators=10)
regression = regression.fit(X, Y)
regression.predict_proba(X)
开发者ID:lgadawski,项目名称:spdb-driver-telematics,代码行数:7,代码来源:test_driver_functions.py
示例4: rforest_classify
def rforest_classify(X,Y):
#clf = RandomForestClassifier(criterion='gini',max_features=7,n_estimators=100,n_jobs=3,min_samples_leaf=5)
clf = RandomForestClassifier(n_estimators=500, \
criterion='entropy', max_depth=None, min_samples_split=2, min_samples_leaf=1 \
,max_features='auto', bootstrap=False, oob_score=False, n_jobs=-1, min_density=None)
clf.fit(X,Y)
return clf
开发者ID:kalpanki,项目名称:pp,代码行数:8,代码来源:models.py
示例5: train_rf
def train_rf(train_vec, train_label):
from sklearn.ensemble.forest import RandomForestClassifier as RFC
# rfrclf = RFR(n_estimators=1001)
# rfrclf.fit(train_vec, train_label)
# print rfrclf.feature_importances_
trfclf = RFC(n_estimators=1001)
trfclf.fit(train_vec, train_label)
# print rfclf.feature_importances_
return trfclf
开发者ID:JayveeHe,项目名称:OpinionRankProject,代码行数:9,代码来源:amazon_process.py
示例6: __init__
def __init__(self, sig_weight=1., pow_sig=1., pow_bg=1., n_estimators=10,
criterion="gini", max_depth=None, min_samples_split=2, min_samples_leaf=1, max_features="auto",
bootstrap=True, oob_score=False, n_jobs=1, random_state=None, verbose=0, min_density=None,
compute_importances=None):
RandomForestClassifier.__init__(self)
# Everything should be set via set_params
self.sig_weight = sig_weight
self.pow_bg = pow_bg
self.pow_sig = pow_sig
开发者ID:mityinzer,项目名称:lhcb_trigger_ml,代码行数:9,代码来源:gradient_boosting_old.py
示例7: main
def main(args):
if args.analyse != None:
train_data_x, test_data_x,train_data_y, test_data_y = process_data(args.analyse)
RT = RandomForestClassifier(n_estimators=100)
RT.fit(train_data_x, train_data_y)
print RT.score(test_data_x, test_data_y)
return
开发者ID:rjgsousa,项目名称:sentiment_analysis,代码行数:10,代码来源:main.py
示例8: my_digits
def my_digits():
digits = _data()
n_samples = len(digits.images)
datas = digits.images.reshape((n_samples, -1))
classifier = RandomForestClassifier()
classifier.fit(datas, digits.target)
return classifier
开发者ID:Emsibil,项目名称:Bachelor,代码行数:10,代码来源:Ba.py
示例9: RandomForestClassifer
def RandomForestClassifer(self):
'''
Function to do RandomForest Classifer.
'''
train_Array = self.titanic_train_frame.values
self.test_Array = self.titanic_test_frame.values
randomForest = RandomForestClassifier(n_estimators = 100, n_jobs = -1)
randomForest.fit(train_Array[0::,1::],train_Array[0::,0])
self.predicted_probability = randomForest.predict(self.test_Array[0::,0::])
self.predicted_probability_list = self.predicted_probability.tolist()
开发者ID:malaikannan,项目名称:Kaggle_TitanicPredictionChallenge,代码行数:11,代码来源:TitanicPrediction_LogisticRegression.py
示例10: do_training
def do_training(processed_train_csv_file):
## Processed train samples reading
# read saved processed train samples from the given csv file
processed_train_samples = pd.read_csv(processed_train_csv_file)
# inf to nan
processed_train_samples = processed_train_samples.replace([np.inf, -np.inf], np.nan)
# nan to 0
processed_train_samples = processed_train_samples.fillna(value=0)
processed_train_samples_index_lst = processed_train_samples.index.tolist()
# 之前排过序,这里shuffle一下,效果更好
random.shuffle(processed_train_samples_index_lst)
# organize new train samples and targets
shuffled_train_samples = processed_train_samples.ix[processed_train_samples_index_lst]
col_names = shuffled_train_samples.columns.tolist()
col_names.remove("booking_bool")
features = shuffled_train_samples[col_names].values
labels = shuffled_train_samples['booking_bool'].values
# Model training
# 1 Random Forest Classifier
print("Training Random Forest Classifier")
rf_classifier = RandomForestClassifier(n_estimators=150,
verbose=2,
n_jobs=-1,
min_samples_split=10)
rf_classifier.fit(features, labels)
print("Saving the Random Forest Classifier")
data_io.save_model(rf_classifier, model_name='rf_classifier.pkl')
# 2 Gradient Boosting Classifier
print("Gradient Boosting Classifier")
gb_classifier = GradientBoostingClassifier(n_estimators=150,
verbose=2,
learning_rate=0.1,
min_samples_split=10)
gb_classifier.fit(features, labels)
print("Saving the Gradient Boosting Classifier")
data_io.save_model(gb_classifier, model_name='gb_classifier.pkl')
# 3 SGD Classifier
print("SGD Classifier")
sgd_classifier = SGDClassifier(loss="modified_huber", verbose=2,
n_jobs=-1)
sgd_classifier.fit(features, labels)
print("saved the SGD Classifier")
data_io.save_model(sgd_classifier, model_name='sgd_classifier.pkl')
开发者ID:gssgch,项目名称:gssgML,代码行数:52,代码来源:training_prediction.py
示例11: RF
def RF(pth):
train_desc=np.load(pth+'/training_features.npy')
nbr_occurences = np.sum( (train_desc > 0) * 1, axis = 0)
idf = np.array(np.log((1.0*len(image_paths)+1) / (1.0*nbr_occurences + 1)), 'float32')
# Scaling the words
stdSlr = StandardScaler().fit(train_desc)
train_desc = stdSlr.transform(train_desc)
modelRF=RandomForestClassifier(n_estimators=10,
max_depth=5,max_features=1,random_state=0)
modelRF.fit(train_desc,np.array(train_labels))
joblib.dump((modelRF, img_classes, stdSlr), pth+"/rf-bof.pkl", compress=3)
test(pth, "rf-")
开发者ID:fengxinhe,项目名称:DeviceManager,代码行数:13,代码来源:Algro.py
示例12: try_model
def try_model(train):
print(train.shape)
features = ["phone_brand", "device_model", "event_count", "action_radius_max", "medianTime", "minTime", "maxTime", "weekday", "appcounts1"]
encoder = LabelEncoder()
train["group"] = encoder.fit_transform(train["group"].values)
rf = RandomForestClassifier(n_estimators=50, max_depth=15, max_features=6, bootstrap=True, n_jobs=4, random_state=2016, class_weight=None)
rf.fit(train[features].values, train["group"].values)
feature_importance(rf, features)
skf = StratifiedKFold(train["group"].values, n_folds=5, shuffle=True, random_state=2016)
scores = cross_val_score(rf, train[features].values, train["group"].values, scoring="log_loss", cv=skf, n_jobs=1)
print(scores)
print("RF Score: %0.5f" %(-scores.mean())) # RF Score: 2.39884
开发者ID:homoroselaps,项目名称:KaggleMobileUserDemo,代码行数:15,代码来源:create_features.py
示例13: just_pred
def just_pred(x, y):
xlen = len(x)
i = range(xlen)
np.random.shuffle(i)
trainpct = 0.7
trainlen = int(trainpct * xlen)
testlen = xlen - trainlen
xtrain = x.ix[:trainlen,:]
ytrain = y.ix[:trainlen]
xtest = x.ix[trainlen:,:]
ytest = y.ix[trainlen:]
rf = RandomForestClassifier()
rf.fit(xtrain, ytrain)
ypred = rf.predict(xtest)
return ytest, ypred
开发者ID:coreyabshire,项目名称:color-names,代码行数:15,代码来源:pscvread.py
示例14: crossval
def crossval(x, y, k=5):
for i in range(k):
i = range(len(X))
np.random.shuffle(i)
xlen = len(x)
trainpct = 0.7
trainlen = int(trainpct * xlen)
testlen = xlen - trainlen
xtrain = x.ix[:trainlen,:]
ytrain = y.ix[:trainlen]
xtest = x.ix[trainlen:,:]
ytest = y.ix[trainlen:]
rf = RandomForestClassifier()
rf.fit(xtrain, ytrain)
ypred = rf.predict(xtest)
print ypred
开发者ID:coreyabshire,项目名称:color-names,代码行数:16,代码来源:pscvread.py
示例15: __init__
def __init__(self, n_estimators, max_depth, min_samples_leaf):
self.classifier = RandomForestClassifier(**{'verbose':1, 'n_estimators': n_estimators,
'max_depth':max_depth,'min_samples_leaf':min_samples_leaf,
'n_jobs':40})
self.name = "rf_n{n}_md{md}_ms{ms}".format(
**{"n": n_estimators, "md": max_depth, "ms": min_samples_leaf}
)
开发者ID:hongbin0908,项目名称:pytrade,代码行数:7,代码来源:tree.py
示例16: MyRfClassifier
class MyRfClassifier(BaseClassifier):
def __init__(self, n_estimators, max_depth, min_samples_leaf):
self.classifier = RandomForestClassifier(**{'verbose':1, 'n_estimators': n_estimators,
'max_depth':max_depth,'min_samples_leaf':min_samples_leaf,
'n_jobs':40})
self.name = "rf_n{n}_md{md}_ms{ms}".format(
**{"n": n_estimators, "md": max_depth, "ms": min_samples_leaf}
)
def get_name(self):
return self.name
def fit(self, X, y, X_t, y_t):
return self.classifier.fit(X, y)
def predict_proba(self, X):
return self.classifier.predict_proba(X)
def get_feature_importances(self, feat_names):
ipts = dict(zip(feat_names, self.classifier.feature_importances_))
return ipts
开发者ID:hongbin0908,项目名称:pytrade,代码行数:20,代码来源:tree.py
示例17: initDecTrees
def initDecTrees(self, path):
for filename in os.listdir(path):
if filename=='train.csv':
with open(os.path.join(path,filename)) as infile:
f = csv.reader(infile)
aux = f.next() # skip the header
x = []
y = []
for line in f:
if size(line) > 1:
if self.option == 1:
data = [converter(line[2]), converter(line[3]), converter(line[4]), converter(line[7]), converter(line[9])]
y.append(converter(line[6]))
x.append(data)
elif self.option == 2:
auxDeputy = fetchDeputyParty(line[2])
data = [converter(line[2]), converter(line[3]), converter(line[4]), converter(line[7]), converter(line[9]), encodeParty(auxDeputy['party']), encodeState(auxDeputy['state'])]
y.append(converter(line[6]))
x.append(data)
clf = RandomForestClassifier(n_estimators=5)
clf.fit(x, y)
return clf
开发者ID:ignasiet,项目名称:LabIA,代码行数:22,代码来源:portfolioClassificator.py
示例18: drawfeature
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)
开发者ID:quan-js,项目名称:SentimentAnalysis,代码行数:38,代码来源:mainfuction.py
示例19: int
if 'FIGURES' in line:
break
vals = line.strip().split('\t')
text = vals[2]
corpus_test.append(text)
if int(vals[0]) == 0:
y_test.append('0')
else:
y_test.append('1')
X_train = vectorizer.fit_transform(corpus_train)
X_test = vectorizer.transform(corpus_test)
clf = RandomForestClassifier(n_estimators=10)
#clf = KNeighborsClassifier(n_neighbors=10)
#clf = LinearSVC()
clf.fit(X_train, y_train)
print len(y_train)
print len(y_test)
pred = clf.predict(X_test)
#pred = ['0']* len(y_test)
score = metrics.accuracy_score(y_test, pred)
print("accuracy: %0.3f" % score)
total.append(score)
开发者ID:amyxzhang,项目名称:NB_project,代码行数:30,代码来源:baseline_model.py
示例20: model_pred
def model_pred(trainX,trainY,testX,model_type):
if model_type == "rf":
clf = RandomForestClassifier(n_estimators = 500,n_jobs = 20)
clf.fit(trainX,trainY)
pred = clf.predict(testX)
if model_type == "gbdt":
clf = GradientBoostingClassifier(n_estimators=6,learning_rate=0.9,random_state=0)
clf.fit(trainX,trainY)
pred = clf.predict(testX)
if model_type == "fusion":
prob = np.zeros(len(testX))
params = [100,200,300,400,500]
for param in params:
clf = RandomForestClassifier(n_estimators = param,n_jobs = 20,bootstrap=True)
clf.fit(trainX,trainY)
prob += clf.predict(testX)
'''
params = [1,2,3,4,5,6,7,8,9,10]
for param in params:
clf = GradientBoostingClassifier(n_estimators=param,learning_rate=0.9,random_state=0)
clf.fit(trainX,trainY)
prob += clf.predict(testX)
'''
pred = list(prob >= 3)
print "the pos rate is:",float(sum(pred))/len(pred)
return pred
开发者ID:tearf001,项目名称:ucloud,代码行数:26,代码来源:model2.py
注:本文中的sklearn.ensemble.forest.RandomForestClassifier类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论