Lassen Sie uns sagen, dass ich einen Datensatz haben, werde ich ein Spielzeug Beispiel in diesem Fall bieten ...Wie Zielmarke zur Vorhersage scikit
data = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
target = "A"
..., die ...
A B C D
0 75 38 81 58
1 36 92 80 79
2 22 40 19 3
... ...
erzeugt
Dies ist eindeutig nicht genug Daten, die eine gute Genauigkeit zu geben, aber dennoch, sagen wir, ich füttern data
und target
zu einem random forest
Algorithmus von bereitgestellt scikit lernen ...
def random_forest(target, data):
# Drop the target label, which we save separately.
X = data.drop([target], axis=1).values
y = data[target].values
# Run Cross Validation on Random Forest Classifier.
clf_tree = ske.RandomForestClassifier(n_estimators=50)
unique_permutations_cross_val(X, y, clf_tree)
unique_permutations_cross_val
ist einfach eine Kreuzvalidierung Funktion, die ich gemacht, dies ist die Funktion (es gibt die Genauigkeit des Modells als auch aus) ...
def unique_permutations_cross_val(X, y, model):
# Split data 20/80 to be used in a K-Fold Cross Validation with unique permutations.
shuffle_validator = model_selection.ShuffleSplit(n_splits=10, test_size=0.2, random_state=0)
# Calculate the score of the model after Cross Validation has been applied to it.
scores = model_selection.cross_val_score(model, X, y, cv=shuffle_validator)
# Print out the score (mean), as well as the variance.
print("Accuracy: %0.4f (+/- %0.2f)" % (scores.mean(), scores.std()))
Anyways, meine Hauptfrage ist, Wie kann ich das Ziellabel mithilfe dieses Modells vorhersagen? Nehmen wir zum Beispiel an, dass ich das Modell [28, 12, 33]
füttere. Ich möchte, dass das Modell die target
vorhersagt, die in diesem Fall "A"
ist.