ML 1
ML 1
Mounted at /content/drive
Choose Files No file chosen Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to
enable.
Saving iris.csv to iris.csv
import pandas as pd
iris = pd.read_csv('/content/iris.csv')
iris.shape
(150, 5)
iris.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150 entries, 0 to 149
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 sepal.length 150 non-null float64
1 sepal.width 150 non-null float64
2 petal.length 150 non-null float64
3 petal.width 150 non-null float64
4 variety 150 non-null object
dtypes: float64(4), object(1)
memory usage: 6.0+ KB
X = iris.iloc[ : , 0:4]
X
sepal.length sepal.width petal.length petal.width
Y = iris.iloc[ : , 4: ]
Y.variety.unique()
▾ DecisionTreeClassifier
DecisionTreeClassifier(criterion='entropy', random_state=1234)
text_representation = tree.export_text(clf)
print(text_representation)
_ = tree.plot_tree(clf,
feature_names = ['sepal.length' ,'sepal.width', 'petal.length', 'petal.width'],
class_names = ['setosa', 'versicolor', 'virginica'],
filled = True)
from sklearn.metrics import accuracy_score
pred_train = clf.predict(X_train)
# Let us test the accuracy of the model on the test data (or new data or unseen data).
pred_test = clf.predict(X_test)
new_df = pd.DataFrame(new_data)
new_df.head()