Python Forum
Converting Dataframe in Python from Object to Float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting Dataframe in Python from Object to Float
#7
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'
Reply


Messages In This Thread
I am getting error in this code - by AnkitGupta - Jan-08-2020, 04:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  converting dataframe to int numpy array glennford49 1 2,358 Apr-04-2020, 06:15 AM
Last Post: snippsat
  Converting string the pandas dataframe chrismc 0 2,380 Jan-24-2019, 11:07 AM
Last Post: chrismc
  Converting Flattened JSON to Dataframe in Python 2.7 ManMan 1 5,306 Jul-12-2017, 06:52 PM
Last Post: ManMan
  The problem of converting string to float by using CSV file CChen 2 12,988 Jul-11-2017, 03:32 PM
Last Post: CChen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020