Python Forum
How to predict with date as input for DecisionTreeRegressor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to predict with date as input for DecisionTreeRegressor
#1
Hi Forum,

How to predict with date as input for DecisionTreeRegressor model?

source: student_mark_result_dec_hist.csv

name day subject percentage
john 12/1/2019 maths 30
john 12/2/2019 maths 40
john 12/3/2019 maths 33
john 12/4/2019 maths 32
john 12/5/2019 maths 31
john 12/6/2019 maths 38
john 12/7/2019 maths 35
john 12/8/2019 maths 38
john 12/9/2019 maths 39
john 12/10/2019 maths 55
john 12/11/2019 maths 65
john 12/12/2019 maths 68
john 12/13/2019 maths 62
john 12/14/2019 maths 70
john 12/15/2019 maths 64
john 12/16/2019 maths 82
john 12/17/2019 maths 80
john 12/18/2019 maths 55
john 12/19/2019 maths 68
john 12/20/2019 maths 79
john 12/21/2019 maths 88
john 12/22/2019 maths 87
john 12/23/2019 maths 80
john 12/24/2019 maths 75


Now, i want to predict for 12/25/2019 and 11/30/2019 marks for subject-maths for name -john, Any ideas?
I was trying with below, but i doubt that's absolutely incorrect,

import pandas as pd
#import numpy as np
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn import preprocessing


raw_data=pd.read_csv('student_mark_result_dec_hist.csv',index_col=False)
blankIndex=[''] * len(raw_data)
raw_data.index=blankIndex

le = preprocessing.LabelEncoder()

for column_name in raw_data.columns:
	if raw_data[column_name].dtype == object:
		raw_data[column_name] = le.fit_transform(raw_data[column_name])
		le_name_mapping = dict(zip(le.classes_, le.transform(le.classes_)))
		print(le_name_mapping)
		
	else:
		pass
print('---->', raw_data[:])

X=raw_data[['name','day','subject']]
y=raw_data['percentage']

model=DecisionTreeRegressor()
model.fit(X,y)

predictions=model.predict([  [0,24,0], [0,-1,0]  ])
print(predictions)

#here, i am not sure if [0.24.0],[0,-1,0] points to date 12/25/2019 and 11/30/2019, Any ideas?
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use .predict() method Jack90_ 4 755 Nov-03-2023, 08:21 PM
Last Post: Larz60+
  How to predict Total Hours needed with List as Input? caninan 0 786 Jan-27-2023, 04:20 PM
Last Post: caninan
  Which network architecture should be chosen to predict disease severity? AlekseyPython 2 1,994 Aug-21-2021, 07:12 PM
Last Post: jefsummers
  How to predict output in a regression problem? Rezaafz 1 2,499 Apr-03-2021, 04:16 PM
Last Post: jefsummers
  Keras.Predict into Dataframe Finpyth 13 9,787 Aug-31-2020, 07:22 AM
Last Post: hussainmujtaba
  Analyze, predict the next step in a sequence. Antonio0608 0 2,010 Jul-23-2020, 05:53 PM
Last Post: Antonio0608
  Error When Using sklearn Predict Function firebird 0 2,052 Mar-21-2020, 04:34 PM
Last Post: firebird
  replace nan values by mean group by date.year, date.month wissam1974 5 8,449 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Predict Longitude and Latitude Using Python vibeandvisualize 1 2,287 Dec-27-2019, 12:10 PM
Last Post: Larz60+
  Trying to Pass date to pandas search from input prompt curranjohn46 1 2,104 Oct-10-2019, 10:01 AM
Last Post: curranjohn46

Forum Jump:

User Panel Messages

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