本文整理汇总了Python中sklearn.ensemble.forest.RandomForestClassifier类的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier类的具体用法?Python RandomForestClassifier怎么用?Python RandomForestClassifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RandomForestClassifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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')
示例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-")
示例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
示例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
示例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
示例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}
)