# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
#Import scikit learn dataset library
from sklearn import datasets

#Load datasets
iris=datasets.load_iris()
# -

#print the label species(setosa,versicolar,virginica)
print(iris.target_names)
#print the names of four features
print(iris.feature_names)

#print the iris data(top 5 records)
print(iris.data[0:5])


#print the iris labels (0:setosa,1:versicolar,2:virginica)
print(iris.target)

#Creating a dataframe of given iris dataset
import pandas as pd
data=pd.DataFrame({'sepal length':iris.data[:,0],
                  'sepal width':iris.data[:,1],
                  'petal length':iris.data[:,2],
                  'petal width':iris.data[:,3],
                  'species':iris.target})
data

#Train test split
from sklearn.model_selection import train_test_split
X=data[['sepal length','sepal width','petal length','petal width']] #Features
Y=data['species']#Labels
#split dataset into into training set and testing set
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.4)#60% training and 40% testing

#Import Random Forest Model
from sklearn.ensemble import RandomForestClassifier
#Create a Gaussian Classifier
clf=RandomForestClassifier(n_estimators=100)
#Train the model using the training setsy_pred=clf.predict(X_test)
clf.fit(X_train,Y_train)
Y_pred=clf.predict(X_test)

#Import sckit-learn metrics module for accuracy calculation
from sklearn import metrics
#Model Accuracy,how often is the classifier correct?
print('Accuracy:',metrics.accuracy_score(Y_test,Y_pred))

clf.predict([[3,4,8,9]])

# # Feature Selection

feature_imp=pd.Series(clf.feature_importances_,index=iris.feature_names).sort_values(ascending=False)
feature_imp

import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline
#Create a bar plot
sns.barplot(x=feature_imp,y=feature_imp.index)
#Add labels to your graph
plt.xlabel('Feature importance score')
plt.ylabel('Features')
plt.title('Visualizing Important Features')
plt.show()

for index, row in data.interrows():
    A=row['']

StarcoderdataJupyterScriptsDedupFiltered