from sklearn import datasets
# Loading the iris plants dataset (classification)
iris = datasets.load_iris()
print(iris.target_names)
print(iris.feature_names)
# dividing the datasets into two parts i.e. training datasets and test datasets
X, y = datasets.load_iris( return_X_y = True)
# Splitting arrays or matrices into random train and test subsets
from sklearn.model_selection import train_test_split
# i.e. 70 % training dataset and 30 % test datasets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30)
# importing random forest classifier from assemble module
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
# creating dataframe of IRIS dataset
data = pd.DataFrame({'sepallength': iris.data[:, 0], 'sepalwidth': iris.data[:, 1],
'petallength': iris.data[:, 2], 'petalwidth': iris.data[:, 3],
'species': iris.target})
# creating a RF classifier
clf = RandomForestClassifier(n_estimators = 100)
# Training the model on the training dataset
# fit function is used to train the model using the training sets as parameters
clf.fit(X_train, y_train)
# performing predictions on the test dataset
y_pred = clf.predict(X_test)
# metrics are used to find accuracy or error
from sklearn import metrics
print()
# using metrics module for accuracy calculation
print("ACCURACY OF THE MODEL:", metrics.accuracy_score(y_test, y_pred))
# predicting which type of flower it is.
clf.predict([[5, 4, 1, 1]])
ZnJvbSBza2xlYXJuIGltcG9ydCBkYXRhc2V0cwoKIyBMb2FkaW5nIHRoZSBpcmlzIHBsYW50cyBkYXRhc2V0IChjbGFzc2lmaWNhdGlvbikKaXJpcyA9IGRhdGFzZXRzLmxvYWRfaXJpcygpCnByaW50KGlyaXMudGFyZ2V0X25hbWVzKQpwcmludChpcmlzLmZlYXR1cmVfbmFtZXMpCiMgZGl2aWRpbmcgdGhlIGRhdGFzZXRzIGludG8gdHdvIHBhcnRzIGkuZS4gdHJhaW5pbmcgZGF0YXNldHMgYW5kIHRlc3QgZGF0YXNldHMKWCwgeSA9IGRhdGFzZXRzLmxvYWRfaXJpcyggcmV0dXJuX1hfeSA9IFRydWUpCgojIFNwbGl0dGluZyBhcnJheXMgb3IgbWF0cmljZXMgaW50byByYW5kb20gdHJhaW4gYW5kIHRlc3Qgc3Vic2V0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