Jan-08-2020, 04:01 PM
import pandas as pd
import numpy as np
from sklearn import tree
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.model_selection import cross_val_score
df = pd.read_csv('ADM-cmiyc_data-small.csv',index_col = 0)
# Spliting the independent variable from dependent variable.
X = df.drop(['target'], axis=1)
y = df['target']
# Splitting the data into four variable to train and test the data.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=12)
# By using these function we are building and fit the model.
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X_train, y_train)
# using to predict the class of samples
y_pred = clf.predict(X_test)
# Finally we are using confusion matrix.
print('Confusion Matrix:')
print(confusion_matrix(y_test, y_pred))
print('\nClassification_Report:')
print(classification_report(y_test, y_pred))
# Using Cross validation
cross_val_score(clf, X_train,y_train, cv=5)
error is could not convert string to float: '2013-11-21 14:40:57'
import numpy as np
from sklearn import tree
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.model_selection import cross_val_score
df = pd.read_csv('ADM-cmiyc_data-small.csv',index_col = 0)
# Spliting the independent variable from dependent variable.
X = df.drop(['target'], axis=1)
y = df['target']
# Splitting the data into four variable to train and test the data.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=12)
# By using these function we are building and fit the model.
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X_train, y_train)
# using to predict the class of samples
y_pred = clf.predict(X_test)
# Finally we are using confusion matrix.
print('Confusion Matrix:')
print(confusion_matrix(y_test, y_pred))
print('\nClassification_Report:')
print(classification_report(y_test, y_pred))
# Using Cross validation
cross_val_score(clf, X_train,y_train, cv=5)
error is could not convert string to float: '2013-11-21 14:40:57'