本文整理汇总了Python中sklearn.ensemble.ExtraTreesClassifier.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python ExtraTreesClassifier.fit_transform方法的具体用法?Python ExtraTreesClassifier.fit_transform怎么用?Python ExtraTreesClassifier.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.ExtraTreesClassifier
的用法示例。
在下文中一共展示了ExtraTreesClassifier.fit_transform方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSelectedValues
# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
def getSelectedValues(self):
(train, trainLabels, test) = self.getScaledValues()
selector = ExtraTreesClassifier(compute_importances=True, random_state=0)
train = selector.fit_transform(train, trainLabels)
return (train, trainLabels, test)
test = selector.transform(test)
示例2: ExtraTreesClassifier
# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
import numpy as np
from sklearn import preprocessing as pp
from sklearn import cross_validation as cv
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.svm import SVC
workDir = r'C:\users\Akshay\Downloads\kaggle\\'
# Read data
train = np.genfromtxt(open(workDir + 'train.csv','rb'), delimiter=',')
target = np.genfromtxt(open(workDir + 'trainLabels.csv','rb'), delimiter=',')
test = np.genfromtxt(open(workDir + 'test.csv','rb'), delimiter=',')
# Scale data
train = pp.scale(train)
test = pp.scale(test)
# Select features
selector = ExtraTreesClassifier(compute_importances=True, random_state=0)
train = selector.fit_transform(train, target)
test = selector.transform(test)
# Estimate score
classifier = SVC(C=8, gamma=0.17)
scores = cv.cross_val_score(classifier, train, target, cv=30)
print('Estimated score: %0.5f (+/- %0.5f)' % (scores.mean(), scores.std() / 2))
# Predict and save
result = classifier.fit(train, target).predict(test)
np.savetxt(workDir + 'a.csv', result, fmt='%d')
示例3: print
# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
import numpy as np
import pandas as pd
from sklearn import preprocessing as pp
from sklearn.ensemble import ExtraTreesClassifier
print("Preparing the data")
train = pd.io.parsers.read_csv(r"D:\shared\datascience\phy_train_clean.csv", sep=',', header=0)
test = pd.io.parsers.read_csv(r"D:\shared\datascience\phy_test_clean.csv", sep=',', header=0)
test_index = test.Id
test = test.iloc[:,2:]
target = train.kind
train_index = train.Id
train = train.iloc[:,2:]
print("Preparing an Feature classifier")
selector = ExtraTreesClassifier(compute_importances=True, random_state=0)
print("Transforming the original dataset")
train = pd.DataFrame(selector.fit_transform(train, target), index = train_index)
test = pd.DataFrame(selector.transform(test), index = test_index)
train['kind'] = target
print("Storing the data...")
train.to_csv(r"D:\shared\datascience\phy_train.csv", sep=',')
test.to_csv(r"D:\shared\datascience\phy_test.csv", sep=',')
print("Job finished")
示例4: main
# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
def main():
X =[]
Y=[]
featuresDB = Base(os.getcwd()+"\\Databases\\features.db")
featuresDB.open()
print "features open"
for rec in featuresDB:
vec = []
vec.append(rec.f1)
vec.append(rec.f3)
vec.append(rec.f4)
vec.append(rec.f5)
vec.append(rec.f6)
vec.append(rec.f7)
vec.append(rec.f10)
vec.append(rec.f11)
vec.append(rec.f12)
vec.append(rec.f13)
vec.append(rec.f14)
vec.append(rec.f15)
vec.append(rec.f16)
vec.append(rec.f17)
vec.append(rec.f18)
vec.append(rec.f19)
vec.append(rec.f20)
vec.append(rec.f21)
vec.append(rec.f22)
vec.append(rec.f23)
X.append(vec)
Y.append(rec.score)
print "building classifier"
Y = np.array(Y)
ybar = Y.mean()
for i in range(len(Y)):
if Y[i]<ybar:
Y[i]=1
else:
Y[i]=2
scaler = Scaler().fit(X)
X = scaler.transform(X)
X= np.array(X)
Y=np.array(Y)
skf = cross_validation.StratifiedKFold(Y,k=2)
for train, test in skf:
X_train, X_test = X[train], X[test]
y_train, y_test = Y[train], Y[test]
clf = ExtraTreesClassifier(n_estimators=8,max_depth=None,min_split=1,random_state=0,compute_importances=True)
scores = cross_validation.cross_val_score(clf,X_train,y_train,cv=5)
clf.fit_transform(X_train,y_train)
print "Accuracy: %0.4f (+/- %0.2f)" % (scores.mean(), scores.std() / 2)
print clf.feature_importances_
y_pred =clf.predict(X_test)
print classification_report(y_test,y_pred)
model=(scaler,clf)
joblib.dump(model,'AestheticModel\\aestheticModel.pkl')
print "Done"
示例5: PCA
# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
print test_data_array.shape
file_label.close()
# normalize the features in the train and test dataset
train_data_array_norm = preprocessing.scale(train_data_array)
test_data_array_norm = preprocessing.scale(test_data_array)
# run the module of PCA
#pca = PCA(n_components = 10)
#train_data_array_norm_pca = pca.fit_transform(train_data_array_norm, train_result_array)
#test_data_array_norm_pca = pca.transform(test_data_array_norm)
#print 'train data shape', train_data_array_norm_pca.shape
# tree-based feature selection
classifier = ExtraTreesClassifier()
train_data_array_norm_pca = classifier.fit_transform(train_data_array_norm, np.ravel(train_result_array))
test_data_array_norm_pca = classifier.transform(test_data_array_norm)
print 'train data shape', train_data_array_norm_pca.shape
## build SVM
# random shuffle
np.random.seed(0)
indices = np.random.permutation(len(train_result_array))
classifer = svm.SVC(C=20, gamma = 0.05)
# cross validation
scores = cv.cross_val_score(classifier, train_data_array_norm_pca, np.ravel(train_result_array), cv = 30)